Skip to content

Commit 4787cf7

Browse files
committed
More Like This: remove percent_terms_to_match
Users should use minimum_should_match instead. Closes elastic#11030
1 parent 8128f39 commit 4787cf7

File tree

5 files changed

+12
-20
lines changed

5 files changed

+12
-20
lines changed

docs/reference/migration/migrate_2_0.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Partial fields were deprecated since 1.0.0beta1 in favor of <<search-request-sou
2929
The More Like This API and the More Like This Field query have been removed in
3030
favor of the <<query-dsl-mlt-query, More Like This Query>>.
3131

32+
The parameter `percent_terms_to_match` has been removed in favor of
33+
`minimum_should_match`.
34+
3235
=== Routing
3336

3437
The default hash function that is used for routing has been changed from djb2 to

src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,6 @@ public MoreLikeThisQueryBuilder minimumShouldMatch(String minimumShouldMatch) {
258258
return this;
259259
}
260260

261-
/**
262-
* The percentage of terms to match. Defaults to <tt>0.3</tt>.
263-
*/
264-
@Deprecated
265-
public MoreLikeThisQueryBuilder percentTermsToMatch(float percentTermsToMatch) {
266-
return minimumShouldMatch(Math.round(percentTermsToMatch * 100) + "%");
267-
}
268-
269261
/**
270262
* The frequency below which terms will be ignored in the source doc. The default
271263
* frequency is <tt>2</tt>.

src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryParser.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public static class Fields {
6767
public static final ParseField MAX_DOC_FREQ = new ParseField("max_doc_freq");
6868
public static final ParseField BOOST_TERMS = new ParseField("boost_terms");
6969
public static final ParseField MINIMUM_SHOULD_MATCH = new ParseField("minimum_should_match");
70-
public static final ParseField PERCENT_TERMS_TO_MATCH = new ParseField("percent_terms_to_match").withAllDeprecated("minimum_should_match");
7170
public static final ParseField FAIL_ON_UNSUPPORTED_FIELD = new ParseField("fail_on_unsupported_field");
7271
public static final ParseField STOP_WORDS = new ParseField("stop_words");
7372
public static final ParseField DOCUMENT_IDS = new ParseField("ids").withAllDeprecated("like");
@@ -142,8 +141,6 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
142141
}
143142
} else if (Fields.MINIMUM_SHOULD_MATCH.match(currentFieldName, parseContext.parseFlags())) {
144143
mltQuery.setMinimumShouldMatch(parser.text());
145-
} else if (Fields.PERCENT_TERMS_TO_MATCH.match(currentFieldName, parseContext.parseFlags())) {
146-
mltQuery.setMinimumShouldMatch(Math.round(parser.floatValue() * 100) + "%");
147144
} else if ("analyzer".equals(currentFieldName)) {
148145
analyzer = parseContext.analysisService().analyzer(parser.text());
149146
} else if ("boost".equals(currentFieldName)) {

src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ public void testMoreLikeThisIds() throws Exception {
17511751
}
17521752

17531753
@Test
1754-
public void testMLTPercentTermsToMatch() throws Exception {
1754+
public void testMLTMinimumShouldMatch() throws Exception {
17551755
// setup for mocking fetching items
17561756
MoreLikeThisQueryParser parser = (MoreLikeThisQueryParser) queryParser.queryParser("more_like_this");
17571757
parser.setFetchService(new MockMoreLikeThisFetchService());

src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,16 @@ public void testSimpleMoreLikeInclude() throws Exception {
299299

300300
logger.info("Running More Like This with include true");
301301
SearchResponse response = client().prepareSearch().setQuery(
302-
new MoreLikeThisQueryBuilder().addItem(new Item("test", "type1", "1")).minTermFreq(1).minDocFreq(1).include(true).percentTermsToMatch(0)).get();
302+
new MoreLikeThisQueryBuilder().addItem(new Item("test", "type1", "1")).minTermFreq(1).minDocFreq(1).include(true).minimumShouldMatch("0%")).get();
303303
assertOrderedSearchHits(response, "1", "2");
304304

305305
response = client().prepareSearch().setQuery(
306-
new MoreLikeThisQueryBuilder().addItem(new Item("test", "type1", "2")).minTermFreq(1).minDocFreq(1).include(true).percentTermsToMatch(0)).get();
306+
new MoreLikeThisQueryBuilder().addItem(new Item("test", "type1", "2")).minTermFreq(1).minDocFreq(1).include(true).minimumShouldMatch("0%")).get();
307307
assertOrderedSearchHits(response, "2", "1");
308308

309309
logger.info("Running More Like This with include false");
310310
response = client().prepareSearch().setQuery(
311-
new MoreLikeThisQueryBuilder().addItem(new Item("test", "type1", "1")).minTermFreq(1).minDocFreq(1).percentTermsToMatch(0)).get();
311+
new MoreLikeThisQueryBuilder().addItem(new Item("test", "type1", "1")).minTermFreq(1).minDocFreq(1).minimumShouldMatch("0%")).get();
312312
assertSearchHits(response, "2");
313313
}
314314

@@ -394,7 +394,7 @@ public void testMoreLikeThisMultiValueFields() throws Exception {
394394
int max_query_terms = randomIntBetween(1, values.length);
395395
logger.info("Running More Like This with max_query_terms = %s", max_query_terms);
396396
MoreLikeThisQueryBuilder mltQuery = moreLikeThisQuery("text").ids("0").minTermFreq(1).minDocFreq(1)
397-
.maxQueryTerms(max_query_terms).percentTermsToMatch(0);
397+
.maxQueryTerms(max_query_terms).minimumShouldMatch("0%");
398398
SearchResponse response = client().prepareSearch("test").setTypes("type1")
399399
.setQuery(mltQuery).execute().actionGet();
400400
assertSearchResponse(response);
@@ -493,7 +493,7 @@ public void testMoreLikeThisMalformedArtificialDocs() throws Exception {
493493
.docs((Item) new Item().doc(malformedFieldDoc).index("test").type("type1"))
494494
.minTermFreq(0)
495495
.minDocFreq(0)
496-
.percentTermsToMatch(0);
496+
.minimumShouldMatch("0%");
497497
SearchResponse response = client().prepareSearch("test").setTypes("type1")
498498
.setQuery(mltQuery).get();
499499
assertSearchResponse(response);
@@ -505,7 +505,7 @@ public void testMoreLikeThisMalformedArtificialDocs() throws Exception {
505505
.docs((Item) new Item().doc(emptyDoc).index("test").type("type1"))
506506
.minTermFreq(0)
507507
.minDocFreq(0)
508-
.percentTermsToMatch(0);
508+
.minimumShouldMatch("0%");
509509
response = client().prepareSearch("test").setTypes("type1")
510510
.setQuery(mltQuery).get();
511511
assertSearchResponse(response);
@@ -517,7 +517,7 @@ public void testMoreLikeThisMalformedArtificialDocs() throws Exception {
517517
.docs((Item) new Item().doc(malformedDoc).index("test").type("type1"))
518518
.minTermFreq(0)
519519
.minDocFreq(0)
520-
.percentTermsToMatch(0);
520+
.minimumShouldMatch("0%");
521521
response = client().prepareSearch("test").setTypes("type1")
522522
.setQuery(mltQuery).get();
523523
assertSearchResponse(response);
@@ -533,7 +533,7 @@ public void testMoreLikeThisMalformedArtificialDocs() throws Exception {
533533
.docs((Item) new Item().doc(normalDoc).index("test").type("type1"))
534534
.minTermFreq(0)
535535
.minDocFreq(0)
536-
.percentTermsToMatch(1); // strict all terms must match but date is ignored
536+
.minimumShouldMatch("100%"); // strict all terms must match but date is ignored
537537
response = client().prepareSearch("test").setTypes("type1")
538538
.setQuery(mltQuery).get();
539539
assertSearchResponse(response);

0 commit comments

Comments
 (0)