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:
Alex Ksikes 2014-09-30 15:30:09 +02:00
parent fca406415d
commit e53b2eede7
6 changed files with 6 additions and 6 deletions

View File

@ -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) + "%");
}
/**

View File

@ -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) + "%");
}
/**

View File

@ -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) + "%");
}
/**

View File

@ -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)) {

View File

@ -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) + "%");
}
/**

View File

@ -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)) {