Excluding one pager sections from search results

Let’s say I have a site with many one-pagers. Each one-pager is made up of sections, each section being a child page.

Now, when using Kirby search, the search results will contain the page objects of each section of the one-pager because that’s the nature of the search. It will search in pages.

What I think should happen though is that the search actually searches within those child pages of a one-pager, however the result should be the parent page. Because the actual section is not meant to be rendered by itself (though it has a URL).

Possibly, a search term appears multiple times within sections of a one-pager, so the results should be aggregated into one parent page (the one-pager) instead of many child pages (the sections of the one-pager).

Looking forward to feedback, also I may be making a mental error.
What would be the recommended way of doing this?

Btw imho…this also pertains to sections not appearing on sitemaps. Would be nice if Kirby had a way of saying “yeah, these are actually not pages, they act like one technically but make up a one-pager container”.

Thx!

As you wrote yourself, Kirby searches in pages (actually, in the content files of those pages) and doesn’t know anything about what is actually rendered where.

For such use cases, Kirby’s search is not the right search method.

I was thinking to do something like this:

  • flag a section / child page via a blueprint field, e.g. is_one_pager_section or something like that
  • from the search results, convert a result flagged is_one_pager_section to its parent url (or create / assign the page object of its parent)
  • make the search results unique (in case there a multiple with the same url)
  • paginate

What do you think, @texnixe, would that work?

Yes, that would work. Although the search scores of course wouldn’t work anymore, because they are based only on the single result, not the combined one.

A service like Algolia would certainly work better (but come at a price) or any other search engine that searches the rendered pages.

Ok, thx, @texnixe! Any other concerns / hints?

If my solution works out, I’ll post it here. I think it would in general be nice to have a search solution involving one-pagers as many others may follow the cookbook way of creating one-pagers with subpages.

If you create a page model for the subpages with a url that points to the parent, you wouldn’t need the flag.

1 Like