$files->search() parameters and searching with additional fields

instead of the search you could just do a filerBy on the “all files collection”

$result = $site->index()->files()->filterBy(function($file) use ($query) {
  return $file->name() === $query || Str::contains($file->friendly_name()->value(), $query);
});

but given how many files and pages you have you can expect that to take increasingly more time. you could add some kind of caching by creating a search index cache. on file create or update hook write name and friendly_name to a single big array. with file id as key. that array will hold all search data of all files no matter where they are. searching that should be much faster than using the collection.

1 Like