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
$pageIds
The current page IDs to be searched though.
string
$keywords
The search keywords.
string
$queryType
The query type: either
and
oror
.bool
$fuzzy
Whether the search should be “fuzzy”.
\Contao\Module
$module
The 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 …
}
}