Skip to content

Commit

Permalink
[TASK:BP:11.5] Handle invalid facet options
Browse files Browse the repository at this point in the history
Invalid filter options will lead to Solr errors and exceptions
in frontend. This commit adds an additional check, ensuring invalid
filter options will not be applied.

A log entry will help the website administrator to solve the
issue.

Ports: 3444
  • Loading branch information
dkd-friedrich committed Apr 4, 2023
1 parent b145cdd commit f14861f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Classes/Query/Modifier/Faceting.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use ApacheSolrForTypo3\Solr\Domain\Search\SearchRequestAware;
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
use InvalidArgumentException;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Modifies a query to add faceting parameters
Expand Down Expand Up @@ -155,8 +157,11 @@ protected function addFacetQueryFilters(array $resultParameters, bool $keepAllFa
$facetConfiguration = $allFacets[$facetName . '.'];
$tag = $this->getFilterTag($facetConfiguration, $keepAllFacetsOnSelection);
$filterParts = $this->getFilterParts($facetConfiguration, $facetName, $filterValues);
$operator = (($facetConfiguration['operator'] ?? null) === 'OR') ? ' OR ' : ' AND ';
$facetFilters[$facetName] = $tag . '(' . implode($operator, $filterParts) . ')';

if (!empty($filterParts)) {
$operator = (($facetConfiguration['operator'] ?? null) === 'OR') ? ' OR ' : ' AND ';
$facetFilters[$facetName] = $tag . '(' . implode($operator, $filterParts) . ')';
}
}

return $facetFilters;
Expand Down Expand Up @@ -208,7 +213,13 @@ protected function getFilterParts(array $facetConfiguration, string $facetName,
}

$filterValue = $filterEncoder->decode($filterValue, $filterOptions);
$filterParts[] = $facetConfiguration['field'] . ':' . $filterValue;
if (($facetConfiguration['field'] ?? '') !== '' && $filterValue !== '') {
$filterParts[] = $facetConfiguration['field'] . ':' . $filterValue;
} else {
/** @var $logger \TYPO3\CMS\Core\Log\Logger */
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$logger->warning('Invalid filter options found, skipping.', ['facet' => $facetName, 'configuration' => $facetConfiguration]);
}
}

return $filterParts;
Expand Down

0 comments on commit f14861f

Please sign in to comment.