Repository navigation
feat(react): add mergeFacetFilters helper - #3066
Merged
Merged
Conversation
8bittitan
requested review from
LorrisSaintGenez,
NatanTechofNY,
dylantientcheu,
pipeline1987 and
shortcuts
as code owners
October 28, 2026 14:32
✅ Deploy Preview for docsearch-demo ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for docsearch ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
pipeline1987
approved these changes
Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Docusaurus is upgrading to DocSearch v5 (meta/docusaurus#12406) and needs to combine the filters it builds from the current page (language, version tags) with the
facetFiltersa site sets in its config. It currently carries its own merge logic for this, and the maintainers asked for it to live in DocSearch instead of being maintained on their side.This adds a
mergeFacetFiltershelper, exposed from a new@docsearch/react/utilssubpath. It's a separate entry so consumers can import it without pulling in any components. The only runtime dependency isgetFacetFilterKey, and the file it comes from imports types only.Why the merge isn't a plain concat
Algolia treats top-level entries as AND and nested arrays as OR. If a page filter says
language:enand the site config sayslanguage:es, joining them as AND returns nothing, since a record has one language. The helper follows how faceted search and the facet bar here already behave: the same facet across inputs is ORed, and different facets are ANDed.The rules I kept narrow on purpose, so the helper doesn't guess what a caller meant:
['_tags:docs', '_tags:v2']stays an AND.status:-draft) are never merged, so exclusions add up instead of being undone.Because this ORs values, it can widen a base filter.
facetFiltersaren't access control (secured API keys are), so I don't think that's a concern, but it's worth knowing if you use this for anything restrictive.Testing
Unit tests cover the cases above, including the "multiple filters with AND and OR" example from the Algolia docs.
bun run test --run packages/docsearch-react/src/utils/__tests__/mergeFacetFilters.test.tsTo check the export after a build:
Then confirm
packages/docsearch-react/dist/esm/utils.jsandutils.d.tsexist, and tryimport { mergeFacetFilters } from '@docsearch/react/utils'from a consumer. Some calls worth trying: