Do search results contain virtual pages?

Hi!

I’m using the cookbook search example as a starting point. Everything works as expected, however I still have a question if you mind.

In my config.php file I’m using the following redirect to create virtual sub-overview-pages displaying $data.

'pattern' => 'biomes/(:any)',
    'action' => function ($value) {
         $data = [
          'slug' => $value,
        ];
       return page('biomes')->render($data);
     }

biomes has different virtual sub-overview-pages.

These virtual sub-overview-pages render a list of subpages filtered by a select field – like biomes/forests or biomes/beaches. Where forests or beaches are options in a select field on each subpage inside the biomes-page. The virtual sub-overview-page has an intro text like “Forests and beaches are cool”.

So my goal is: if somebody types “forests” or “cool” to have the search results list the corresponding overview-page(s) like biomes/forests etc.

Thanks for any hints!

No, Kirby’s search doesn’t know anything of your routes and what they return. Although it seems that these subpages do actually exist and are only rendered with the parent template? Don’t quite get your structure without an example…

The search function does, however, find “real” virtual pages, i.e. those declared via a page model.

Ah ok. Maybe it helps if I clarify the structure.

The following is the navigation with three nav items:

Bildschirmfoto 2020-01-05 um 17.15.57

When you click on one of the three nav items it redirects to a virtual page where all of the, for example, publications are listed – that means that every nav item has an overview-page:

So I want to achieve the following:
If the search keyword is part of the results description text (see panel field), the search results should show links to the three virtual overview-pages Publications, Media, Presentations.

In the panel the structure is the following:
(Each publication etc. has its own subpage withing the All results subpage page.)

I think you have two options (or at least that’s what I would try):

  • create a results page model with the subpages as children (as children, these pages will become part of the $site->index() and thus searchable.
  • modify the results collection, by replacing every results page result with links to the overview subpages instead.

(or use another type of search that crawls URLs and returns the results)

Thanks for your hints!

If you don’t mind, I have another related question:

I’m using this controller:

return function ($site) {

  $query   = get('q');
  $results = $site->search($query, 'title|text')->listed();

  return [
    'query'   => $query,
    'results' => $results,
  ];

};

and trying to get the search result’s parent page’s color field contents. (Like in case the search result is a subpage of the page with the color field.)
However <?= $result()->parent()->color() ?> does not really work. $result is the resulting value of a foreach loop.

The structure is:

Should be $result->parent()->color() without the parentheses after $result

1 Like

Oh, thanks!