Skip to content

Conversation

@Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Nov 20, 2024

Summary

Use the values of the main facet in disjunctive facets

This is relevant in two cases:

  • second query is non-exhaustive
  • second query is not correct due to facet count after distinct

There's still more edge cases left (first query non exhaustive, but second isn't, but that's unlikely) and those are not worse after this PR.

Result

disjunctive facets read the count from the first query over the ones from the second query. This is already the case for hierarchical facets.

This is relevant in two cases:
- second query is non-exhaustive
- second query is not correct due to facet count after distinct

There's still more edge cases left (first query non exhaustive, but second isn't, but that's unlikely) and those are not worse after this PR.
@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 20, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 4f2b466:

Sandbox Source
example-instantsearch-getting-started Configuration
example-react-instantsearch-getting-started Configuration
example-react-instantsearch-next-app-dir-example Configuration
example-react-instantsearch-next-routing-example Configuration
example-vue-instantsearch-getting-started Configuration

@Haroenv Haroenv marked this pull request as ready for review November 20, 2024 16:43
@Haroenv Haroenv requested review from a team, dhayab and shaejaz and removed request for a team November 20, 2024 16:44
@Haroenv Haroenv added the 🚨 DO NOT MERGE for a pull request that is ready to review, but should not be merged yet label Nov 20, 2024
Copy link
Member

@dhayab dhayab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works great for disjunctive refinements. Looking at the customer issue again, they experience this on a conjunctive refinement, which is not covered by this fix. Do you want to handle this in a subsequent PR or can you add it here?

@Haroenv
Copy link
Contributor Author

Haroenv commented Nov 21, 2024

How could they have this issue on a conjunctive facet? there's only one query there

@dhayab
Copy link
Member

dhayab commented Nov 21, 2024

Sorry I was wrong, I thought the menu widget was using conjunctive faceting but it instead is based on hierarchical facets. In that case, we do reattribute the root level count but not in this instance?

screenshot-20241121-102734@2x

@Haroenv Haroenv requested a review from dhayab November 22, 2024 08:46
@Haroenv
Copy link
Contributor Author

Haroenv commented Nov 22, 2024

@dhayab fixed now for hierarchical too, but only if persistHierarchicalRootCount is true, other cases seemed to break a lot of tests

@dhayab
Copy link
Member

dhayab commented Nov 22, 2024

Nice, thanks!

Copy link
Member

@dhayab dhayab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, thank you!

@dhayab dhayab removed the 🚨 DO NOT MERGE for a pull request that is ready to review, but should not be merged yet label Dec 9, 2024
@Haroenv Haroenv enabled auto-merge (squash) December 9, 2024 09:28
@Haroenv Haroenv merged commit 9bc841a into master Dec 9, 2024
13 of 14 checks passed
@Haroenv Haroenv deleted the fix/disjunctive-prefer-main branch December 9, 2024 09:34
Haroenv added a commit that referenced this pull request Jan 20, 2025
When doing disjunctive faceting, there are two different sets of results:

1. the results with the filter applied
2. the results without the filter applied

Normally we want to use the facets of result 2, as those don't have the other constraints applied. think for example of this:

```json
[
  {
    "facetFilters": ["f:alpha"],
    "hits": [{ "f": ["alpha", "beta"] }],
    "facets": { "f": { "alpha": 1, "beta": 1 } }
  },
  {
    "hits": [{ "f": ["alpha", "beta"] }, { "f": ["beta", "gamma"] }],
    "facets": { "f": { "alpha": 1, "beta": 2, "gamma": 1 } }
  }
]
```

This was the behaviour before #6445. In #6445 we have swapped the order, to cater for "more tricky" use cases like non-exhaustive second response, less results in second response due to remove words optional or distinct.

Therefore now we take the middle ground: use the highest value. This works for all existing test cases, as well as newly introduced ones that simulate the "array" use case.

see #6482, [CR-7169], #6445.
Haroenv added a commit that referenced this pull request Jan 21, 2025
* fix(facets): choose highest value in disjunctive

When doing disjunctive faceting, there are two different sets of results:

1. the results with the filter applied
2. the results without the filter applied

Normally we want to use the facets of result 2, as those don't have the other constraints applied. think for example of this:

```json
[
  {
    "facetFilters": ["f:alpha"],
    "hits": [{ "f": ["alpha", "beta"] }],
    "facets": { "f": { "alpha": 1, "beta": 1 } }
  },
  {
    "hits": [{ "f": ["alpha", "beta"] }, { "f": ["beta", "gamma"] }],
    "facets": { "f": { "alpha": 1, "beta": 2, "gamma": 1 } }
  }
]
```

This was the behaviour before #6445. In #6445 we have swapped the order, to cater for "more tricky" use cases like non-exhaustive second response, less results in second response due to remove words optional or distinct.

Therefore now we take the middle ground: use the highest value. This works for all existing test cases, as well as newly introduced ones that simulate the "array" use case.

see #6482, [CR-7169], #6445.

* bundlesize, unavoidable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants