TYPO3 v9 has reached its end-of-life September 30th, 2021 and is not maintained by the community anymore. Looking for a stable version? Use the version switch on the top left.
You can order Extended Long Term Support (ELTS) here: TYPO3 ELTS.
Searching for Files¶
Since TYPO3 9.5.6, there is an API in FAL to search for files in a storage or folder, which includes matches in meta data
of those files. The given search term is looked for in all search fields defined in TCA of
Searching for files in a folder works like this:
use TYPO3\CMS\Core\Resource\Search\FileSearchDemand; $searchDemand = FileSearchDemand::createForSearchTerm($searchWord)->withRecursive(); $files = $folder->searchFiles($searchDemand);
Searching for files in a complete storage works like this:
$searchDemand = FileSearchDemand::createForSearchTerm($searchWord)->withRecursive(); $files = $storage->searchFiles($searchDemand);
It is possible to further limit the result set, by adding additional restrictions to the
Please note, that
FileSearchDemand is an immutable value object, but allows chaining methods for ease of use:
$searchDemand = FileSearchDemand::createForSearchTerm($this->searchWord) ->withRecursive() ->withMaxResults(10) ->withOrdering('fileext'); $files = $storage->searchFiles($searchDemand);
There is also a driver capability
to allow implementing an optimized search with good performance.
Drivers can optionally add this capability in case the identifiers that are constructed by the driver
include the directory structure.
Adding this capability to drivers can provide a big performance boost
when it comes to recursive search (which is default in the file list and file browser UI).