Skip to content

Search

Add your own search engine

If you are not happy with our built-in search for collections, you can create your own.

Keep in mind that the search component will be used for all searches of collections (e.g. pages, users, fields) that use the ->search() method.

/site/plugins/my-search/index.php
Kirby::plugin('my/search', [
   'components' => [
      'search' => function (Kirby $kirby, Collection $collection, string $query = null, $params = []) {

            // only search in the field named keywords
            $result = $collection->filterBy('keywords', '*=', $query);

            return $result;
        }
  ]
]);

Parameters

Name Type Default Description
$kirby * Kirby\Cms\App Kirby instance
$collection * Kirby\Cms\Collection Collection of searchable models
$query string null
$params mixed [ ]

Return type

Kirby\Cms\Collection|bool