From bb3278dd1797a45e06e7c03445ead75bad09828b Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Mon, 21 Nov 2016 06:29:05 -0500 Subject: [PATCH] LUCENE-7560: make QueryBuilder.analyzeXXX methods protected --- .../org/apache/lucene/util/QueryBuilder.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) 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 current, BooleanClause.Occur operator) { + protected void add(BooleanQuery.Builder q, List current, BooleanClause.Occur operator) { if (current.isEmpty()) { return; } @@ -305,7 +308,7 @@ public class QueryBuilder { /** * Creates complex boolean query from the cached tokenstream contents */ - private Query analyzeMultiBoolean(String field, TokenStream stream, BooleanClause.Occur operator) throws IOException { + protected Query analyzeMultiBoolean(String field, TokenStream stream, BooleanClause.Occur operator) throws IOException { BooleanQuery.Builder q = newBooleanQuery(); List currentQuery = new ArrayList<>(); @@ -328,7 +331,7 @@ public class QueryBuilder { /** * Creates simple phrase query from the cached tokenstream contents */ - private Query analyzePhrase(String field, TokenStream stream, int slop) throws IOException { + protected Query analyzePhrase(String field, TokenStream stream, int slop) throws IOException { PhraseQuery.Builder builder = new PhraseQuery.Builder(); builder.setSlop(slop); @@ -352,7 +355,7 @@ public class QueryBuilder { /** * Creates complex phrase query from the cached tokenstream contents */ - private Query analyzeMultiPhrase(String field, TokenStream stream, int slop) throws IOException { + protected Query analyzeMultiPhrase(String field, TokenStream stream, int slop) throws IOException { MultiPhraseQuery.Builder mpqb = newMultiPhraseQueryBuilder(); mpqb.setSlop(slop);