Skip to content

Commit

Permalink
Remove findBestWeightFor method
Browse files Browse the repository at this point in the history
  • Loading branch information
saikatsarkar056 committed Feb 23, 2024
1 parent ee3233b commit 8969c31
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException {
"["
+ fieldTypeName
+ "]"
+ " is not an appropriate field type for text expansion query. "
+ " is not an appropriate field type for this query. "
+ "Allowed field types are ["
+ AllowedFieldType.getAllowedFieldTypesAsString()
+ "]."
Expand All @@ -185,7 +185,7 @@ private Query queryBuilderWithPrunedTokens(List<WeightedToken> tokens, MappedFie
throws IOException {
var qb = new BooleanQuery.Builder();
int fieldDocCount = context.getIndexReader().getDocCount(fieldName);
float bestWeight = findBestWeightFor(tokens);
float bestWeight = tokens.stream().map(WeightedToken::weight).reduce(0f, Math::max);
float averageTokenFreqRatio = getAverageTokenFreqRatio(context.getIndexReader(), fieldDocCount);
if (averageTokenFreqRatio == 0) {
return new MatchNoDocsQuery("The \"" + getName() + "\" query is against an empty field");
Expand All @@ -202,10 +202,6 @@ private Query queryBuilderWithPrunedTokens(List<WeightedToken> tokens, MappedFie
return qb.setMinimumNumberShouldMatch(1).build();
}

private float findBestWeightFor(List<WeightedToken> tokens) {
return tokens.stream().map(WeightedToken::weight).reduce(0f, Math::max);
}

@Override
protected boolean doEquals(WeightedTokensQueryBuilder other) {
return Objects.equals(fieldName, other.fieldName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ setup:
reason: "validation for invalid field type introduced in 8.14.0"

- do:
catch: /\[keyword\] is not an appropriate field type for text expansion query/
catch: /\[keyword\] is not an appropriate field type for this query/
search:
index: index-with-rank-features
body:
Expand Down

0 comments on commit 8969c31

Please sign in to comment.