MLT Query/API: fix `minimum_should_match` bwc
Rounded to the nearest int allows to avoid issues in which (int) (0.59f * 100) = 58, instead of 59%.
This commit is contained in:
parent
fca406415d
commit
e53b2eede7
|
@ -237,7 +237,7 @@ public class MoreLikeThisRequest extends ActionRequest<MoreLikeThisRequest> impl
|
|||
*/
|
||||
@Deprecated
|
||||
public MoreLikeThisRequest percentTermsToMatch(float percentTermsToMatch) {
|
||||
return minimumShouldMatch((int) (percentTermsToMatch * 100) + "%");
|
||||
return minimumShouldMatch(Math.round(percentTermsToMatch * 100) + "%");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -75,7 +75,7 @@ public class MoreLikeThisRequestBuilder extends ActionRequestBuilder<MoreLikeThi
|
|||
* The percent of the terms to match for each field. Defaults to <tt>0.3f</tt>.
|
||||
*/
|
||||
public MoreLikeThisRequestBuilder setPercentTermsToMatch(float percentTermsToMatch) {
|
||||
return setMinimumShouldMatch((int) (percentTermsToMatch * 100) + "%");
|
||||
return setMinimumShouldMatch(Math.round(percentTermsToMatch * 100) + "%");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,7 +79,7 @@ public class MoreLikeThisFieldQueryBuilder extends BaseQueryBuilder implements B
|
|||
*/
|
||||
@Deprecated
|
||||
public MoreLikeThisFieldQueryBuilder percentTermsToMatch(float percentTermsToMatch) {
|
||||
return minimumShouldMatch((int) (percentTermsToMatch * 100) + "%");
|
||||
return minimumShouldMatch(Math.round(percentTermsToMatch * 100) + "%");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -99,7 +99,7 @@ public class MoreLikeThisFieldQueryParser implements QueryParser {
|
|||
} else if (MoreLikeThisQueryParser.Fields.MINIMUM_SHOULD_MATCH.match(currentFieldName,parseContext.parseFlags())) {
|
||||
mltQuery.setMinimumShouldMatch(parser.text());
|
||||
} else if (MoreLikeThisQueryParser.Fields.PERCENT_TERMS_TO_MATCH.match(currentFieldName,parseContext.parseFlags())) {
|
||||
mltQuery.setMinimumShouldMatch((int) (parser.floatValue() * 100) + "%");
|
||||
mltQuery.setMinimumShouldMatch(Math.round(parser.floatValue() * 100) + "%");
|
||||
} else if ("analyzer".equals(currentFieldName)) {
|
||||
analyzer = parseContext.analysisService().analyzer(parser.text());
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
|
|
|
@ -199,7 +199,7 @@ public class MoreLikeThisQueryBuilder extends BaseQueryBuilder implements Boosta
|
|||
*/
|
||||
@Deprecated
|
||||
public MoreLikeThisQueryBuilder percentTermsToMatch(float percentTermsToMatch) {
|
||||
return minimumShouldMatch((int) (percentTermsToMatch * 100) + "%");
|
||||
return minimumShouldMatch(Math.round(percentTermsToMatch * 100) + "%");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -128,7 +128,7 @@ public class MoreLikeThisQueryParser implements QueryParser {
|
|||
} 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((int) (parser.floatValue() * 100) + "%");
|
||||
mltQuery.setMinimumShouldMatch(Math.round(parser.floatValue() * 100) + "%");
|
||||
} else if ("analyzer".equals(currentFieldName)) {
|
||||
analyzer = parseContext.analysisService().analyzer(parser.text());
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
|
|
Loading…
Reference in New Issue