Skip to content
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
13 changes: 12 additions & 1 deletion src/Nest/DSL/Query/MatchQueryDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public interface IMatchQuery : IFieldNameQuery
[JsonProperty(PropertyName = "fuzziness")]
double? Fuzziness { get; set; }

[JsonProperty(PropertyName = "fuzzy_transpositions")]
bool? FuzzyTranspositions { get; set; }

[JsonProperty(PropertyName = "cutoff_frequency")]
double? CutoffFrequency { get; set; }

Expand Down Expand Up @@ -82,6 +85,7 @@ void IFieldNameQuery.SetFieldName(string fieldName)
public string Analyzer { get; set; }
public RewriteMultiTerm? Rewrite { get; set; }
public double? Fuzziness { get; set; }
public bool? FuzzyTranspositions { get; set; }
public double? CutoffFrequency { get; set; }
public int? PrefixLength { get; set; }
public int? MaxExpansions { get; set; }
Expand Down Expand Up @@ -112,6 +116,7 @@ public class MatchQueryDescriptor<T> : IMatchQuery where T : class
RewriteMultiTerm? IMatchQuery.Rewrite { get; set; }

double? IMatchQuery.Fuzziness { get; set; }
bool? IMatchQuery.FuzzyTranspositions { get; set; }

double? IMatchQuery.CutoffFrequency { get; set; }

Expand Down Expand Up @@ -187,7 +192,13 @@ public MatchQueryDescriptor<T> Fuzziness(double fuzziness)
Self.Fuzziness = fuzziness;
return this;
}


public MatchQueryDescriptor<T> FuzzyTranspositions(bool fuzzyTranspositions = true)
{
Self.FuzzyTranspositions = fuzzyTranspositions;
return this;
}

public MatchQueryDescriptor<T> CutoffFrequency(double cutoffFrequency)
{
Self.CutoffFrequency = cutoffFrequency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
fq.Analyzer = GetPropValue<string>(jo, "analyzer");
fq.CutoffFrequency = GetPropValue<double?>(jo, "cutoff_frequency");
fq.Fuzziness = GetPropValue<double?>(jo, "fuzziness");
fq.FuzzyTranspositions = GetPropValue<bool?>(jo, "fuzzy_transpositions");
fq.Lenient = GetPropValue<bool?>(jo, "lenient");
fq.MaxExpansions = GetPropValue<int?>(jo, "max_expansions");
fq.PrefixLength = GetPropValue<int?>(jo, "prefix_length");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void Match_Deserializes()
q.Boost.Should().Be(2.1);
q.CutoffFrequency.Should().Be(1.31);
q.Fuzziness.Should().Be(2.3);
q.FuzzyTranspositions.Should().Be(null);
q.Lenient.Should().BeTrue();
q.MaxExpansions.Should().Be(2);
q.Field.Should().Be("name");
Expand All @@ -54,6 +55,7 @@ public void MatchPhrasePhrefix_Deserializes()
.Boost(2.1)
.CutoffFrequency(1.31)
.Fuzziness(2.3)
.FuzzyTranspositions(false)
.Lenient()
.MaxExpansions(2)
.Operator(Operator.And)
Expand All @@ -68,6 +70,7 @@ public void MatchPhrasePhrefix_Deserializes()
q.Boost.Should().Be(2.1);
q.CutoffFrequency.Should().Be(1.31);
q.Fuzziness.Should().Be(2.3);
q.FuzzyTranspositions.Should().Be(false);
q.Lenient.Should().BeTrue();
q.MaxExpansions.Should().Be(2);
q.Field.Should().Be("name");
Expand All @@ -89,6 +92,7 @@ public void MatchPhrase_Deserializes()
.Boost(2.1)
.CutoffFrequency(1.31)
.Fuzziness(2.3)
.FuzzyTranspositions()
.Lenient()
.MaxExpansions(2)
.Operator(Operator.And)
Expand All @@ -103,6 +107,7 @@ public void MatchPhrase_Deserializes()
q.Boost.Should().Be(2.1);
q.CutoffFrequency.Should().Be(1.31);
q.Fuzziness.Should().Be(2.3);
q.FuzzyTranspositions.Should().Be(true);
q.Lenient.Should().BeTrue();
q.MaxExpansions.Should().Be(2);
q.Field.Should().Be("name");
Expand Down
44 changes: 43 additions & 1 deletion src/Tests/Nest.Tests.Unit/Search/Query/Singles/MatchQueryJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void MatchQuery()
}
}
}";

Assert.True(json.JsonEquals(expected), json);
}

Expand Down Expand Up @@ -66,8 +67,10 @@ public void MatchPhraseQuery()
}
}
}";

Assert.True(json.JsonEquals(expected), json);
}

[Test]
public void MatchQuerySomeOptions()
{
Expand All @@ -78,7 +81,6 @@ public void MatchQuerySomeOptions()
.Match(t => t
.OnField(f => f.Name)
.Query("this is a test")

.Fuzziness(1.0)
.Analyzer("my_analyzer")
.CutoffFrequency(0.3)
Expand All @@ -102,6 +104,46 @@ public void MatchQuerySomeOptions()
}
}
}";

Assert.True(json.JsonEquals(expected), json);
}

[Test]
public void MatchQueryFuzzyTranspositions()
{
var s = new SearchDescriptor<ElasticsearchProject>()
.From(0)
.Size(10)
.Query(q => q
.Match(t => t
.OnField(f => f.Name)
.Query("this is a test")
.Fuzziness(1.0)
.FuzzyTranspositions()
.Analyzer("my_analyzer")
.CutoffFrequency(0.3)
.Rewrite(RewriteMultiTerm.ConstantScoreFilter)
.PrefixLength(2)
)
);

var json = TestElasticClient.Serialize(s);
var expected = @"{ from: 0, size: 10,
query : {
match: {
name : {
query : ""this is a test"",
analyzer : ""my_analyzer"",
rewrite: ""constant_score_filter"",
fuzziness: 1.0,
fuzzy_transpositions : true,
cutoff_frequency: 0.3,
prefix_length: 2
}
}
}
}";

Assert.True(json.JsonEquals(expected), json);
}
}
Expand Down