Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling facet counts when there are disjunctive filters within a filter, across a set of conjunctive faceted filters. #1580

Closed
mvattuone opened this issue Feb 6, 2025 · 3 comments

Comments

@mvattuone
Copy link

I noticed this quote in an issue from a few years back

When you use the helper and have a disjunctive refinement, it sends that second query to get the correct facet counts. If you look at the results of the first facet, you'll see that they are conjunctive (only the facets remaining in that result set), and not disjunctive as requested. That's what the second query is for.

Originally posted by @Haroenv in #1404

My understanding was that handling disjunctive facet counts is only managed via InstantSearch according to Algolia's documentation https://support.algolia.com/hc/en-us/articles/11923043923217-How-can-I-configure-my-facet-attribute-as-conjunctive-AND-disjunctive-OR

We are not using InstantSearch, and I am trying to figure out how Algolia handles disjunctive facet counts so that I can replicate it in my application. I've gotten close with my own second request that I've added, where I effectively exclude the last applied filter, but I'm finding edge cases (particular initially accessing a page with filters applied (e.g. query params), and feel like if it's a solved problem on your end, it would be great to utilize your solution without having to use InstantSearch components.

Could you help me understand how that second request is made using your client? Or show me where in InstantSearch it is handled? Happy to share more details if that would help contextualize my issue.

Just to clarify, this is a set of search filters, all conjunctive, but options within each search filter are disjunctive.

@mvattuone mvattuone changed the title Handling disjunctive facet counts when creating a search that contains both disjunctive and conjunctive refinements Handling facet counts when there are disjunctive filters within a filter, across a set of conjunctive facets. Feb 6, 2025
@mvattuone mvattuone changed the title Handling facet counts when there are disjunctive filters within a filter, across a set of conjunctive facets. Handling facet counts when there are disjunctive filters within a filter, across a set of conjunctive faceted filters. Feb 6, 2025
@shortcuts
Copy link
Member

Hey! I believe this would be handled in this package, and @Haroenv might be able to exactly point out that logic

@Haroenv
Copy link
Contributor

Haroenv commented Feb 6, 2025

relevant code here: https://github.com/algolia/instantsearch/blob/master/packages/algoliasearch-helper/src/requestBuilder.js for computing the queries, and https://github.com/algolia/instantsearch/blob/master/packages/algoliasearch-helper/src/SearchResults/index.js (big file, it's in many parts of it) for reading it in the end.

I recommend you just use the helper or InstantSearch though, this is complicated code that you'd rather have vendored IMO

@mvattuone
Copy link
Author

@Haroenv Gotcha - I wound up looking at how the requests were built in an InstantSearch demo and got what I needed. At first I was hoping there was a way to handle this without creating several requests (or even any additional requests), but I see we can send them all at once to your API, so that's cool. 👍

We probably should use your libraries (and I may look into that helper if I can get the OK to add the dependency), but to be honest, we may not use Algolia in the future for cost reasons (nothing personal! it's just the state of the world!), so we'd rather not get too dependent on things outside of the main search functionality you provide if we decide to use a different service, since there are many similar versions out there and refactoring the search itself wouldn't be too hard, but I'm not so sure about the InstantSearch components.

Thanks for responding and for the help, I really appreciate it! I'll go ahead and close this.

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

No branches or pull requests

3 participants