From e8c2218c3a9c9de1f845b50d88702642ed6622e5 Mon Sep 17 00:00:00 2001 From: Shubham Chaudhary <36742242+shubhamvishu@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:01:34 +0530 Subject: [PATCH] Make some BooleanQuery methods public and a new `#add(Collection)` method for BQ builder (#13950) --- lucene/CHANGES.txt | 2 ++ .../org/apache/lucene/search/BooleanQuery.java | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 439dc3fe9d2..0e615b95f8f 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -10,6 +10,8 @@ API Changes * GITHUB#13859: Allow open-ended ranges in Intervals range queries. (Mayya Sharipova) +* GITHUB#13950: Make BooleanQuery#getClauses public and add #add(Collection) to BQ builder. (Shubham Chaudhary) + New Features --------------------- diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java index 4798745ef67..0d6daa07ba1 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java @@ -87,6 +87,22 @@ public class BooleanQuery extends Query implements Iterable { return this; } + /** + * Add a collection of BooleanClauses to this {@link Builder}. Note that the order in which + * clauses are added does not have any impact on matching documents or query performance. + * + * @throws IndexSearcher.TooManyClauses if the new number of clauses exceeds the maximum clause + * number + */ + public Builder add(Collection collection) { + // see #addClause(BooleanClause) + if ((clauses.size() + collection.size()) > IndexSearcher.maxClauseCount) { + throw new IndexSearcher.TooManyClauses(); + } + clauses.addAll(collection); + return this; + } + /** * Add a new clause to this {@link Builder}. Note that the order in which clauses are added does * not have any impact on matching documents or query performance. @@ -136,7 +152,7 @@ public class BooleanQuery extends Query implements Iterable { } /** Return the collection of queries for the given {@link Occur}. */ - Collection getClauses(Occur occur) { + public Collection getClauses(Occur occur) { return clauseSets.get(occur); }