LUCENE-7560: make QueryBuilder.analyzeXXX methods protected

This commit is contained in:
Mike McCandless 2016-11-21 06:29:05 -05:00
parent 3e2800ea04
commit 5d5e274962
1 changed files with 13 additions and 10 deletions

View File

@ -51,8 +51,8 @@ import org.apache.lucene.search.TermQuery;
* are provided so that the generated queries can be customized. * are provided so that the generated queries can be customized.
*/ */
public class QueryBuilder { public class QueryBuilder {
private Analyzer analyzer; protected Analyzer analyzer;
private boolean enablePositionIncrements = true; protected boolean enablePositionIncrements = true;
/** Creates a new QueryBuilder using the given analyzer. */ /** Creates a new QueryBuilder using the given analyzer. */
public QueryBuilder(Analyzer analyzer) { public QueryBuilder(Analyzer analyzer) {
@ -189,7 +189,10 @@ public class QueryBuilder {
* <p> * <p>
* 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)} * 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 analyzer analyzer used for this query
* @param operator default boolean operator used for this query * @param operator default boolean operator used for this query
* @param field field to create queries against * @param field field to create queries against
@ -266,7 +269,7 @@ public class QueryBuilder {
/** /**
* Creates simple term query from the cached tokenstream contents * 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); TermToBytesRefAttribute termAtt = stream.getAttribute(TermToBytesRefAttribute.class);
stream.reset(); stream.reset();
@ -280,7 +283,7 @@ public class QueryBuilder {
/** /**
* Creates simple boolean query from the cached tokenstream contents * 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); TermToBytesRefAttribute termAtt = stream.getAttribute(TermToBytesRefAttribute.class);
stream.reset(); stream.reset();
@ -292,7 +295,7 @@ public class QueryBuilder {
return newSynonymQuery(terms.toArray(new Term[terms.size()])); return newSynonymQuery(terms.toArray(new Term[terms.size()]));
} }
private void add(BooleanQuery.Builder q, List<Term> current, BooleanClause.Occur operator) { protected void add(BooleanQuery.Builder q, List<Term> current, BooleanClause.Occur operator) {
if (current.isEmpty()) { if (current.isEmpty()) {
return; return;
} }
@ -306,7 +309,7 @@ public class QueryBuilder {
/** /**
* Creates complex boolean query from the cached tokenstream contents * 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(); BooleanQuery.Builder q = newBooleanQuery();
List<Term> currentQuery = new ArrayList<>(); List<Term> currentQuery = new ArrayList<>();
@ -329,7 +332,7 @@ public class QueryBuilder {
/** /**
* Creates simple phrase query from the cached tokenstream contents * 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(); PhraseQuery.Builder builder = new PhraseQuery.Builder();
builder.setSlop(slop); builder.setSlop(slop);
@ -353,7 +356,7 @@ public class QueryBuilder {
/** /**
* Creates complex phrase query from the cached tokenstream contents * 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(); MultiPhraseQuery.Builder mpqb = newMultiPhraseQueryBuilder();
mpqb.setSlop(slop); mpqb.setSlop(slop);