How to exclude non-routable Pages from SimpleSearch results

Hi everyone,

I’m currently using the SimpleSearch plugin on my GRAV CMS website to search and display results. However, I’m encountering an issue where the search results include links to non-routable pages, specifically those located in folders with names prefixed by an underscore (e.g., _hidden/page.md).

I would like to find a solution to exclude these non-routable pages from the search results. Ideally, I would prefer to avoid having to add code to each individual non-routable page.

simplesearch:
    process: false

I found this information: Simplesearch returns _module pages but something may change.

I think commenting out the line in the simplesearch.php file works:

//Add modular pages again 
$this->collection->merge($modularPageCollection); 

but I would also like to avoid such modification inside the file.

Has anyone faced a similar issue or have any suggestions on how to achieve this? Your help would be greatly appreciated!

Thank you in advance.

Not an answer to your question, but have you tried the TNT Search plugin?

I can’t remember the details of why, but I had lots of problems like yours when I tried making SimpleSearch work, and they mostly went away when I switched to TNT Search. Both are released by the Grav team. There’s also Algolia as a premium plugin but I haven’t tried it except as a user on the Grav docs and I’m not very impressed.

@q3d,

However, I’m encountering an issue where the search results include links to non-routable pages, specifically those located in folders with names prefixed by an underscore (e.g., _hidden/page.md ).

“Non-routable”
The purpose of using the underscore (_) as prefix in a foldername is, imho, not to mark it as non-routable, but to mark a page as a module. Modules will be treated differently by Grav. Although a module is non-routable, it will be treated differently form pages which are explicitly being marked as non-routable using routable: false in the header of the page.

SimpleSearch
I suspect when a module (underscore prefixed folder) contains the search keyword, the parent (the modular) will be returned and not the module itself.

If you have a different experience, please share the relevant folder tree and frontmatter.

I wasn’t aware of the TNT Search plugin, but I’ll definitely take a closer look at it. It sounds like it might resolve some of the issues I’m facing with SimpleSearch.

Thank you for the detailed explanation regarding “non-routable” pages and the use of the underscore prefix. Your clarification helps me understand how modules are treated differently in GRAV. I appreciate the insight and will consider it while working on my site.

Thanks again to both of you for your helpful suggestions and explanations!

1 Like

@q3d, Just curious, do the pages with routable: false still appear in your SimpleSearch?
They don’t in my tests…

Please keep the community updated.

In my case, I have a main page (modular)

01.start -> modular.md

---
title: Main Page
visible: false
simplesearch:
    process: false
content:
    items: '@self.modules'
---

On this page, I display several modules, including, for example, Hero.

Case 1.

01.start -> 01._hero -> section.md

section.md:

title: 'We invest in the environment together'
block: hero
layout: full-image
...

The search finds the phrase ‘We invest in the environment together’ and directs to the main page. Thanks to you, I understand the reasoning behind this behavior. However, in my case, it causes confusion.

Case 2.

title: 'We invest in the environment together'
simplesearch:
    process: false
block: hero
layout: full-image
...

When entering the phrase: ‘We invest in the environment together’, the search finds nothing. That’s ok!

Case 3.

title: 'We invest in the environment together'
routable: false
block: hero
layout: full-image
...

Gives me exactly the same result as in Case 1. That is, the phrase is found, and the link from the search results directs to the main page.


@q3d,

Case 1:
This how modules are supposed to be handled by Grav: As part of a parent modular page.

Case 2:
That’s how, according the README of SimpleSearch, pages should be excluded.

Case 3:
This is also according the definition of `routable’.

According Grav’s docs about routable:

By default, all pages are routable . This means that they can be reached by pointing your browser to the URL of the page.
However, you may need to create a page that is created to hold specific content, but it is meant to be called directly by a plugin, other content, or even a theme directly.

  • The module is directly called by the modular, hence it will be available according the definition shown above.
1 Like