Use SimpleSearch two times on the same website

Ok, here is the problem. I have a website with a blog page with subpages, and another page to collect various information which also has subpages.
What ai want to do now is to have two different search boxes. One on the blog page to search only in blog subpages, and another search box on the mentioned information collecting page and their subpages.
I use page based search as mentioned in the docs. The search on the blog page works correctly, but the search on the other page results in a 404 page not found error.
Is it possible to have two search boxes on one website?

1 Like

Hello there,

following text is written on the github page of the plugin:

Maybe you should give it a try to configurate the search lik this ?

Regards
Michael

Hey Michael,
thanks for your reply, but I already tried this, without success.

For explanation: under pages I have this structure

  1. home (which is my blog)
    -> blog.md
  2. books
    -> boods.md

In my /user/config/plugins/simplesearch.yaml i have:

route: /search
search_content: rendered
template: mysearch_results

In my blog.md I find:
simplesearch:
route: @self
filters:
- @self
- @taxonomy: [tag]
filter_combinator: and

Same section is under books.md

I call the simplesearch_searchbox.html.twig from my blog.html.twig and from my books.html.twig. Before calling with {%include … I set my base_url to @self.

Maybe this is the problem?

I think I don’t exactly understand the route thing …

So I still can’t figure it out how page-based search works. What I need is an example of the simplesearch.yaml file configuration, and the frontmatter of the two pages where I add the two simplesearch_searchbox.

Any idea please?

Maybe my findings will help you.

Hy pollito, I just read through your findings and I will give it a try this evening and let you know about my results. Thanks a lot in advance.

Hi,
sorry but this solution didn’t work for me either.

Ok I finally got it to work. I share my findings here. It was all about the route and a missing results page.
My structre is like this:
01,blog
–>blog.md
04.books
–>books.md
–>book1
---->book.md

in my simplesearch.yaml I have:

route: /search
search_content: rendered
template: mysearch_results
filters:
filter_combinator: or

my blog.md looks something like:

title: Blog
content:
    items: '@self.children'
    order:
        by: date
        dir: desc
    limit: 5
    pagination: true
pagination: true
simplesearch:
    route: /search
    filters:
        - @self
    filter_combinator: and

my books.md looks like this:

title: Books
content:
    items: '@self.children'
    order:
        by: date
        dir: desc
    limit: 20
    pagination: true
pagination: true  
simplesearch:
    route: /search
    filters:
        - @self
    filter_combinator: and

in both, my blog.html.twig and books.html.twig I include the sidebar with:

{% include 'partials/sidebar.html.twig' with {'page':page} %}

!!Attention: In this two files I have to delete the change of the base_url, which was:

{% set base_url = page.url %}

This line caused the problem on the books.md. page, so the search result never was shown.

in the sidebar.html.twig the searchbox is included with this command lines:

{% set new_base_url = page.url == '/' ? '' : page.url %}
{% if config.plugins.simplesearch.enabled %}
<div class="sidebar-content">
    <h4>SimpleSearch</h4>
    {% include 'partials/simplesearch_searchbox.html.twig' %}
</div>
{% endif %}

and the simplesearch_searchbox.html.twig remains unchanged.

Hope it helps you too. Good luck.