Skip to content

Commit

Permalink
Deprecate CommonTerms query and CutoffFrequency of MatchQuery (#4056)
Browse files Browse the repository at this point in the history
relates: #4001
(cherry picked from commit 538d741)
  • Loading branch information
russcam committed Aug 30, 2019
1 parent 2fbd3d8 commit a5ff75f
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Nest/QueryDsl/Abstractions/Container/IQueryContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public interface IQueryContainer
IBoostingQuery Boosting { get; set; }

[DataMember(Name ="common")]
#pragma warning disable 618
ICommonTermsQuery CommonTerms { get; set; }
#pragma warning restore 618

[DataMember(Name ="constant_score")]
IConstantScoreQuery ConstantScore { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public partial class QueryContainer : IQueryContainer, IDescriptor
{
private IBoolQuery _bool;
private IBoostingQuery _boosting;
#pragma warning disable 618
private ICommonTermsQuery _commonTerms;
#pragma warning restore 618
private IConstantScoreQuery _constantScore;
private IDisMaxQuery _disMax;
private IExistsQuery _exists;
Expand Down Expand Up @@ -73,11 +75,14 @@ IBoostingQuery IQueryContainer.Boosting
set => _boosting = Set(value);
}

#pragma warning disable 618
ICommonTermsQuery IQueryContainer.CommonTerms

{
get => _commonTerms;
set => _commonTerms = Set(value);
}
#pragma warning restore 618

IConstantScoreQuery IQueryContainer.ConstantScore
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ public QueryContainer GeoBoundingBox(Func<GeoBoundingBoxQueryDescriptor<T>, IGeo
/// The common terms query is a modern alternative to stopwords which improves the precision and recall
/// of search results (by taking stopwords into account), without sacrificing performance.
/// </summary>
#pragma warning disable 618
public QueryContainer CommonTerms(Func<CommonTermsQueryDescriptor<T>, ICommonTermsQuery> selector) =>
WrapInContainer(selector, (query, container) => container.CommonTerms = query);
#pragma warning restore 618

/// <summary>
/// The has_child query works the same as the has_child filter, by automatically wrapping the filter with a
Expand Down
6 changes: 5 additions & 1 deletion src/Nest/QueryDsl/FullText/CommonTerms/CommonTermsQuery.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Runtime.Serialization;
using System;
using System.Runtime.Serialization;
using Elasticsearch.Net.Utf8Json;

namespace Nest
{
[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.")]
[InterfaceDataContract]
[JsonFormatter(typeof(FieldNameQueryFormatter<CommonTermsQuery, ICommonTermsQuery>))]
public interface ICommonTermsQuery : IFieldNameQuery
Expand All @@ -28,6 +30,7 @@ public interface ICommonTermsQuery : IFieldNameQuery
string Query { get; set; }
}

[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.")]
public class CommonTermsQuery : FieldNameQueryBase, ICommonTermsQuery
{
public string Analyzer { get; set; }
Expand All @@ -43,6 +46,7 @@ public class CommonTermsQuery : FieldNameQueryBase, ICommonTermsQuery
internal static bool IsConditionless(ICommonTermsQuery q) => q.Field.IsConditionless() || q.Query.IsNullOrEmpty();
}

[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.")]
public class CommonTermsQueryDescriptor<T>
: FieldNameQueryDescriptorBase<CommonTermsQueryDescriptor<T>, ICommonTermsQuery, T>
, ICommonTermsQuery
Expand Down
7 changes: 6 additions & 1 deletion src/Nest/QueryDsl/FullText/Match/MatchQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.Serialization;
using System;
using System.Runtime.Serialization;
using Elasticsearch.Net.Utf8Json;

namespace Nest
Expand Down Expand Up @@ -27,6 +28,7 @@ public interface IMatchQuery : IFieldNameQuery
/// or all of the low frequency terms in the case of an <see cref="Nest.Operator.And" /> match.
/// </summary>
[DataMember(Name = "cutoff_frequency")]
[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.")]
double? CutoffFrequency { get; set; }

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

/// <inheritdoc />
[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.")]
public double? CutoffFrequency { get; set; }

/// <inheritdoc />
Expand Down Expand Up @@ -161,6 +164,7 @@ public class MatchQueryDescriptor<T>
protected virtual string MatchQueryType => null;
string IMatchQuery.Analyzer { get; set; }
bool? IMatchQuery.AutoGenerateSynonymsPhraseQuery { get; set; }
[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.")]
double? IMatchQuery.CutoffFrequency { get; set; }
IFuzziness IMatchQuery.Fuzziness { get; set; }
MultiTermQueryRewrite IMatchQuery.FuzzyRewrite { get; set; }
Expand Down Expand Up @@ -190,6 +194,7 @@ public MatchQueryDescriptor<T> FuzzyTranspositions(bool? fuzzyTranspositions = t
Assign(fuzzyTranspositions, (a, v) => a.FuzzyTranspositions = v);

/// <inheritdoc cref="IMatchQuery.CutoffFrequency" />
[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.")]
public MatchQueryDescriptor<T> CutoffFrequency(double? cutoffFrequency) => Assign(cutoffFrequency, (a, v) => a.CutoffFrequency = v);

/// <inheritdoc cref="IMatchQuery.FuzzyRewrite" />
Expand Down
1 change: 1 addition & 0 deletions src/Nest/QueryDsl/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static QueryContainer Bool(Func<BoolQueryDescriptor<T>, IBoolQuery> selec
public static QueryContainer Boosting(Func<BoostingQueryDescriptor<T>, IBoostingQuery> selector) =>
new QueryContainerDescriptor<T>().Boosting(selector);

[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.")]
public static QueryContainer CommonTerms(Func<CommonTermsQueryDescriptor<T>, ICommonTermsQuery> selector) =>
new QueryContainerDescriptor<T>().CommonTerms(selector);

Expand Down
2 changes: 2 additions & 0 deletions src/Nest/QueryDsl/Visitor/DslPrettyPrintVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public virtual void Visit(IQuery query) { }

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

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

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

Expand Down
4 changes: 4 additions & 0 deletions src/Nest/QueryDsl/Visitor/QueryVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public interface IQueryVisitor

void Visit(IBoostingQuery query);

#pragma warning disable 618
void Visit(ICommonTermsQuery query);
#pragma warning restore 618

void Visit(IConstantScoreQuery query);

Expand Down Expand Up @@ -153,7 +155,9 @@ public virtual void Visit(IBoolQuery query) { }

public virtual void Visit(IBoostingQuery query) { }

#pragma warning disable 618
public virtual void Visit(ICommonTermsQuery query) { }
#pragma warning restore 618

public virtual void Visit(IConstantScoreQuery query) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using Tests.Framework.EndpointTests.TestState;
using static Nest.Infer;

// CommonTerms is deprecated in 7.3.0
#pragma warning disable 618,612

namespace Tests.QueryDsl.FullText.CommonTerms
{
/*
Expand Down
3 changes: 0 additions & 3 deletions src/Tests/Tests/QueryDsl/FullText/Match/MatchUsageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public MatchUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage)
Analyzer = "standard",
Boost = 1.1,
Name = "named_query",
CutoffFrequency = 0.001,
Query = "hello world",
Fuzziness = Fuzziness.AutoLength(3, 6),
FuzzyTranspositions = true,
Expand All @@ -70,7 +69,6 @@ public MatchUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage)
fuzzy_rewrite = "top_terms_blended_freqs_10",
fuzziness = "AUTO:3,6",
fuzzy_transpositions = true,
cutoff_frequency = 0.001,
lenient = true,
minimum_should_match = 2,
@operator = "or",
Expand All @@ -84,7 +82,6 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
.Field(p => p.Description)
.Analyzer("standard")
.Boost(1.1)
.CutoffFrequency(0.001)
.Query("hello world")
.Fuzziness(Fuzziness.AutoLength(3, 6))
.Lenient()
Expand Down

0 comments on commit a5ff75f

Please sign in to comment.