Skip to content

Commit

Permalink
More Like This: remove percent_terms_to_match
Browse files Browse the repository at this point in the history
Users should use minimum_should_match instead.

Closes #11030
  • Loading branch information
alexksikes committed May 7, 2015
1 parent 8128f39 commit 4787cf7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
3 changes: 3 additions & 0 deletions docs/reference/migration/migrate_2_0.asciidoc
Expand Up @@ -29,6 +29,9 @@ Partial fields were deprecated since 1.0.0beta1 in favor of <<search-request-sou
The More Like This API and the More Like This Field query have been removed in
favor of the <<query-dsl-mlt-query, More Like This Query>>.

The parameter `percent_terms_to_match` has been removed in favor of
`minimum_should_match`.

=== Routing

The default hash function that is used for routing has been changed from djb2 to
Expand Down
Expand Up @@ -258,14 +258,6 @@ public MoreLikeThisQueryBuilder minimumShouldMatch(String minimumShouldMatch) {
return this;
}

/**
* The percentage of terms to match. Defaults to <tt>0.3</tt>.
*/
@Deprecated
public MoreLikeThisQueryBuilder percentTermsToMatch(float percentTermsToMatch) {
return minimumShouldMatch(Math.round(percentTermsToMatch * 100) + "%");
}

/**
* The frequency below which terms will be ignored in the source doc. The default
* frequency is <tt>2</tt>.
Expand Down
Expand Up @@ -67,7 +67,6 @@ public static class Fields {
public static final ParseField MAX_DOC_FREQ = new ParseField("max_doc_freq");
public static final ParseField BOOST_TERMS = new ParseField("boost_terms");
public static final ParseField MINIMUM_SHOULD_MATCH = new ParseField("minimum_should_match");
public static final ParseField PERCENT_TERMS_TO_MATCH = new ParseField("percent_terms_to_match").withAllDeprecated("minimum_should_match");
public static final ParseField FAIL_ON_UNSUPPORTED_FIELD = new ParseField("fail_on_unsupported_field");
public static final ParseField STOP_WORDS = new ParseField("stop_words");
public static final ParseField DOCUMENT_IDS = new ParseField("ids").withAllDeprecated("like");
Expand Down Expand Up @@ -142,8 +141,6 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
}
} else if (Fields.MINIMUM_SHOULD_MATCH.match(currentFieldName, parseContext.parseFlags())) {
mltQuery.setMinimumShouldMatch(parser.text());
} else if (Fields.PERCENT_TERMS_TO_MATCH.match(currentFieldName, parseContext.parseFlags())) {
mltQuery.setMinimumShouldMatch(Math.round(parser.floatValue() * 100) + "%");
} else if ("analyzer".equals(currentFieldName)) {
analyzer = parseContext.analysisService().analyzer(parser.text());
} else if ("boost".equals(currentFieldName)) {
Expand Down
Expand Up @@ -1751,7 +1751,7 @@ public void testMoreLikeThisIds() throws Exception {
}

@Test
public void testMLTPercentTermsToMatch() throws Exception {
public void testMLTMinimumShouldMatch() throws Exception {
// setup for mocking fetching items
MoreLikeThisQueryParser parser = (MoreLikeThisQueryParser) queryParser.queryParser("more_like_this");
parser.setFetchService(new MockMoreLikeThisFetchService());
Expand Down
Expand Up @@ -299,16 +299,16 @@ public void testSimpleMoreLikeInclude() throws Exception {

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

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

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

Expand Down Expand Up @@ -394,7 +394,7 @@ public void testMoreLikeThisMultiValueFields() throws Exception {
int max_query_terms = randomIntBetween(1, values.length);
logger.info("Running More Like This with max_query_terms = %s", max_query_terms);
MoreLikeThisQueryBuilder mltQuery = moreLikeThisQuery("text").ids("0").minTermFreq(1).minDocFreq(1)
.maxQueryTerms(max_query_terms).percentTermsToMatch(0);
.maxQueryTerms(max_query_terms).minimumShouldMatch("0%");
SearchResponse response = client().prepareSearch("test").setTypes("type1")
.setQuery(mltQuery).execute().actionGet();
assertSearchResponse(response);
Expand Down Expand Up @@ -493,7 +493,7 @@ public void testMoreLikeThisMalformedArtificialDocs() throws Exception {
.docs((Item) new Item().doc(malformedFieldDoc).index("test").type("type1"))
.minTermFreq(0)
.minDocFreq(0)
.percentTermsToMatch(0);
.minimumShouldMatch("0%");
SearchResponse response = client().prepareSearch("test").setTypes("type1")
.setQuery(mltQuery).get();
assertSearchResponse(response);
Expand All @@ -505,7 +505,7 @@ public void testMoreLikeThisMalformedArtificialDocs() throws Exception {
.docs((Item) new Item().doc(emptyDoc).index("test").type("type1"))
.minTermFreq(0)
.minDocFreq(0)
.percentTermsToMatch(0);
.minimumShouldMatch("0%");
response = client().prepareSearch("test").setTypes("type1")
.setQuery(mltQuery).get();
assertSearchResponse(response);
Expand All @@ -517,7 +517,7 @@ public void testMoreLikeThisMalformedArtificialDocs() throws Exception {
.docs((Item) new Item().doc(malformedDoc).index("test").type("type1"))
.minTermFreq(0)
.minDocFreq(0)
.percentTermsToMatch(0);
.minimumShouldMatch("0%");
response = client().prepareSearch("test").setTypes("type1")
.setQuery(mltQuery).get();
assertSearchResponse(response);
Expand All @@ -533,7 +533,7 @@ public void testMoreLikeThisMalformedArtificialDocs() throws Exception {
.docs((Item) new Item().doc(normalDoc).index("test").type("type1"))
.minTermFreq(0)
.minDocFreq(0)
.percentTermsToMatch(1); // strict all terms must match but date is ignored
.minimumShouldMatch("100%"); // strict all terms must match but date is ignored
response = client().prepareSearch("test").setTypes("type1")
.setQuery(mltQuery).get();
assertSearchResponse(response);
Expand Down

0 comments on commit 4787cf7

Please sign in to comment.