Skip to content

Commit f18aade

Browse files
committed
Refactored method minTermLength() as per @sandeshkr419's advice
Signed-off-by: Dmitry Kryukov <[email protected]>
1 parent 72ebe23 commit f18aade

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

modules/percolator/src/main/java/org/opensearch/percolator/QueryAnalyzer.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,19 +510,25 @@ static Result selectBestResult(Result result1, Result result2) {
510510
}
511511

512512
private static int minTermLength(Set<QueryExtraction> extractions) {
513-
// In case there are only range extractions, then we return Integer.MIN_VALUE,
514-
// so that selectBestExtraction(...) we are likely to prefer the extractions that contains at least a single extraction
515-
if (extractions.stream().noneMatch(queryExtraction -> queryExtraction.term != null)
516-
&& extractions.stream().anyMatch(queryExtraction -> queryExtraction.range != null)) {
517-
return Integer.MIN_VALUE;
518-
}
519-
513+
boolean hasTerm = false;
514+
boolean hasRange = false;
520515
int min = Integer.MAX_VALUE;
516+
521517
for (QueryExtraction qt : extractions) {
522518
if (qt.term != null) {
519+
hasTerm = true;
523520
min = Math.min(min, qt.bytes().length);
524521
}
522+
if (qt.range != null) {
523+
hasRange = true;
524+
}
525525
}
526+
527+
// If there are no terms but there are ranges, return Integer.MIN_VALUE
528+
if (!hasTerm && hasRange) {
529+
return Integer.MIN_VALUE;
530+
}
531+
526532
return min;
527533
}
528534

0 commit comments

Comments
 (0)