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::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
CommentFileSizeAuthor
#3 3498459-3.patch1.46 KBnixou
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

nixou created an issue. See original summary.

nixou’s picture

Issue summary: View changes
nixou’s picture

Status: Active » Needs review
StatusFileSize
new1.46 KB
jsacksick’s picture

Thank you, this looks like an interesting change... Wondering if this is what's causing OR facets to act weirdly as well, I seem to be getting the right facet values back with this patch, I'll open an MR to see if this broke any test.

jsacksick’s picture

The tests are failing on with D11 on dev as well... But this seems to alter the behavior of OR facets... But I think it fixes it... I'm not 100% sure though so a bit hesitant to commit this.

  • jsacksick committed ae0b7be5 on 8.x-1.x
    Issue #3498459: Incorrect condition groups nesting leads to incorrect...
jsacksick’s picture

Status: Needs review » Fixed

Ok decided to go ahead and merge this! Hopefully I won't regret this :).

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.