Goal: I’m trying to build a website search, that allows to filter by downloads. Basically, when I decide to filter for downloads, It should show me pages that have files (from a specific file blueprint called downloads
) that match the search query, based on the file name and probably other fields defined on the file blueprint.
When I just search for pages, I would use $pages->search()
and can define any additional parameters, for example score
and fields
, to give weight to certain fields.
Based on the documentation and the fact that files also build on top of Collection, I assume $files->search()
parameters are the same, even though the documentation only describes it as an array, without further explanation.
Now, what is not clear to me: Whether $files->search()
includes any information from the file blueprint or if it is a raw file search based on filename only.
Because I tried to do something like that:
$fileResults = $site->index()->files()->search($query, [
'fields' => ['name', 'friendly_name'],
'score' => ['friendly_name' => 64, 'name' => 32]
]);
Where friendly_name
is a text field on the file blueprint, allowing content editors to set a title for the download as shown to the users on the website.
It doesn’t look like these kinds of parameters work on the file search. It does emit zero results at anytime.
The question then is: How do I correctly search all pages for files matching the query? Because $site->index()->search($query, 'downloads');
(limiting it to the file upload fields) does not work either. Also, this doesn’t allow me to extend which fields of the downloads should be included.