Problem/Motivation

There seems to be an issue with the facet.missing (Show missing) feature for facets based on multi-valued fields using OR operator.

When enabling the feature on such facet, the facet count is correct, but the filtering is wrong and returns most of the time all documents.
It looks like the operator within the condition group is determined by the facet operator itself, as seen here, which is currently set to OR in such cases.

It doesn't look correct, if we have 4 documents with values:
- D1: A, B, C
- D2: B
- D3: A, C
- D4: /

We want to return 1 result: !A AND !B AND !C -> D4
Instead of currently 3 results: !A OR !B OR !C -> D2, D3, D4
In other words, I believe the operator within this condition group should always be an AND.

Steps to reproduce

On a standard profile:
- Enable search_api, search_api_db_defaults and facets
- Create a facet for field_tags (operator: OR, Show the amount of results: enabled, Show missing: enabled) and display it from blocks
- Create some tags terms and some article documents (with e.g. values as explained above)
- When filtering on "Other (1)" we get D2, D3, D4 instead of D4

Note: the result is the same with search_api_solr

Proposed resolution

I can't see any situation where an OR operator would be needed, so update SearchApiString to create a condition group for the facet.missing feature and always apply an AND.

Remaining tasks

/

User interface changes

/

API changes

/

Data model changes

/

Issue fork facets-3344081

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

herved created an issue. See original summary.

herved’s picture

Assigned: herved » Unassigned
Status: Active » Needs review
StatusFileSize
new1.42 KB
stefan.korn’s picture

I can confirm the issue and confirm that the patch solves the issue.

Thanks @herved

ericgsmith’s picture

Status: Needs review » Reviewed & tested by the community

+1 for RTBC

ericgsmith’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new4.55 KB
new3.13 KB

Adding a test for this

ericgsmith’s picture

StatusFileSize
new4.56 KB
new1.02 KB

Fixed coding standards error in test.

The 2 failed tests are currently failing in the 2.0.x branch (https://www.drupal.org/pift-ci-job/2658100).

Comment #6 is still just test only addition from #2 which had no failures - I will try remember to come back and retest it assuming the tests in the main branch will get fixed some time soon.

ericgsmith’s picture

herved’s picture

I wonder, does the exclude facet option work with this condition?
I think it won't but I have not tested yet.

ericgsmith’s picture

You are correct, this does break the exclude logic.

I think having the separate condition group for the missing condition is correct, and the missing condition group operator could be determined based on the exclude value.

ericgsmith’s picture

StatusFileSize
new8.01 KB
new5.98 KB

How does that look?

Improved the test a bit to more clearly show the expected condition groups.

ericgsmith’s picture

Version: 2.0.x-dev » 3.0.x-dev

ericgsmith’s picture

Moved patch to MR - CI shows test job passing + expected failure of the test only change

ericgsmith’s picture

Rebased MR - noting tests currently failing due to #3579256: Failing DefaultFacetManagerTest