SimpleSearch Self-Controlled Page Configuration

Hello to the Grav Community! I have been reading this forum for a while now and I must say that you are doing incredible job here.

Never the less I have some problems with SimpleSearch plug-in. Initial configuration was working fine but it only searched for blog category. When I added Self-Controlled Page configuration described in the docs and tried to search blog, only URI was changed but results page didn’t load. I have made var_dump in simplesearch.php of $this->collection after if ($query){ ... } to check if search results are correct and they are correct but results are not presented on search result page.

Obviously I am missing something, so I am here to ask for help with configuration.

My current configuration is given bellow.

-user/config/plugins/simplesearch.yaml
enabled: true
built_in_css: true
built_in_js: true
display_button: true
min_query_length: 3
route:
search_content: rendered
template: simplesearch_results
filters:
filter_combinator: or
ignore_accented_characters: false
order:
  by: date
  dir: desc

-user/pages/02.blog/blog.md
title: Blog
menu: Blog
author: 'Blog Smith'
routes:
  default: '/blog'
content:
  items:
    - '@self.children'
    - '@taxonomy':
      category: ['blog']
  order:
    by: date
    dir: desc
  limit: 10
  pagination: true 
simplesearch:
  route: @self
  filter:
    - @self
  filter_combinator: and

-user/pages/02.blog/article1/default.md
title: Article 1
author: 'John Author'
slug: article1
route:
    default: '/blog/article1'
taxonomy:
    tag: [tag1,tag2]
    category: blog
    author: 'John Author'
    title: Article 1

I have tried various combinations that are posted in relevant topics but it didn’t work. My intention is to make few sites (similar to the blog site) that can use search for searching @self.children content.

Thanks in advance for you responses.

After doing some code examination and few unsuccessful attempts to solve the issue I have found what I was missing and the answer is the following.

If you want to have few pages and search their content (independently or not), you need search results page where you can display search results. To be more specific let’s say that I have /user/pages/01.blog1 and /user/pages/02.blog2 pages. Both of them have their blog.md configuration file and frontmatter given bellow:

title: Blog {1|2}
routes:
    default: '/blog{1|2}'
content:
    items:
        - '@self.children'
    order:
        by: date
        dir: desc
    limit: 10
    pagination: true
simplesearch:
    route: /blog{1|2}/search
    filters: 
        - @self
    filter_combinator: and

You will notice that atribute route in simplesearch is not pointing to the blog page. The presented route is logical location of search results pages for blog1 and blog2. Search result pages could be physical located in /user/pages/search_blog1 and /user/pages/search_blog2 and they will have simplesearch_results.md configuration file with following frontmatter:

title: Blog{1|2} search results
routes:
    default: '/blog{1|2}/search'
content:
    items:
        - '@page.children': '/blog{1|2}'
    order:
        by: title
        dir: desc
 simplesearch:
     route: @self
     filters:
         - @self
     filter_combinator: and

To be fair, with this method you just redirect search query from blog page to the hidden search page. In items you can put just - @page.children: '/blog1' and SimpleSearch will search only children pages of blog and but you can add as much sources initems` as you like and they will be included in search. For example if you want to search posts from both blog pages:

items:
    - '@page.children': '/blog1'
    - '@page.children': '/blog2'

Also you can apply desired filters under atribute filters in simplesearch.

This opens another problem which is pagination of search results :slight_smile: