Skip to content

Changes to queries for 5.0 #2046

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

Merged
merged 1 commit into from
Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/Nest/CommonOptions/Fuzziness/Fuzziness.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
namespace Nest
using System;

namespace Nest
{
public class Fuzziness : IFuzziness
{
private bool _auto;
private int? _editDistance;
private double? _ratio;
bool IFuzziness.Auto { get { return this._auto; } }
int? IFuzziness.EditDistance { get { return this._editDistance; } }
double? IFuzziness.Ratio { get { return this._ratio; } }
bool IFuzziness.Auto => this._auto;

int? IFuzziness.EditDistance => this._editDistance;

[Obsolete("Deprecated. Setting this is a noop")]
double? IFuzziness.Ratio => this._ratio;

public static Fuzziness Auto { get { return new Fuzziness() { _auto = true }; } }
public static Fuzziness Auto => new Fuzziness { _auto = true };

public static Fuzziness EditDistance(int distance)
{
return new Fuzziness() { _editDistance = distance };
}
public static Fuzziness EditDistance(int distance) => new Fuzziness { _editDistance = distance };

public static Fuzziness Ratio(double ratio)
{
return new Fuzziness() { _ratio = ratio };
}
[Obsolete("Deprecated. Setting this is a noop")]
public static Fuzziness Ratio(double ratio) => new Fuzziness { _ratio = ratio };
}
}
}
14 changes: 4 additions & 10 deletions src/Nest/CommonOptions/Fuzziness/FuzzinessJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ internal class FuzzinessJsonConverter : JsonConverter
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var v = value as IFuzziness;
if (v.Auto) writer.WriteValue("AUTO");
else if (v.EditDistance.HasValue) writer.WriteValue(v.EditDistance.Value);
else if (v.Ratio.HasValue) writer.WriteValue(v.Ratio.Value);
else writer.WriteNull();
if (v.Auto) writer.WriteValue("AUTO");
else if (v.EditDistance.HasValue) writer.WriteValue(v.EditDistance.Value);
else writer.WriteNull();
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
Expand All @@ -27,13 +26,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
var editDistance = Convert.ToInt32(reader.Value);
return Fuzziness.EditDistance(editDistance);
}
if (reader.TokenType == JsonToken.Float)
{
var ratio = (reader.Value as double?).GetValueOrDefault(0);
return Fuzziness.Ratio(ratio);
}
return null;
}

}
}
}
7 changes: 5 additions & 2 deletions src/Nest/CommonOptions/Fuzziness/IFuzziness.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System;
using Newtonsoft.Json;

namespace Nest
{
Expand All @@ -7,6 +8,8 @@ public interface IFuzziness
{
bool Auto { get; }
int? EditDistance { get; }

[Obsolete("Deprecated. Setting this is a noop")]
double? Ratio { get; }
}
}
}
8 changes: 8 additions & 0 deletions src/Nest/QueryDsl/TermLevel/Terms/TermsQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace Nest
[JsonConverter(typeof(TermsQueryJsonConverter))]
public interface ITermsQuery : IFieldNameQuery
{
[Obsolete("Will be removed in 5.0. Use bool query instead")]
MinimumShouldMatch MinimumShouldMatch { get; set; }
[Obsolete("Will be removed in 5.0. Use bool query instead")]
bool? DisableCoord { get; set; }
IEnumerable<object> Terms { get; set; }
IFieldLookup TermsLookup { get; set; }
Expand All @@ -19,7 +21,9 @@ public interface ITermsQuery : IFieldNameQuery
public class TermsQuery : FieldNameQueryBase, ITermsQuery
{
protected override bool Conditionless => IsConditionless(this);
[Obsolete("Will be removed in 5.0. Use bool query instead")]
public MinimumShouldMatch MinimumShouldMatch { get; set; }
[Obsolete("Will be removed in 5.0. Use bool query instead")]
public bool? DisableCoord { get; set; }
public IEnumerable<object> Terms { get; set; }
public IFieldLookup TermsLookup { get; set; }
Expand Down Expand Up @@ -54,16 +58,20 @@ public class TermsQueryDescriptor<T>
, ITermsQuery where T : class
{
protected override bool Conditionless => TermsQuery.IsConditionless(this);
[Obsolete("Will be removed in 5.0. Use bool query instead")]
MinimumShouldMatch ITermsQuery.MinimumShouldMatch { get; set; }
[Obsolete("Will be removed in 5.0. Use bool query instead")]
bool? ITermsQuery.DisableCoord { get; set; }
IEnumerable<object> ITermsQuery.Terms { get; set; }
IFieldLookup ITermsQuery.TermsLookup { get; set; }

public TermsQueryDescriptor<T> TermsLookup<TOther>(Func<FieldLookupDescriptor<TOther>, IFieldLookup> selector)
where TOther : class => Assign(a => a.TermsLookup = selector(new FieldLookupDescriptor<TOther>()));

[Obsolete("Will be removed in 5.0. Use bool query instead")]
public TermsQueryDescriptor<T> MinimumShouldMatch(MinimumShouldMatch minMatch) => Assign(a => a.MinimumShouldMatch = minMatch);

[Obsolete("Will be removed in 5.0. Use bool query instead")]
public TermsQueryDescriptor<T> DisableCoord(bool? disable = true) => Assign(a => a.DisableCoord = disable);

public TermsQueryDescriptor<T> Terms<TValue>(IEnumerable<TValue> terms) => Assign(a => a.Terms = terms?.Cast<object>());
Expand Down
4 changes: 4 additions & 0 deletions src/Nest/QueryDsl/TermLevel/Terms/TermsQueryJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
writer.WritePropertyName(field);
serializer.Serialize(writer, t.TermsLookup);
}
#pragma warning disable 618
if (t.DisableCoord.HasValue)
{
writer.WritePropertyName("disable_coord");
Expand All @@ -42,6 +43,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
writer.WritePropertyName("minimum_should_match");
serializer.Serialize(writer, t.MinimumShouldMatch);
}
#pragma warning restore 618
if (t.Boost.HasValue)
{
writer.WritePropertyName("boost");
Expand All @@ -68,6 +70,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
var property = reader.Value as string;
switch (property)
{
#pragma warning disable 618
case "disable_coord":
reader.Read();
f.DisableCoord = reader.Value as bool?;
Expand All @@ -77,6 +80,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
var min = serializer.Deserialize<MinimumShouldMatch>(reader);
f.MinimumShouldMatch = min;
break;
#pragma warning restore 618
case "boost":
reader.Read();
f.Boost = reader.Value as double?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Tests.Framework.Integration;
using Tests.Framework.MockData;

#pragma warning disable 618 // DisableCoord and MinimumShouldMatch

namespace Tests.QueryDsl.TermLevel.Terms
{
public class TermsListQueryUsageTests : QueryDslUsageTestsBase
Expand Down Expand Up @@ -80,7 +82,6 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
.DisableCoord()
.Terms(_terms)
);

}

public class TermsListOfListStringAgainstNumericFieldIntegrationTests : QueryDslIntegrationTestsBase
Expand Down Expand Up @@ -132,7 +133,5 @@ [I] public Task AsserResponse() => AssertOnAllResponses(r =>
var rootCause = rootCauses.First();
rootCause.Type.Should().Be("number_format_exception");
});

}

}
8 changes: 4 additions & 4 deletions src/Tests/QueryDsl/TermLevel/Terms/TermsQueryUsageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

namespace Tests.QueryDsl.TermLevel.Terms
{
/**
#pragma warning disable 618 // DisableCoord and MinimumShouldMatch

/**
* Filters documents that have fields that match any of the provided terms (not analyzed).
*
* Be sure to read the Elasticsearch documentation on {ref_current}/query-dsl-terms-query.html[Terms query] for more information.
Expand Down Expand Up @@ -59,7 +61,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
}

/**[float]
*== Single term Terms Query
*== Single term Terms Query
*/
public class SingleTermTermsQueryUsageTests : TermsQueryUsageTests
{
Expand All @@ -77,6 +79,4 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
.Terms("term1")
);
}


}