mirror of https://github.com/apache/lucene.git
LUCENE-9023: GlobalOrdinalsWithScore should not compute occurrences when the provided min is 1 (#964)
This commit is contained in:
parent
7ec17376be
commit
36f6359fe4
|
@ -222,6 +222,9 @@ Improvements
|
|||
* LUCENE-9455: ExitableTermsEnum should sample timeout and interruption
|
||||
check before calling next(). (Zach Chen via Bruno Roustant)
|
||||
|
||||
* LUCENE-9023: GlobalOrdinalsWithScore should not compute occurrences when the
|
||||
provided min is 1. (Jim Ferenczi)
|
||||
|
||||
Optimizations
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ abstract class GlobalOrdinalsWithScoreCollector implements Collector {
|
|||
throw new IllegalStateException("Can't collect more than [" + Integer.MAX_VALUE + "] ids");
|
||||
}
|
||||
this.field = field;
|
||||
this.doMinMax = !(min <= 0 && max == Integer.MAX_VALUE);
|
||||
this.doMinMax = min > 1 || max < Integer.MAX_VALUE;
|
||||
this.min = min;
|
||||
this.max = max;;
|
||||
this.ordinalMap = ordinalMap;
|
||||
|
|
|
@ -86,7 +86,7 @@ final class GlobalOrdinalsWithScoreQuery extends Query implements Accountable {
|
|||
if (searcher.getTopReaderContext().id() != indexReaderContextId) {
|
||||
throw new IllegalStateException("Creating the weight against a different index reader than this query has been built for.");
|
||||
}
|
||||
boolean doNoMinMax = min <= 0 && max == Integer.MAX_VALUE;
|
||||
boolean doNoMinMax = min <= 1 && max == Integer.MAX_VALUE;
|
||||
if (scoreMode.needsScores() == false && doNoMinMax) {
|
||||
// We don't need scores then quickly change the query to not uses the scores:
|
||||
GlobalOrdinalsQuery globalOrdinalsQuery = new GlobalOrdinalsQuery(collector.collectedOrds, joinField, globalOrds,
|
||||
|
|
|
@ -496,7 +496,7 @@ public final class JoinUtil {
|
|||
globalOrdinalsWithScoreCollector = new GlobalOrdinalsWithScoreCollector.Avg(joinField, ordinalMap, valueCount, min, max);
|
||||
break;
|
||||
case None:
|
||||
if (min <= 0 && max == Integer.MAX_VALUE) {
|
||||
if (min <= 1 && max == Integer.MAX_VALUE) {
|
||||
GlobalOrdinalsCollector globalOrdinalsCollector = new GlobalOrdinalsCollector(joinField, ordinalMap, valueCount);
|
||||
searcher.search(rewrittenFromQuery, globalOrdinalsCollector);
|
||||
return new GlobalOrdinalsQuery(globalOrdinalsCollector.getCollectorOrdinals(), joinField, ordinalMap, rewrittenToQuery,
|
||||
|
|
|
@ -640,7 +640,6 @@ public class TestJoinUtil extends LuceneTestCase {
|
|||
}
|
||||
assertEquals(expectedCount, collector.getTotalHits());
|
||||
}
|
||||
|
||||
searcher.getIndexReader().close();
|
||||
dir.close();
|
||||
}
|
||||
|
@ -657,8 +656,19 @@ public class TestJoinUtil extends LuceneTestCase {
|
|||
IndexReader reader = w.getReader();
|
||||
IndexSearcher searcher = newSearcher(reader);
|
||||
OrdinalMap ordMap = OrdinalMap.build(null, new SortedDocValues[0], 0f);
|
||||
Query joinQuery = JoinUtil.createJoinQuery("join_field", new MatchNoDocsQuery(), new MatchNoDocsQuery(), searcher, RandomPicks.randomFrom(random(), ScoreMode.values()), ordMap, 0, Integer.MAX_VALUE);
|
||||
{
|
||||
Query joinQuery = JoinUtil.createJoinQuery("join_field", new MatchNoDocsQuery(),
|
||||
new MatchNoDocsQuery(), searcher, RandomPicks.randomFrom(random(), ScoreMode.values()), ordMap, 0, Integer.MAX_VALUE);
|
||||
searcher.search(joinQuery, 1); // no exception due to missing rewrites
|
||||
}
|
||||
{
|
||||
Query joinQuery = JoinUtil.createJoinQuery("join_field", new MatchNoDocsQuery(),
|
||||
new MatchNoDocsQuery(), searcher, ScoreMode.None, ordMap, 1, Integer.MAX_VALUE);
|
||||
Query rewritten = searcher.rewrite(joinQuery);
|
||||
// should simplify to GlobalOrdinalsQuery since min is set to 1
|
||||
assertTrue(rewritten instanceof GlobalOrdinalsQuery);
|
||||
searcher.search(joinQuery, 1); // no exception due to missing rewrites
|
||||
}
|
||||
reader.close();
|
||||
w.close();
|
||||
dir.close();
|
||||
|
|
Loading…
Reference in New Issue