Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Use SimpleSearch two times on the same website

Solved by Matthias View solution

Started by Matthias 8 years ago · 7 replies · 1391 views
8 years ago

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
8 years ago

Hello there,

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

@Github:
To accomplish multiple search types in a single site, you should use page-based configuration. This is simple to do, simply provide any or all of the configuration options under a simplesearch: header in your page frontmatter. For example:

YAML
simplesearch:
    route: @self
    filters:
        - @self
        - @taxonomy: [tag]
    filter_combinator: and

These page headers will only be taken into account if the search route points to this page. For example: here the the route points to @self which in turn resolves to /blog. You can also specify the route explicity with route: /blog if you so choose. This header is within the /user/pages/blog/blog.md file. We will cover this self-controlled form of search handling below.

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

Regards
Michael

8 years ago

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 ...

8 years ago

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?

8 years ago

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.

8 years ago

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

8 years ago Solution

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:

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

my blog.md looks something like:

YAML
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:

YAML
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:

TWIG
{% 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.

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 47 1 week ago
Plugins · by Xavier, 4 weeks ago
2 56 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1182 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 50 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 74 2 months ago