-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Deprecate CommonTermsQuery and cutoff_frequency #42619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
d6a2e01
5445142
8abbce8
5d63b69
fc0335f
d28cc43
962f2bc
d6b087f
4bbd7b8
9df9deb
4eb1045
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| package org.elasticsearch.index.query; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.lucene.analysis.Analyzer; | ||
| import org.apache.lucene.analysis.TokenStream; | ||
| import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; | ||
|
|
@@ -32,6 +33,7 @@ | |
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.logging.DeprecationLogger; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.index.mapper.MappedFieldType; | ||
|
|
@@ -47,9 +49,19 @@ | |
| * and high-frequency terms are added to an optional boolean clause. The | ||
| * optional clause is only executed if the required "low-frequency' clause | ||
| * matches. | ||
| * | ||
| * @deprecated Since max_optimization optimization landed in 7.0, normal MatchQuery | ||
| * will achieve the same result without any configuration. | ||
| */ | ||
| @Deprecated | ||
| public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQueryBuilder> { | ||
|
|
||
| private static final DeprecationLogger deprecationLogger = | ||
| new DeprecationLogger(LogManager.getLogger(CommonTermsQueryBuilder.class)); | ||
|
|
||
| public static final String COMMON_TERMS_QUERY_DEPRECATION_MSG = "[Common Terms Query] has been deprecated in favor of the " + | ||
| "MatchQuery [max_score] optimization which is applied automatically without any configuration"; | ||
|
|
||
| public static final String NAME = "common"; | ||
|
|
||
| public static final float DEFAULT_CUTOFF_FREQ = 0.01f; | ||
|
|
@@ -87,6 +99,7 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue | |
| * Constructs a new common terms query. | ||
| */ | ||
| public CommonTermsQueryBuilder(String fieldName, Object text) { | ||
| deprecationLogger.deprecated(COMMON_TERMS_QUERY_DEPRECATION_MSG); | ||
| if (Strings.isEmpty(fieldName)) { | ||
| throw new IllegalArgumentException("field name is null or empty"); | ||
| } | ||
|
|
@@ -102,6 +115,7 @@ public CommonTermsQueryBuilder(String fieldName, Object text) { | |
| */ | ||
| public CommonTermsQueryBuilder(StreamInput in) throws IOException { | ||
| super(in); | ||
| deprecationLogger.deprecated(COMMON_TERMS_QUERY_DEPRECATION_MSG); | ||
|
||
| fieldName = in.readString(); | ||
| text = in.readGenericValue(); | ||
| highFreqOperator = Operator.readFromStream(in); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,12 +19,14 @@ | |
|
|
||
| package org.elasticsearch.index.query; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.lucene.search.FuzzyQuery; | ||
| import org.apache.lucene.search.Query; | ||
| import org.elasticsearch.common.ParseField; | ||
| import org.elasticsearch.common.ParsingException; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.logging.DeprecationLogger; | ||
| import org.elasticsearch.common.lucene.search.Queries; | ||
| import org.elasticsearch.common.unit.Fuzziness; | ||
| import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; | ||
|
|
@@ -42,8 +44,20 @@ | |
| * result of the analysis. | ||
| */ | ||
| public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> { | ||
|
|
||
| private static final DeprecationLogger deprecationLogger = | ||
| new DeprecationLogger(LogManager.getLogger(MatchQueryBuilder.class)); | ||
|
|
||
| static final String CUTOFF_FREQUENCY_DEPRECATION_MSG = "[cutoff_frequency] has been deprecated in favor of the " + | ||
| "[max_score] optimization which is applied automatically without any configuration"; | ||
|
|
||
| public static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField("zero_terms_query"); | ||
| public static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField("cutoff_frequency"); | ||
| /** | ||
| * @deprecated Since max_optimization optimization landed in 7.0, normal MatchQuery | ||
| * will achieve the same result without any configuration. | ||
| */ | ||
| @Deprecated | ||
| public static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField("cutoff_frequency", "cutoff_frequency"); | ||
|
||
| public static final ParseField LENIENT_FIELD = new ParseField("lenient"); | ||
| public static final ParseField FUZZY_TRANSPOSITIONS_FIELD = new ParseField("fuzzy_transpositions"); | ||
| public static final ParseField FUZZY_REWRITE_FIELD = new ParseField("fuzzy_rewrite"); | ||
|
|
@@ -85,6 +99,10 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> { | |
|
|
||
| private MatchQuery.ZeroTermsQuery zeroTermsQuery = MatchQuery.DEFAULT_ZERO_TERMS_QUERY; | ||
|
|
||
| /** | ||
| * @deprecated See {@link MatchQueryBuilder#CUTOFF_FREQUENCY_FIELD} for more details | ||
| */ | ||
| @Deprecated | ||
| private Float cutoffFrequency = null; | ||
|
|
||
| private boolean autoGenerateSynonymsPhraseQuery = true; | ||
|
|
@@ -235,8 +253,12 @@ public int maxExpansions() { | |
| * Set a cutoff value in [0..1] (or absolute number >=1) representing the | ||
| * maximum threshold of a terms document frequency to be considered a low | ||
| * frequency term. | ||
| * | ||
| * @deprecated see {@link MatchQueryBuilder#CUTOFF_FREQUENCY_FIELD} for more details | ||
| */ | ||
| @Deprecated | ||
| public MatchQueryBuilder cutoffFrequency(float cutoff) { | ||
| deprecationLogger.deprecated(CUTOFF_FREQUENCY_DEPRECATION_MSG); | ||
|
||
| this.cutoffFrequency = cutoff; | ||
| return this; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole class is deprecated so you don't need to log the deprecation here. Maybe add a Deprecated annotation to all constructors and you can set the deprecation for the rest handler in the SearchModule. Replacing
elasticsearch/server/src/main/java/org/elasticsearch/search/SearchModule.java
Line 770 in 6bba9fc
should work.