getgrav / grav-plugin-simplesearch

Grav SimpleSearch Plugin
https://getgrav.org
MIT License
44 stars 55 forks source link

Collection search doesn't work #118

Open olivierdalang opened 7 years ago

olivierdalang commented 7 years ago

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 ?

timrobbings commented 7 years ago

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.

olivierdalang commented 7 years ago

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

olivierdalang commented 7 years ago

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 %}
...
Dean-kasail commented 6 years ago

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

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