diff --git a/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java b/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java index 977af5387e6..6c5ea15aac5 100644 --- a/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java +++ b/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java @@ -51,8 +51,8 @@ import org.apache.lucene.search.TermQuery; * are provided so that the generated queries can be customized. */ public class QueryBuilder { - private Analyzer analyzer; - private boolean enablePositionIncrements = true; + protected Analyzer analyzer; + protected boolean enablePositionIncrements = true; /** Creates a new QueryBuilder using the given analyzer. */ public QueryBuilder(Analyzer analyzer) { @@ -186,9 +186,12 @@ public class QueryBuilder { /** * Creates a query from the analysis chain. *
- * Expert: this is more useful for subclasses such as queryparsers.
+ * Expert: this is more useful for subclasses such as queryparsers.
* If using this class directly, just use {@link #createBooleanQuery(String, String)}
- * and {@link #createPhraseQuery(String, String)}
+ * and {@link #createPhraseQuery(String, String)}. This is a complex method and
+ * it is usually not necessary to override it in a subclass; instead, override
+ * methods like {@link #newBooleanQuery}, etc., if possible.
+ *
* @param analyzer analyzer used for this query
* @param operator default boolean operator used for this query
* @param field field to create queries against
@@ -265,7 +268,7 @@ public class QueryBuilder {
/**
* Creates simple term query from the cached tokenstream contents
*/
- private Query analyzeTerm(String field, TokenStream stream) throws IOException {
+ protected Query analyzeTerm(String field, TokenStream stream) throws IOException {
TermToBytesRefAttribute termAtt = stream.getAttribute(TermToBytesRefAttribute.class);
stream.reset();
@@ -279,7 +282,7 @@ public class QueryBuilder {
/**
* Creates simple boolean query from the cached tokenstream contents
*/
- private Query analyzeBoolean(String field, TokenStream stream) throws IOException {
+ protected Query analyzeBoolean(String field, TokenStream stream) throws IOException {
TermToBytesRefAttribute termAtt = stream.getAttribute(TermToBytesRefAttribute.class);
stream.reset();
@@ -291,7 +294,7 @@ public class QueryBuilder {
return newSynonymQuery(terms.toArray(new Term[terms.size()]));
}
- private void add(BooleanQuery.Builder q, List