You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ji...@apache.org on 2020/11/10 12:12:19 UTC
[lucene-solr] branch master updated: LUCENE-9023:
GlobalOrdinalsWithScore should not compute occurrences when the provided
min is 1 (#964)
This is an automated email from the ASF dual-hosted git repository.
jimczi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/master by this push:
new 36f6359 LUCENE-9023: GlobalOrdinalsWithScore should not compute occurrences when the provided min is 1 (#964)
36f6359 is described below
commit 36f6359fe4b337ab37e97f63fb036a41b5c14b68
Author: Jim Ferenczi <ji...@elastic.co>
AuthorDate: Tue Nov 10 13:12:03 2020 +0100
LUCENE-9023: GlobalOrdinalsWithScore should not compute occurrences when the provided min is 1 (#964)
---
lucene/CHANGES.txt | 3 +++
.../search/join/GlobalOrdinalsWithScoreCollector.java | 2 +-
.../lucene/search/join/GlobalOrdinalsWithScoreQuery.java | 2 +-
.../src/java/org/apache/lucene/search/join/JoinUtil.java | 2 +-
.../test/org/apache/lucene/search/join/TestJoinUtil.java | 16 +++++++++++++---
5 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 163c09c..2d0b866 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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
---------------------
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreCollector.java b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreCollector.java
index ee9731f..56c6991 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreCollector.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreCollector.java
@@ -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;
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
index 183bca1..4a7ed92 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
@@ -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,
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/JoinUtil.java b/lucene/join/src/java/org/apache/lucene/search/join/JoinUtil.java
index 0e933c0..b9d0a43 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/JoinUtil.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/JoinUtil.java
@@ -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,
diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java
index 4d72b13..1803f03 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java
@@ -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);
- searcher.search(joinQuery, 1); // no exception due to missing rewrites
+ {
+ 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();