Skip to content
Snippets Groups Projects
Commit ae0b7be5 authored by Jonathan Sacksick's avatar Jonathan Sacksick
Browse files

Issue #3498459: Incorrect condition groups nesting leads to incorrect facets count

parent 7d6842b4
No related branches found
No related tags found
1 merge request!17Issue #3498459 by nixou, jsacksick: Incorrect condition groups nesting leads...
Pipeline #450232 passed
...@@ -272,7 +272,7 @@ final class IndexFacetsTest extends BrowserTestBase { ...@@ -272,7 +272,7 @@ final class IndexFacetsTest extends BrowserTestBase {
'condition' => [ 'condition' => [
'path' => 'keywords', 'path' => 'keywords',
'operator' => 'IN', 'operator' => 'IN',
'value' => ['grape', 'strawberry'], 'value' => ['grape', 'strawberry', 'banana', 'apple'],
], ],
], ],
]; ];
......
...@@ -21,6 +21,8 @@ use Drupal\search_api\IndexInterface; ...@@ -21,6 +21,8 @@ use Drupal\search_api\IndexInterface;
use Drupal\search_api\Item\ItemInterface; use Drupal\search_api\Item\ItemInterface;
use Drupal\search_api\ParseMode\ParseModeInterface; use Drupal\search_api\ParseMode\ParseModeInterface;
use Drupal\search_api\ParseMode\ParseModePluginManager; use Drupal\search_api\ParseMode\ParseModePluginManager;
use Drupal\search_api\Query\ConditionGroupInterface;
use Drupal\search_api\Query\ConditionInterface;
use Drupal\search_api\Query\QueryInterface; use Drupal\search_api\Query\QueryInterface;
use Drupal\search_api\SearchApiException; use Drupal\search_api\SearchApiException;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
...@@ -170,7 +172,18 @@ final class IndexResource extends EntityResourceBase implements ContainerInjecti ...@@ -170,7 +172,18 @@ final class IndexResource extends EntityResourceBase implements ContainerInjecti
} }
try { try {
$filter = Filter::createFromQueryParameter($filter); $filter = Filter::createFromQueryParameter($filter);
$query->addConditionGroup($filter->queryCondition($query));
$root_group = $query->getConditionGroup();
$new_group = $filter->queryCondition($query);
foreach ($new_group->getConditions() as $element) {
if ($element instanceof ConditionInterface) {
$root_group->addCondition($element->getField(), $element->getValue(), $element->getOperator());
}
elseif ($element instanceof ConditionGroupInterface) {
$root_group->addConditionGroup($element);
}
}
} }
catch (\Exception $exception) { catch (\Exception $exception) {
throw new CacheableBadRequestHttpException($cacheability, $exception->getMessage()); throw new CacheableBadRequestHttpException($cacheability, $exception->getMessage());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment