customizeSearch
The customizeSearch hook is triggered when a user is using the search module
in the front end. With this hook you can customize which pages should get searched.
The hook passes the current page IDs as an array, the search keywords, the query
type (and or or), whether the search is “fuzzy” and the module object as
arguments. The hook does not expect a return value.
Parameters
array
$pageIdsThe current page IDs to be searched though.
string
$keywordsThe search keywords.
string
$queryTypeThe query type: either
andoror.bool
$fuzzyWhether the search should be “fuzzy”.
\Contao\Module
$moduleThe front end module instance executing this hook.
Example
// src/EventListener/CustomizeSearchListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Module;
#[AsHook('customizeSearch')]
class CustomizeSearchListener
{
public function __invoke(array &$pageIds, string $keywords, string $queryType, bool $fuzzy, Module $module): void
{
// Change the $pageIds array here or do some other adjustments …
}
}