Excluding Filter URLs from the Contao Search Index

If you want an MM list to be included in the search index but not the list calls with filter parameters, this cannot be configured from the backend.

An FE filter generates various URLs with “key-value pairs” for filtering when passing data to an MM list. In most cases, including these URLs in the search index is unnecessary or undesirable, as it only bloats the index without providing meaningful search results.

For filter widgets that generate a URL directly — such as a link list — inclusion in the index is typically prevented by specifying the data-escargot-ignore attribute in the widget template.

However, if a website visitor visits a filter URL, it is still added to the search index, provided the base page of the list has not been excluded from search. With few filter options, this is not a problem. But if many filter combinations are possible, this can lead to a continuously growing search index with little helpful results.

To prevent this, the following code can be used to suppress indexing when a filter is active. The code snippet must be inserted in the MM list template.

Note

For MM 2.4 / Contao 5.3

 1<?php
 2
 3use Contao\CoreBundle\Routing\ResponseContext\JsonLd\ContaoPageSchema;
 4use Contao\CoreBundle\Routing\ResponseContext\JsonLd\JsonLdManager;
 5use Contao\System;
 6
 7if (!empty($this->filterParams)) {
 8    $responseContext = System::getContainer()->get('contao.routing.response_context_accessor')->getResponseContext();
 9    if ($responseContext?->has(JsonLdManager::class)) {
10        /** @var JsonLdManager $jsonLdManager */
11        $jsonLdManager = $responseContext->get(JsonLdManager::class);
12        $schema        =
13            $jsonLdManager->getGraphForSchema(JsonLdManager::SCHEMA_CONTAO)->get(ContaoPageSchema::class);
14        $schema->setNoSearch(true);
15    }
16}
17?>

Note

For MM 2.3 / Contao 4.13

1 <?php
2 if (!empty($this->filterParams)) {
3     global $objPage;
4     $objPage->noSearch = true;
5 }
6 ?>