From c40c7cd114938aeddaefff5503fc877c25420251 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Wed, 16 Nov 2005 16:39:59 +0000 Subject: [PATCH] BooleanQuery/BooleanScorer minNrShouldMatch implementation: LUCENE-395 git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@345056 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 4 + .../apache/lucene/search/BooleanQuery.java | 64 ++- .../apache/lucene/search/BooleanScorer2.java | 176 ++++---- .../search/TestBooleanMinShouldMatch.java | 380 ++++++++++++++++++ 4 files changed, 542 insertions(+), 82 deletions(-) create mode 100644 src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java diff --git a/CHANGES.txt b/CHANGES.txt index 2a27452ad16..663c4bc630e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -179,6 +179,10 @@ New features number of terms the range can cover. Both endpoints may also be open. (Yonik Seeley, LUCENE-383) +26. Added ability to specify a minimum number of optional clauses that + must match in a BooleanQuery. See BooleanQuery.setMinimumNumberShouldMatch(). + (Paul Elschot, Chris Hostetter via Yonik Seeley, LUCENE-395) + API Changes 1. Several methods and fields have been deprecated. The API documentation diff --git a/src/java/org/apache/lucene/search/BooleanQuery.java b/src/java/org/apache/lucene/search/BooleanQuery.java index 279cbc32f34..b459ed581a7 100644 --- a/src/java/org/apache/lucene/search/BooleanQuery.java +++ b/src/java/org/apache/lucene/search/BooleanQuery.java @@ -107,6 +107,41 @@ public class BooleanQuery extends Query { return result; } + /** + * Specifies a minimum number of the optional BooleanClauses + * which must be satisifed. + * + *

+ * By default no optional clauses are neccessary for a match + * (unless there are no required clauses). If this method is used, + * then the specified numebr of clauses is required. + *

+ *

+ * Use of this method is totally independant of specifying that + * any specific clauses are required (or prohibited). This number will + * only be compared against the number of matching optional clauses. + *

+ *

+ * EXPERT NOTE: Using this method will force the use of BooleanWeight2, + * regardless of wether setUseScorer14(true) has been called. + *

+ * + * @param min the number of optional clauses that must match + * @see #setUseScorer14 + */ + public void setMinimumNumberShouldMatch(int min) { + this.minNrShouldMatch = min; + } + protected int minNrShouldMatch = 0; + + /** + * Gets the minimum number of the optional BooleanClauses + * which must be satisifed. + */ + public int getMinimumNumberShouldMatch() { + return minNrShouldMatch; + } + /** Adds a clause to a boolean query. Clauses may be: *