Skip to content

Commit 6a74667

Browse files
committed
MLT query: add support for minimum_should_match
Closes #1354
1 parent de12213 commit 6a74667

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Nest/DSL/Query/MoreLikeThisQueryDescriptor.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public interface IMoreLikeThisQuery : IQuery
2121
[JsonProperty(PropertyName = "percent_terms_to_match")]
2222
double? TermMatchPercentage { get; set; }
2323

24+
[JsonProperty(PropertyName = "minimum_should_match")]
25+
string MinimumShouldMatch { get; set; }
26+
2427
[JsonProperty(PropertyName = "stop_words")]
2528
IEnumerable<string> StopWords { get; set; }
2629

@@ -84,6 +87,7 @@ protected override void WrapInContainer(IQueryContainer container)
8487
public IEnumerable<PropertyPathMarker> Fields { get; set; }
8588
public string LikeText { get; set; }
8689
public double? TermMatchPercentage { get; set; }
90+
public string MinimumShouldMatch { get; set; }
8791
public IEnumerable<string> StopWords { get; set; }
8892
public int? MinTermFrequency { get; set; }
8993
public int? MaxQueryTerms { get; set; }
@@ -108,7 +112,9 @@ public class MoreLikeThisQueryDescriptor<T> : IMoreLikeThisQuery where T : class
108112
string IMoreLikeThisQuery.LikeText { get; set; }
109113

110114
double? IMoreLikeThisQuery.TermMatchPercentage { get; set; }
111-
115+
116+
string IMoreLikeThisQuery.MinimumShouldMatch { get; set; }
117+
112118
IEnumerable<string> IMoreLikeThisQuery.StopWords { get; set; }
113119

114120
int? IMoreLikeThisQuery.MinTermFrequency { get; set; }
@@ -212,6 +218,19 @@ public MoreLikeThisQueryDescriptor<T> TermMatchPercentage(double termMatchPercen
212218
this.Self.TermMatchPercentage = termMatchPercentage;
213219
return this;
214220
}
221+
222+
public MoreLikeThisQueryDescriptor<T> MinimumShouldMatch(string minMatch)
223+
{
224+
this.Self.MinimumShouldMatch = minMatch;
225+
return this;
226+
}
227+
228+
public MoreLikeThisQueryDescriptor<T> MinimumShouldMatch(int minMatch)
229+
{
230+
this.Self.MinimumShouldMatch = minMatch.ToString();
231+
return this;
232+
}
233+
215234
public MoreLikeThisQueryDescriptor<T> Boost(double boost)
216235
{
217236
this.Self.Boost = boost;

src/Tests/Nest.Tests.Unit/Search/Query/Singles/MoreLikeThisQueryJson.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public void TestMoreLikeThisAllQuery()
161161
.StopWords(new[] { "thou", "shall" })
162162
.BoostTerms(1.4)
163163
.TermMatchPercentage(12)
164+
.MinimumShouldMatch("30%")
164165
.Boost(1.1)
165166
.Analyzer("my_analyzer")
166167
)
@@ -171,6 +172,7 @@ public void TestMoreLikeThisAllQuery()
171172
fields : [""name"" ],
172173
like_text : ""elasticsearcc"",
173174
percent_terms_to_match: 12.0,
175+
minimum_should_match: ""30%"",
174176
stop_words: [
175177
""thou"",
176178
""shall""

0 commit comments

Comments
 (0)