From 1c606b62e236637df26641669e4f42e205c851b2 Mon Sep 17 00:00:00 2001 From: Lukas Niestroj Date: Mon, 2 Jan 2023 15:02:25 +0100 Subject: [PATCH 1/2] [BUGFIX] add empty string as fallback ensure a string is always returned, even if the query does not exist --- .../Facets/OptionBased/QueryGroup/QueryGroupUrlDecoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Domain/Search/ResultSet/Facets/OptionBased/QueryGroup/QueryGroupUrlDecoder.php b/Classes/Domain/Search/ResultSet/Facets/OptionBased/QueryGroup/QueryGroupUrlDecoder.php index 16641b4db0..f423d2ba2f 100644 --- a/Classes/Domain/Search/ResultSet/Facets/OptionBased/QueryGroup/QueryGroupUrlDecoder.php +++ b/Classes/Domain/Search/ResultSet/Facets/OptionBased/QueryGroup/QueryGroupUrlDecoder.php @@ -37,6 +37,6 @@ class QueryGroupUrlDecoder implements FacetUrlDecoderInterface */ public function decode(string $value, array $configuration = []): string { - return $configuration[$value . '.']['query']; + return $configuration[$value . '.']['query'] ?? ''; } } From 99143fc4cb8cadb81a8cb7af6acbc59b4cc51636 Mon Sep 17 00:00:00 2001 From: Markus Friedrich Date: Mon, 27 Mar 2023 13:42:13 +0200 Subject: [PATCH 2/2] [TASK] Handle invalid facet options 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. --- Classes/Query/Modifier/Faceting.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Classes/Query/Modifier/Faceting.php b/Classes/Query/Modifier/Faceting.php index 8355484855..b80415f5a9 100644 --- a/Classes/Query/Modifier/Faceting.php +++ b/Classes/Query/Modifier/Faceting.php @@ -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 @@ -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; @@ -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;