Skip to content

Commit 2c294a4

Browse files
committed
Deprecate CommonTerms query and CutoffFrequency of MatchQuery
relates: #4001
1 parent ee84e1a commit 2c294a4

File tree

10 files changed

+30
-5
lines changed

10 files changed

+30
-5
lines changed

src/Nest/QueryDsl/Abstractions/Container/IQueryContainer.cs

+2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public interface IQueryContainer
1414
IBoostingQuery Boosting { get; set; }
1515

1616
[DataMember(Name ="common")]
17+
#pragma warning disable 618
1718
ICommonTermsQuery CommonTerms { get; set; }
19+
#pragma warning restore 618
1820

1921
[DataMember(Name ="constant_score")]
2022
IConstantScoreQuery ConstantScore { get; set; }

src/Nest/QueryDsl/Abstractions/Container/QueryContainer-Assignments.cs

+5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ public partial class QueryContainer : IQueryContainer, IDescriptor
88
{
99
private IBoolQuery _bool;
1010
private IBoostingQuery _boosting;
11+
#pragma warning disable 618
1112
private ICommonTermsQuery _commonTerms;
13+
#pragma warning restore 618
1214
private IConstantScoreQuery _constantScore;
1315
private IDisMaxQuery _disMax;
1416
private IDistanceFeatureQuery _distanceFeature;
@@ -74,11 +76,14 @@ IBoostingQuery IQueryContainer.Boosting
7476
set => _boosting = Set(value);
7577
}
7678

79+
#pragma warning disable 618
7780
ICommonTermsQuery IQueryContainer.CommonTerms
81+
7882
{
7983
get => _commonTerms;
8084
set => _commonTerms = Set(value);
8185
}
86+
#pragma warning restore 618
8287

8388
IConstantScoreQuery IQueryContainer.ConstantScore
8489
{

src/Nest/QueryDsl/Abstractions/Container/QueryContainerDescriptor.cs

+2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ public QueryContainer GeoBoundingBox(Func<GeoBoundingBoxQueryDescriptor<T>, IGeo
187187
/// The common terms query is a modern alternative to stopwords which improves the precision and recall
188188
/// of search results (by taking stopwords into account), without sacrificing performance.
189189
/// </summary>
190+
#pragma warning disable 618
190191
public QueryContainer CommonTerms(Func<CommonTermsQueryDescriptor<T>, ICommonTermsQuery> selector) =>
191192
WrapInContainer(selector, (query, container) => container.CommonTerms = query);
193+
#pragma warning restore 618
192194

193195
/// <summary>
194196
/// The has_child query works the same as the has_child filter, by automatically wrapping the filter with a

src/Nest/QueryDsl/FullText/CommonTerms/CommonTermsQuery.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using System.Runtime.Serialization;
1+
using System;
2+
using System.Runtime.Serialization;
23
using Elasticsearch.Net.Utf8Json;
34

45
namespace Nest
56
{
7+
[Obsolete("Deprecated in 7.3.0. Use MatchQuery instead, which skips blocks of documents efficiently, without any configuration, provided that the total number of hits is not tracked.")]
68
[InterfaceDataContract]
79
[JsonFormatter(typeof(FieldNameQueryFormatter<CommonTermsQuery, ICommonTermsQuery>))]
810
public interface ICommonTermsQuery : IFieldNameQuery
@@ -28,6 +30,7 @@ public interface ICommonTermsQuery : IFieldNameQuery
2830
string Query { get; set; }
2931
}
3032

33+
[Obsolete("Deprecated in 7.3.0. Use MatchQuery instead, which skips blocks of documents efficiently, without any configuration, provided that the total number of hits is not tracked.")]
3134
public class CommonTermsQuery : FieldNameQueryBase, ICommonTermsQuery
3235
{
3336
public string Analyzer { get; set; }
@@ -43,6 +46,7 @@ public class CommonTermsQuery : FieldNameQueryBase, ICommonTermsQuery
4346
internal static bool IsConditionless(ICommonTermsQuery q) => q.Field.IsConditionless() || q.Query.IsNullOrEmpty();
4447
}
4548

49+
[Obsolete("Deprecated in 7.3.0. Use MatchQuery instead, which skips blocks of documents efficiently, without any configuration, provided that the total number of hits is not tracked.")]
4650
public class CommonTermsQueryDescriptor<T>
4751
: FieldNameQueryDescriptorBase<CommonTermsQueryDescriptor<T>, ICommonTermsQuery, T>
4852
, ICommonTermsQuery

src/Nest/QueryDsl/FullText/Match/MatchQuery.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.Serialization;
1+
using System;
2+
using System.Runtime.Serialization;
23
using Elasticsearch.Net.Utf8Json;
34

45
namespace Nest
@@ -27,6 +28,7 @@ public interface IMatchQuery : IFieldNameQuery
2728
/// or all of the low frequency terms in the case of an <see cref="Nest.Operator.And" /> match.
2829
/// </summary>
2930
[DataMember(Name = "cutoff_frequency")]
31+
[Obsolete("Deprecated in 7.3.0. This option can be omitted since MatchQuery can skips blocks of documents efficiently if the total number of hits is not tracked.")]
3032
double? CutoffFrequency { get; set; }
3133

3234
/// <summary>
@@ -112,6 +114,7 @@ public class MatchQuery : FieldNameQueryBase, IMatchQuery
112114
public bool? AutoGenerateSynonymsPhraseQuery { get; set; }
113115

114116
/// <inheritdoc />
117+
[Obsolete("Deprecated in 7.3.0. This option can be omitted since MatchQuery can skips blocks of documents efficiently if the total number of hits is not tracked.")]
115118
public double? CutoffFrequency { get; set; }
116119

117120
/// <inheritdoc />
@@ -161,6 +164,7 @@ public class MatchQueryDescriptor<T>
161164
protected virtual string MatchQueryType => null;
162165
string IMatchQuery.Analyzer { get; set; }
163166
bool? IMatchQuery.AutoGenerateSynonymsPhraseQuery { get; set; }
167+
[Obsolete("Deprecated in 7.3.0. This option can be omitted since MatchQuery can skips blocks of documents efficiently if the total number of hits is not tracked.")]
164168
double? IMatchQuery.CutoffFrequency { get; set; }
165169
IFuzziness IMatchQuery.Fuzziness { get; set; }
166170
MultiTermQueryRewrite IMatchQuery.FuzzyRewrite { get; set; }
@@ -190,6 +194,7 @@ public MatchQueryDescriptor<T> FuzzyTranspositions(bool? fuzzyTranspositions = t
190194
Assign(fuzzyTranspositions, (a, v) => a.FuzzyTranspositions = v);
191195

192196
/// <inheritdoc cref="IMatchQuery.CutoffFrequency" />
197+
[Obsolete("Deprecated in 7.3.0. This option can be omitted since MatchQuery can skips blocks of documents efficiently if the total number of hits is not tracked.")]
193198
public MatchQueryDescriptor<T> CutoffFrequency(double? cutoffFrequency) => Assign(cutoffFrequency, (a, v) => a.CutoffFrequency = v);
194199

195200
/// <inheritdoc cref="IMatchQuery.FuzzyRewrite" />

src/Nest/QueryDsl/Query.cs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public static QueryContainer Bool(Func<BoolQueryDescriptor<T>, IBoolQuery> selec
1111
public static QueryContainer Boosting(Func<BoostingQueryDescriptor<T>, IBoostingQuery> selector) =>
1212
new QueryContainerDescriptor<T>().Boosting(selector);
1313

14+
[Obsolete("Deprecated in 7.3.0. Use MatchQuery instead, which skips blocks of documents efficiently, without any configuration, provided that the total number of hits is not tracked.")]
1415
public static QueryContainer CommonTerms(Func<CommonTermsQueryDescriptor<T>, ICommonTermsQuery> selector) =>
1516
new QueryContainerDescriptor<T>().CommonTerms(selector);
1617

src/Nest/QueryDsl/Visitor/DslPrettyPrintVisitor.cs

+2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public virtual void Visit(IQuery query) { }
4949

5050
public virtual void Visit(IBoostingQuery query) => Write("boosting");
5151

52+
#pragma warning disable 618
5253
public virtual void Visit(ICommonTermsQuery query) => Write("common_terms", query.Field);
54+
#pragma warning restore 618
5355

5456
public virtual void Visit(IConstantScoreQuery query) => Write("constant_score");
5557

src/Nest/QueryDsl/Visitor/QueryVisitor.cs

+4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public interface IQueryVisitor
2828

2929
void Visit(IBoostingQuery query);
3030

31+
#pragma warning disable 618
3132
void Visit(ICommonTermsQuery query);
33+
#pragma warning restore 618
3234

3335
void Visit(IConstantScoreQuery query);
3436

@@ -155,7 +157,9 @@ public virtual void Visit(IBoolQuery query) { }
155157

156158
public virtual void Visit(IBoostingQuery query) { }
157159

160+
#pragma warning disable 618
158161
public virtual void Visit(ICommonTermsQuery query) { }
162+
#pragma warning restore 618
159163

160164
public virtual void Visit(IConstantScoreQuery query) { }
161165

src/Tests/Tests/QueryDsl/FullText/CommonTerms/CommonTermsUsageTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
using Tests.Framework.EndpointTests.TestState;
55
using static Nest.Infer;
66

7+
// CommonTerms is deprecated in 7.3.0
8+
#pragma warning disable 618,612
9+
710
namespace Tests.QueryDsl.FullText.CommonTerms
811
{
912
public class CommonTermsUsageTests : QueryDslUsageTestsBase

src/Tests/Tests/QueryDsl/FullText/Match/MatchUsageTests.cs

-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public MatchUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage)
2323
Analyzer = "standard",
2424
Boost = 1.1,
2525
Name = "named_query",
26-
CutoffFrequency = 0.001,
2726
Query = "hello world",
2827
Fuzziness = Fuzziness.AutoLength(3, 6),
2928
FuzzyTranspositions = true,
@@ -47,7 +46,6 @@ public MatchUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage)
4746
fuzzy_rewrite = "top_terms_blended_freqs_10",
4847
fuzziness = "AUTO:3,6",
4948
fuzzy_transpositions = true,
50-
cutoff_frequency = 0.001,
5149
lenient = true,
5250
minimum_should_match = 2,
5351
@operator = "or",
@@ -61,7 +59,6 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
6159
.Field(p => p.Description)
6260
.Analyzer("standard")
6361
.Boost(1.1)
64-
.CutoffFrequency(0.001)
6562
.Query("hello world")
6663
.Fuzziness(Fuzziness.AutoLength(3, 6))
6764
.Lenient()

0 commit comments

Comments
 (0)