-
Notifications
You must be signed in to change notification settings - Fork 697
(feat) Add prefix and regex filtering for term facets #2242
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
(feat) Add prefix and regex filtering for term facets #2242
Conversation
This change adds support for filtering facet terms by prefix and/or
regex pattern. Which is useful for faceting during search_as_you_type
style faceting for terms that match what is in the searchbar,
aggregated by field (for books I can facet facet authors, titles etc
in an autosuggest a bit cleaner now).
- Adds TermPrefix and TermPattern fields to FacetRequest
- Updated all callers of NewTermsFacetBuilder (now returns error)
- Only matching terms trigger string allocation from []byte
Example usage:
{
"facets": {
"prod_categories": {
"field": "category",
"size": 10,
"prefix": "prod-"
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds prefix and regex filtering capabilities to term facets in Bleve's search functionality, enabling search-as-you-type style faceting where terms can be filtered to match patterns during aggregation.
Key changes:
- Added
TermPrefixandTermPatternfields toFacetRequeststruct for filtering configuration - Modified
NewTermsFacetBuilderto accept prefix and pattern parameters and return an error for invalid regex patterns - Optimized
UpdateVisitorto perform zero-allocation prefix and regex matching on[]bytebefore converting to string
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| search.go | Added TermPrefix and TermPattern fields to FacetRequest for API support |
| search/facet/facet_builder_terms.go | Implemented prefix/regex filtering logic with optimized byte-level matching |
| index_impl.go | Updated to pass prefix and pattern parameters to NewTermsFacetBuilder and handle errors |
| search/collector/topn_test.go | Updated test to handle new error-returning signature of NewTermsFacetBuilder |
| search/facet/facet_builder_terms_test.go | Added comprehensive test coverage for prefix, regex, combined filtering, and edge cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add SetPrefixFilter/SetRegexFilter to FacetRequest and TermsFacetBuilder - Validate regex patterns in FacetRequest.Validate() - Revert NewTermsFacetBuilder signature to avoid breaking changes - Improve code clarity and size estimation
823fd99 to
e344c09
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
search/facet/facet_builder_terms.go:122
- The
missingcounter may not accurately reflect documents without matching values when filters are active. A document with terms that don't match the filters will be counted as "missing" even though it has values for the field. Consider whether this is the intended behavior or ifmissingshould only count documents that truly have no value for the field, regardless of filters.
If the current behavior is intentional (i.e., "missing" means "no matching values"), the documentation should be updated to clarify this semantic change when filters are applied.
}
func (fb *TermsFacetBuilder) EndDoc() {
if !fb.sawValue {
fb.missing++
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
abhinavdangeti
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks for this @ajroetker .
This change adds support for filtering facet terms by prefix and/or regex pattern. Which is useful for faceting during
search_as_you_typestyle faceting for terms that match what is in the searchbox, aggregated by field (for books I can facet facet authors, titles etc in an autosuggest a bit cleaner now).TermPrefixandTermPatternfields to FacetRequestNewTermsFacetBuilderto return error[]byte