Incorrect condition groups nesting leads to incorrect facets count

Created on 9 January 2025, 22 days ago

Problem/Motivation

The Search Api original $query object comes with a ConditionGroup at its root.

When calling $query->addConditionGroup($filter->queryCondition($query)); into jsonapi_search_api/src/Resource/IndexResource.phpIndexResource::applyFiltersToQuery() it adds a group into the root group of the $query object.

The final organization is :

Query Original Root Group created by Search Api
  > Root Group created by Json Api Search Api
    > ... conditions / groups provided by the query

This is not how Search Api does it through Views and it's not compatible with how Search Api SOLR will factorize the groups and tags in its createFilterQueries() methods.

In the end, facets tags are associated with all query filters even if they are not a facet filters and this leads to incorrect facets count.

Steps to reproduce

1. Using Search Api and Search Api SOLR, create a query with non facet filters (for example per language and per category) and facet filters (for example per product characteristic)
2. Put each filters in its own group
3. Perform the query and see that facets counts include results from other languages and categories

Proposed resolution

Instead of creating an additonnal root group, just fill the original root group provided in the query, so the final organization will be :

Query Original Root Group created by Search Api
  > ... conditions / groups provided by the query
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇫🇷France Nixou Toulon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024