Skip to content

Commit

Permalink
Remove unused query methods from MappedFieldType. (#30987)
Browse files Browse the repository at this point in the history
* Remove MappedFieldType#nullValueQuery, as it is now unused.
* Remove MappedFieldType#queryStringTermQuery, as it is never overridden.
  • Loading branch information
jtibshirani authored May 31, 2018
1 parent 4f66b9a commit cd0a375
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,6 @@ public Query existsQuery(QueryShardContext context) {
return new TermQuery(new Term("_feature", name()));
}

@Override
public Query nullValueQuery() {
if (nullValue() == null) {
return null;
}
return termQuery(nullValue(), null);
}

@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,6 @@ public Query existsQuery(QueryShardContext context) {
}
}

@Override
public Query nullValueQuery() {
if (nullValue() == null) {
return null;
}
return termQuery(nullValue(), null);
}

@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@

package org.apache.lucene.queries;

import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.Query;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.index.mapper.MappedFieldType;

/**
* Extended version of {@link CommonTermsQuery} that allows to pass in a
Expand All @@ -33,11 +29,8 @@
*/
public class ExtendedCommonTermsQuery extends CommonTermsQuery {

private final MappedFieldType fieldType;

public ExtendedCommonTermsQuery(Occur highFreqOccur, Occur lowFreqOccur, float maxTermFrequency, MappedFieldType fieldType) {
public ExtendedCommonTermsQuery(Occur highFreqOccur, Occur lowFreqOccur, float maxTermFrequency) {
super(highFreqOccur, lowFreqOccur, maxTermFrequency);
this.fieldType = fieldType;
}

private String lowFreqMinNumShouldMatchSpec;
Expand Down Expand Up @@ -80,16 +73,4 @@ public float getMaxTermFrequency() {
return this.maxTermFrequency;
}

@Override
protected Query newTermQuery(Term term, TermContext context) {
if (fieldType == null) {
return super.newTermQuery(term, context);
}
final Query query = fieldType.queryStringTermQuery(term);
if (query == null) {
return super.newTermQuery(term, context);
} else {
return query;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,6 @@ public Query existsQuery(QueryShardContext context) {
}
}

@Override
public Query nullValueQuery() {
if (nullValue() == null) {
return null;
}
return termQuery(nullValue(), null);
}

@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,6 @@ public Query regexpQuery(String value, int flags, int maxDeterminizedStates, @Nu
throw new QueryShardException(context, "Can only use regexp queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]");
}

public Query nullValueQuery() {
if (nullValue == null) {
return null;
}
return new ConstantScoreQuery(termQuery(nullValue, null));
}

public abstract Query existsQuery(QueryShardContext context);

/**
Expand All @@ -382,12 +375,6 @@ public Relation isFieldWithinQuery(
return Relation.INTERSECTS;
}

/** A term query to use when parsing a query string. Can return {@code null}. */
@Nullable
public Query queryStringTermQuery(Term term) {
return null;
}

/** @throws IllegalArgumentException if the fielddata is not supported on this type.
* An IllegalArgumentException is needed in order to return an http error 400
* when this error occurs in a request. see: {@link org.elasticsearch.ExceptionsHelper#status}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.ngram.EdgeNGramTokenFilter;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.Term;
Expand Down Expand Up @@ -471,14 +470,6 @@ public Query existsQuery(QueryShardContext context) {
}
}

@Override
public Query nullValueQuery() {
if (nullValue() == null) {
return null;
}
return termQuery(nullValue(), null);
}

@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
if (fielddata == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
Occur highFreqOccur = highFreqOperator.toBooleanClauseOccur();
Occur lowFreqOccur = lowFreqOperator.toBooleanClauseOccur();

ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur,
cutoffFrequency, fieldType);
ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, cutoffFrequency);
return parseQueryString(commonsQuery, text, field, analyzerObj, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch);
}

Expand Down
22 changes: 12 additions & 10 deletions server/src/main/java/org/elasticsearch/index/search/MatchQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
package org.elasticsearch.index.search;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.miscellaneous.DisableGraphAttribute;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.miscellaneous.DisableGraphAttribute;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.Term;
import org.apache.lucene.queries.ExtendedCommonTermsQuery;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.DisjunctionMaxQuery;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.MultiPhraseQuery;
import org.apache.lucene.search.MultiTermQuery;
Expand Down Expand Up @@ -283,7 +282,7 @@ public Query parse(Type type, String fieldName, Object value) throws IOException
if (commonTermsCutoff == null) {
query = builder.createBooleanQuery(field, value.toString(), occur);
} else {
query = builder.createCommonTermsQuery(field, value.toString(), occur, occur, commonTermsCutoff, fieldType);
query = builder.createCommonTermsQuery(field, value.toString(), occur, occur, commonTermsCutoff);
}
break;
case PHRASE:
Expand Down Expand Up @@ -463,20 +462,23 @@ private Query toSpanQueryPrefix(SpanQuery query, float boost) {
}
}

public Query createCommonTermsQuery(String field, String queryText, Occur highFreqOccur, Occur lowFreqOccur, float
maxTermFrequency, MappedFieldType fieldType) {
public Query createCommonTermsQuery(String field, String queryText,
Occur highFreqOccur,
Occur lowFreqOccur,
float maxTermFrequency) {
Query booleanQuery = createBooleanQuery(field, queryText, lowFreqOccur);
if (booleanQuery != null && booleanQuery instanceof BooleanQuery) {
BooleanQuery bq = (BooleanQuery) booleanQuery;
return boolToExtendedCommonTermsQuery(bq, highFreqOccur, lowFreqOccur, maxTermFrequency, fieldType);
return boolToExtendedCommonTermsQuery(bq, highFreqOccur, lowFreqOccur, maxTermFrequency);
}
return booleanQuery;
}

private Query boolToExtendedCommonTermsQuery(BooleanQuery bq, Occur highFreqOccur, Occur lowFreqOccur, float
maxTermFrequency, MappedFieldType fieldType) {
ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency,
fieldType);
private Query boolToExtendedCommonTermsQuery(BooleanQuery bq,
Occur highFreqOccur,
Occur lowFreqOccur,
float maxTermFrequency) {
ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency);
for (BooleanClause clause : bq.clauses()) {
if (!(clause.getQuery() instanceof TermQuery)) {
return bq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,6 @@ private Map<String, Float> extractMultiFields(String field, boolean quoted) {
}
}

@Override
protected Query newTermQuery(Term term) {
if (currentFieldType != null) {
Query termQuery = currentFieldType.queryStringTermQuery(term);
if (termQuery != null) {
return termQuery;
}
}
return super.newTermQuery(term);
}

@Override
protected Query newMatchAllDocsQuery() {
return Queries.newMatchAllQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ public String typeName() {
return CONTENT_TYPE;
}

@Override
public Query nullValueQuery() {
if (nullValue() == null) {
return null;
}
return termQuery(nullValue(), null);
}

@Override
public Query existsQuery(QueryShardContext context) {
if (hasDocValues()) {
Expand All @@ -136,7 +128,7 @@ protected void parseCreateField(ParseContext context, List<IndexableField> field
} else {
value = context.parser().textOrNull();
}

if (value == null) {
return;
}
Expand Down

0 comments on commit cd0a375

Please sign in to comment.