Search collection, excluding fields

We have a search form on a website that uses Kirby’s core search method:

$pages->published()->search($query);

Reading the docs, it’s possible to include an array of fields in the params for the search to look into. This is a positive list: only the listed fields get used.

Is there also a way to define a negative list? An array of field to exclude? It’s very tedious to define included fields by hand, ignoring one or two field. And it’s also prone to errors if you forget to adjust your search if the field setup ever changes.

No, that’s not possible, you could however, fetch all fields (of all pages) into an array, exclude the ones you want to exclude, then pass the remaining array to the search method.

Or you overwrite the search component.

Okay, that’s what I thought – thanks! Will have to think about how to preceed in context of the given project.

It would be handy, if the core knew some kind of negation syntax, e. g. $collection->search($query, '!category') (or something similar).