MB-65170: Add filter support to BooleanQuery#2220
Conversation
While I understand the reason for this |
There was a problem hiding this comment.
Pull Request Overview
This PR adds filter support to BooleanQuery, introducing a new Filter field that allows filtering documents without affecting their scores. This is distinct from Must clauses which contribute to scoring while Filter clauses purely filter documents.
- Adds a Filter field to BooleanQuery structure with corresponding AddFilter method
- Updates FilterFunc signature to accept SearchContext parameter across multiple searcher types
- Implements filter logic in BooleanQuery.Searcher() that wraps base searcher with FilteringSearcher when filter is present
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| search/query/boolean.go | Adds Filter field, AddFilter method, and filter logic implementation |
| search/query/query.go | Updates ParseQuery to recognize "filter" field in boolean queries |
| search/searcher/search_filter.go | Updates FilterFunc signature to include SearchContext parameter |
| search/searcher/search_geoboundingbox.go | Updates filter function signature to match new FilterFunc |
| search/searcher/search_geopointdistance.go | Updates filter function signature to match new FilterFunc |
| search/searcher/search_geopolygon.go | Updates filter function signature to match new FilterFunc |
| search/searcher/search_geoshape.go | Updates filter function signature to match new FilterFunc |
| search_test.go | Adds comprehensive test for filtered boolean query functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Good use of Filter here — unlike Must, it restricts results without affecting scores. This is helpful for things like date ranges, access control, or faceted filters (e.g., brand/price in e-commerce) where we don’t want the constraint to influence ranking. |
Relates: blevesearch/bleve#2220 Change-Id: I15a7b6f4bd3b3d46c7a86a7f8f86ef1880548189 Reviewed-on: https://review.couchbase.org/c/cbft/+/234681 Well-Formed: Build Bot <build@couchbase.com> Tested-by: Abhi Dangeti <abhinav@couchbase.com> Reviewed-by: Rahul Rampure <rahul.rampure@couchbase.com>
Boolean query itself.
must also satisfy the filter query.
Must clause is that queries in the Must clause contribute to the score. The Filter
query is intended purely for filtering purposes without modifying the document scores
set by the base Boolean query.
to allow for the usage of the Advanced API in case the FilterQuery is an optimized
composite searcher.