mirror of https://github.com/apache/lucene.git
LUCENE-7560: make QueryBuilder.analyzeXXX methods protected
This commit is contained in:
parent
b426838e8f
commit
bb3278dd17
|
@ -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) {
|
||||||
|
@ -186,9 +186,12 @@ public class QueryBuilder {
|
||||||
/**
|
/**
|
||||||
* Creates a query from the analysis chain.
|
* Creates a query from the analysis chain.
|
||||||
* <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
|
||||||
|
@ -265,7 +268,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();
|
||||||
|
@ -279,7 +282,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();
|
||||||
|
@ -291,7 +294,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;
|
||||||
}
|
}
|
||||||
|
@ -305,7 +308,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<>();
|
||||||
|
|
||||||
|
@ -328,7 +331,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);
|
||||||
|
|
||||||
|
@ -352,7 +355,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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue