grav-plugin-simplesearch icon indicating copy to clipboard operation
grav-plugin-simplesearch copied to clipboard

Collection search doesn't work

Open olivierdalang opened this issue 8 years ago • 4 comments

Hi ! I tried to follow the instructions carefully, but couldn't make simplsearch work on page searches (global search works well).

Here's my code :

---
title: Blog
content:
    items: @self.children
    limit: 10
    order:
        by: date
        dir: desc
    pagination: true
    url_taxonomy_filters: true
simplesearch:
    route: @self
    filters:
        - @self
    filter_combinator: and
---
...

When submitting the form, the query is correctly appended to the url, but the listing page shows all the items, just as if no query was set. Is it a bug ?

olivierdalang avatar May 26 '17 00:05 olivierdalang

Perhaps have a look at @flaviocopes's reply to a similar question here.

I had a similar issue to the one you describe, with an almost identical page configuration to the example you give above.

I did as suggested in the answer, changing this line in my template to {% set collection = search_results ?: page.collection() %} and it fixed the issue for me (thanks flaviocopes).

Hope that helps.

timrobbings avatar May 27 '17 11:05 timrobbings

@timrobbings Thanks that did the trick ! I think this should be fixed to work out of the box or specified in the doc

olivierdalang avatar May 28 '17 16:05 olivierdalang

Another problem once this is solved is the inability to clear the search. If you enter an empty string, you can't submit the query. I think a link should be added to clear the search if there is a query. Here's my quick fix :

in templates/partials/simplesearch_searchbox.html.twig

...
    {% if query %}
    <a href="{{page.url}}">Clear the search</a>
    {% endif %}
...

olivierdalang avatar May 28 '17 16:05 olivierdalang

{% set collection = search_results ?: page.collection() %}

This should totally be added to the docs, this issue was driving me nuts

Dean-kasail avatar Nov 16 '17 06:11 Dean-kasail