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 2019/04/10 10:20:11 UTC
[lucene-solr] branch master updated: LUCENE-8751: Weight#matches
now use the ScorerSupplier to build scorers with a lead cost of 1 (single
document).
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 81fe814 LUCENE-8751: Weight#matches now use the ScorerSupplier to build scorers with a lead cost of 1 (single document).
81fe814 is described below
commit 81fe8144280d9ebe12f3020549e61094d4ac46c4
Author: jimczi <ji...@apache.org>
AuthorDate: Wed Apr 10 12:19:45 2019 +0200
LUCENE-8751: Weight#matches now use the ScorerSupplier to build scorers with a lead cost of 1 (single document).
---
lucene/CHANGES.txt | 3 ++
.../src/java/org/apache/lucene/search/Weight.java | 5 ++-
.../apache/lucene/search/TestMatchesIterator.java | 50 ++++++++++++++++++++++
3 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index cdf70f0..ee5fb8b 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -111,6 +111,9 @@ Improvements
children (avg, max, min). Additionally the score mode `none` that assigns a constant score to
each parent can early terminate top scores's collection. (Jim Ferenczi)
+* LUCENE-8751: Weight#matches now use the ScorerSupplier to build scorers with a lead cost of 1
+ (single document). (Jim Ferenczi)
+
Changes in Runtime Behavior
* LUCENE-8671: Load FST off-heap also for ID-like fields if reader is not opened
diff --git a/lucene/core/src/java/org/apache/lucene/search/Weight.java b/lucene/core/src/java/org/apache/lucene/search/Weight.java
index 2f86f4f..8284d14 100644
--- a/lucene/core/src/java/org/apache/lucene/search/Weight.java
+++ b/lucene/core/src/java/org/apache/lucene/search/Weight.java
@@ -71,10 +71,11 @@ public abstract class Weight implements SegmentCacheable {
* @lucene.experimental
*/
public Matches matches(LeafReaderContext context, int doc) throws IOException {
- Scorer scorer = scorer(context);
- if (scorer == null) {
+ ScorerSupplier scorerSupplier = scorerSupplier(context);
+ if (scorerSupplier == null) {
return null;
}
+ Scorer scorer = scorerSupplier.get(1);
final TwoPhaseIterator twoPhase = scorer.twoPhaseIterator();
if (twoPhase == null) {
if (scorer.iterator().advance(doc) != doc) {
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMatchesIterator.java b/lucene/core/src/test/org/apache/lucene/search/TestMatchesIterator.java
index 0bc243d..d80622e 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestMatchesIterator.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestMatchesIterator.java
@@ -28,11 +28,13 @@ import java.util.stream.Collectors;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.ReaderUtil;
@@ -54,6 +56,7 @@ public class TestMatchesIterator extends LuceneTestCase {
private static final String FIELD_NO_OFFSETS = "field_no_offsets";
private static final String FIELD_DOCS_ONLY = "field_docs_only";
private static final String FIELD_FREQS = "field_freqs";
+ private static final String FIELD_POINT = "field_point";
private static final FieldType OFFSETS = new FieldType(TextField.TYPE_STORED);
static {
@@ -89,6 +92,8 @@ public class TestMatchesIterator extends LuceneTestCase {
doc.add(newField(FIELD_NO_OFFSETS, docFields[i], TextField.TYPE_STORED));
doc.add(newField(FIELD_DOCS_ONLY, docFields[i], DOCS));
doc.add(newField(FIELD_FREQS, docFields[i], DOCS_AND_FREQS));
+ doc.add(new IntPoint(FIELD_POINT, 10));
+ doc.add(new NumericDocValuesField(FIELD_POINT, 10));
doc.add(new NumericDocValuesField("id", i));
doc.add(newField("id", Integer.toString(i), TextField.TYPE_STORED));
writer.addDocument(doc);
@@ -652,4 +657,49 @@ public class TestMatchesIterator extends LuceneTestCase {
});
}
+ public void testPointQuery() throws IOException {
+ IndexOrDocValuesQuery pointQuery = new IndexOrDocValuesQuery(
+ IntPoint.newExactQuery(FIELD_POINT, 10),
+ NumericDocValuesField.newSlowExactQuery(FIELD_POINT, 10)
+ );
+ Term t = new Term(FIELD_WITH_OFFSETS, "w1");
+ Query query = new BooleanQuery.Builder()
+ .add(new TermQuery(t), BooleanClause.Occur.MUST)
+ .add(pointQuery, BooleanClause.Occur.MUST)
+ .build();
+
+ checkMatches(pointQuery, FIELD_WITH_OFFSETS, new int[][]{});
+
+ checkMatches(query, FIELD_WITH_OFFSETS, new int[][]{
+ { 0, 0, 0, 0, 2 },
+ { 1, 0, 0, 0, 2 },
+ { 2, 0, 0, 0, 2 },
+ { 3, 0, 0, 0, 2, 2, 2, 6, 8 },
+ { 4 }
+ });
+
+ pointQuery = new IndexOrDocValuesQuery(
+ IntPoint.newExactQuery(FIELD_POINT, 11),
+ NumericDocValuesField.newSlowExactQuery(FIELD_POINT, 11)
+ );
+
+ query = new BooleanQuery.Builder()
+ .add(new TermQuery(t), BooleanClause.Occur.MUST)
+ .add(pointQuery, BooleanClause.Occur.MUST)
+ .build();
+ checkMatches(query, FIELD_WITH_OFFSETS, new int[][]{});
+
+ query = new BooleanQuery.Builder()
+ .add(new TermQuery(t), BooleanClause.Occur.MUST)
+ .add(pointQuery, BooleanClause.Occur.SHOULD)
+ .build();
+ checkMatches(query, FIELD_WITH_OFFSETS, new int[][]{
+ {0, 0, 0, 0, 2},
+ {1, 0, 0, 0, 2},
+ {2, 0, 0, 0, 2},
+ {3, 0, 0, 0, 2, 2, 2, 6, 8},
+ {4}
+ });
+ }
+
}