Skip to content

MB-65170: Add filter support to BooleanQuery#2220

Merged
CascadingRadium merged 4 commits into
masterfrom
booleanFilter
Sep 3, 2025
Merged

MB-65170: Add filter support to BooleanQuery#2220
CascadingRadium merged 4 commits into
masterfrom
booleanFilter

Conversation

@CascadingRadium

Copy link
Copy Markdown
Member
  • Add a Filter query for Boolean queries, which filters the document set returned by the
    Boolean query itself.
  • The filter query does not affect scores, and any document returned by the Boolean query
    must also satisfy the filter query.
  • The key difference between using a Filter query and placing an equivalent query in the
    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.
  • Requires a Bug Fix (BugFix: Fixed Advance() API implementation in Optimized Composite Searchers #2146)
    to allow for the usage of the Advanced API in case the FilterQuery is an optimized
    composite searcher.
  • Resolves support Filter in searcher like elasticsearch #2037

@abhinavdangeti

abhinavdangeti commented Aug 21, 2025

Copy link
Copy Markdown
Member

The key difference between using a Filter query and placing an equivalent query in the
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.

While I understand the reason for this filter component and how it's different from the must clause - can you highlight a case where this feature would actually be helpful?

@abhinavdangeti abhinavdangeti requested a review from Copilot August 21, 2025 16:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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.

Comment thread search/query/boolean.go Outdated
Comment thread search/query/boolean.go Outdated
@CascadingRadium

Copy link
Copy Markdown
Member Author

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.

@CascadingRadium CascadingRadium merged commit 03d34d9 into master Sep 3, 2025
9 checks passed
@CascadingRadium CascadingRadium deleted the booleanFilter branch September 3, 2025 09:51
ns-codereview pushed a commit to couchbase/cbft that referenced this pull request Oct 6, 2025
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>
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.

support Filter in searcher like elasticsearch

4 participants