I’m wondering if it’s possible to leverage the native kirby search functionality to recursively search through array entries rather than through a collection of pages.
Is it possible? I tried to search in the docs but I didn’t find anything useful.
I’ll answer my own question. Apparently no but I can reuse the search logic to perform a slightly different search for my use case.
bnomei
March 24, 2023, 12:53pm
3
search should work on any collection not just pages collections so you can feed your array into one and run the search then.
}
/**
* Native search method to search for anything within the collection
*
* @param \Kirby\Cms\Collection $collection
* @param string|null $query
* @param mixed $params
* @return \Kirby\Cms\Collection|bool
*/
public static function collection(Collection $collection, string $query = null, $params = [])
{
$kirby = App::instance();
return ($kirby->component('search'))($kirby, $collection, $query, $params);
}
/**
* @param string|null $query
* @param array $params
* @return \Kirby\Cms\Pages
*/
bnomei
March 24, 2023, 12:55pm
4
something like this (without proper namespaces)
$collection = new Collection($data);
$results = Search::collection($collection, $query, $params);