Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self-controlled search page doesn't actually search #51

Closed
hunternet93 opened this issue Jul 20, 2016 · 10 comments
Closed

Self-controlled search page doesn't actually search #51

hunternet93 opened this issue Jul 20, 2016 · 10 comments
Assignees
Labels

Comments

@hunternet93
Copy link
Contributor

I'm trying to set up a per-page search feature as described here, however when searching the template simply renders the same page, instead of filtering content by the search query.

Steps to reproduce:

  1. Download and extract the blog site skeleton. I'm using PHP's built-in webserver for testing, but I've also tried Apache with identical results.

  2. Edit the file user/pages/01.blog/blog.md and append the following to its frontmatter:

    simplesearch:
    route: /blog
    filters:
        - /blog
        - @taxonomy: [tag]
    filter_combinator: and
  3. Open the site in a browser and attempt searching. Searching will redirect the page to /blog/query: as expected, but then will load exactly the same page again, without filtering by the search query.

Did I miss a step when setting up simplesearch?

@flaviocopes flaviocopes self-assigned this Jul 21, 2016
@flaviocopes
Copy link
Contributor

On it

@flaviocopes
Copy link
Contributor

@hunternet93 replicated. Can you test this PR #53 ? Thanks!

@hunternet93
Copy link
Contributor Author

The PR works great, thanks!

@flaviocopes
Copy link
Contributor

Ok cool! Merging it

@Lamecarlate
Copy link
Contributor

Lamecarlate commented May 8, 2017

Hi! I have the same problem: on my local grav site, and on the grav skeleton mentionned by hunternet93 (I downloaded it, added the exact array in the frontmatter, and searched for a word), the self-controlled search does not update the page.

I did some tracing in the code (in onPagesInitialized function), and the collection is indeed reduced to only the pages that correspond to the searched terms, but the page itself is not changed. I take it that $this->collection is meant to be automatically re-inserted in the page - it works well on site wide searching (which create a new page).

Do you know how I can fix that? (I can give a archive of my user folder, for you to see my config & dumps in the simplesearch code)

Is there an specific order to follow in the frontmatter?

Thanks in advance!

@Lamecarlate
Copy link
Contributor

Excuse me, was it an error to "up" this issue? Do I have to create a new one?

@flaviocopes
Copy link
Contributor

flaviocopes commented May 19, 2017

I merged the change but was reverted, as was breaking some functionality.

You need to make sure the blog page (in Antimatter) fetches the collection from the search result. This line: /~https://github.com/getgrav/grav-theme-antimatter/blob/develop/templates/blog.html.twig#L3

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

Need to add this to the docs.

@Lamecarlate
Copy link
Contributor

That was… simple. I'm a bit ashamed I didn't think of that. Thanks!

@flaviocopes
Copy link
Contributor

Actually the docs say that it should work out of the box, something seems to miss, need to dig a little bit this use case.

@IamSAB
Copy link

IamSAB commented Sep 29, 2021

I got the same problem, but it even does not work conditionally setting the collection? Anybody else having trubles?

The docs do not mention this detail. Has there ever been a fix for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants