You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/03/08 07:43:57 UTC
[GitHub] [lucene] LuXugang opened a new pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
LuXugang opened a new pull request #736:
URL: https://github.com/apache/lucene/pull/736
When IndexSortSortedNumericDocValuesRangeQuery can take advantage of index sort, Weight#count will use BoundedDocSetIdIterator's lastDoc and firstDoc to calculate count, but if missingValue enables, those Documents which not contain DocValues may be involved in calculating count.
That is why in BoundedDocSetIdIterator#advance(int target), target need to be check if such Document contains DocValues
`int result = delegate.advance(target);`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jpountz commented on a change in pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
Posted by GitBox <gi...@apache.org>.
jpountz commented on a change in pull request #736:
URL: https://github.com/apache/lucene/pull/736#discussion_r827711332
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -307,9 +292,16 @@ private BoundedDocIdSetIterator getDocIdSetIterator(
}
int lastDocIdExclusive = high + 1;
- BoundedDocIdSetIterator disi =
- new BoundedDocIdSetIterator(firstDocIdInclusive, lastDocIdExclusive, delegate);
- return boundedDisiFunction.apply(sortField.getMissingValue(), disi);
+ Object missingValue = sortField.getMissingValue();
+ BoundedDocIdSetIterator disi;
+ if (missingValue == null
+ || (long) missingValue < lowerValue
+ || (long) missingValue > upperValue) {
Review comment:
I don't think it's correct to exclude the `missingValue == null` case since it's assumed to be zero by default? We should resolve the missing value that is used in practice first, e.g. as below?
```
final long missingLongValue = missingValue == null ? 0L : (long) missingValue;
if (missingLongValue < lowerValue || missingValue > upperValue) { ... }
```
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -380,4 +372,25 @@ public long cost() {
return lastDoc - firstDoc;
}
}
+
+ private static class BoundedAllMatchDocIdSetIterator extends BoundedDocIdSetIterator {
+
+ BoundedAllMatchDocIdSetIterator(int firstDoc, int lastDoc) {
+ super(firstDoc, lastDoc, null);
+ }
+
+ @Override
+ public int advance(int target) throws IOException {
+ if (target < firstDoc) {
+ target = firstDoc;
+ }
+
+ if (target < lastDoc) {
+ docID = target;
+ } else {
+ docID = NO_MORE_DOCS;
+ }
+ return docID;
+ }
+ }
Review comment:
nit: I'd rather fold this logic into `BoundedDocIdSetIterator` with a `null` check on `delegate` unless we have evidence that the sub class buys us much?
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -201,27 +200,18 @@ public boolean isCacheable(LeafReaderContext ctx) {
@Override
public int count(LeafReaderContext context) throws IOException {
- BoundedDocIdSetIterator disi;
- PointValues pointValues = context.reader().getPointValues(field);
- if (pointValues != null && pointValues.getDocCount() == context.reader().maxDoc()) {
- disi = getDocIdSetIteratorOrNull(context, (missingValue, boundedDisi) -> boundedDisi);
- } else {
- disi =
- getDocIdSetIteratorOrNull(
- context,
- (missingValue, boundedDisi) -> {
- if (missingValue == null
- || (long) missingValue < lowerValue
- || (long) missingValue > upperValue) {
- return boundedDisi;
- }
- return null;
- });
- }
-
+ LeafReader reader = context.reader();
+ PointValues pointValues = reader.getPointValues(field);
+ BoundedDocIdSetIterator disi = getDocIdSetIteratorOrNull(context);
if (disi != null) {
- return disi.lastDoc - disi.firstDoc;
+ if (reader.hasDeletions() == false
+ && pointValues != null
+ && pointValues.getDocCount() == context.reader().maxDoc()
Review comment:
this `docCount == maxDoc` check could move to `getDocIdSetIterator` to set the `delegate` to `null` when the field is dense?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jtibshirani commented on a change in pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
Posted by GitBox <gi...@apache.org>.
jtibshirani commented on a change in pull request #736:
URL: https://github.com/apache/lucene/pull/736#discussion_r830381767
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -278,7 +287,21 @@ private BoundedDocSetIdIterator getDocIdSetIterator(
}
int lastDocIdExclusive = high + 1;
- return new BoundedDocSetIdIterator(firstDocIdInclusive, lastDocIdExclusive, delegate);
+ Object missingValue = sortField.getMissingValue();
Review comment:
Pinging again on this: what do you think of moving `reader.hasDeletions` up to the check inside `count` instead?
##########
File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -459,56 +468,122 @@ public void testIndexSortOptimizationDeactivated(RandomIndexWriter writer) throw
reader.close();
}
- public void testCount() throws IOException {
- Directory dir = newDirectory();
- IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
- Sort indexSort = new Sort(new SortedNumericSortField("field", SortField.Type.LONG));
- iwc.setIndexSort(indexSort);
- RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
- Document doc = new Document();
- doc.add(new SortedNumericDocValuesField("field", 10));
- writer.addDocument(doc);
- IndexReader reader = writer.getReader();
- IndexSearcher searcher = newSearcher(reader);
+ public void testCompareCount() throws IOException {
+ final int iters = atLeast(10);
+ for (int iter = 0; iter < iters; ++iter) {
+ Directory dir = newDirectory();
+ IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
+ SortField sortField = new SortedNumericSortField("field", SortField.Type.LONG);
+ boolean enableMissingValue = random().nextBoolean();
+ if (enableMissingValue) {
+ long missingValue =
+ random().nextBoolean()
+ ? Long.MIN_VALUE
+ : (random().nextBoolean() ? Long.MAX_VALUE : random().nextLong());
+ sortField.setMissingValue(missingValue);
+ }
+ RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
- Query fallbackQuery = LongPoint.newRangeQuery("field", 1, 42);
- Query query = new IndexSortSortedNumericDocValuesRangeQuery("field", 1, 42, fallbackQuery);
- Weight weight = query.createWeight(searcher, ScoreMode.COMPLETE, 1.0f);
- for (LeafReaderContext context : searcher.getLeafContexts()) {
- assertEquals(1, weight.count(context));
+ final int numDocs = atLeast(100);
+ for (int i = 0; i < numDocs; ++i) {
+ Document doc = new Document();
+ final int numValues = TestUtil.nextInt(random(), 0, 1);
+ for (int j = 0; j < numValues; ++j) {
+ final long value = TestUtil.nextLong(random(), -100, 10000);
+ doc =
+ random().nextBoolean()
+ ? createMissingValueDocument()
+ : createSNDVAndPointDocument("field", value);
+ }
+ writer.addDocument(doc);
+ }
+
+ if (random().nextBoolean()) {
+ writer.deleteDocuments(LongPoint.newRangeQuery("field", 0L, 10L));
+ }
+
+ final IndexReader reader = writer.getReader();
+ final IndexSearcher searcher = newSearcher(reader);
+ writer.close();
+
+ for (int i = 0; i < 100; ++i) {
+ final long min =
+ random().nextBoolean() ? Long.MIN_VALUE : TestUtil.nextLong(random(), -100, 10000);
+ final long max =
+ random().nextBoolean() ? Long.MAX_VALUE : TestUtil.nextLong(random(), -100, 10000);
+ final Query q1 = LongPoint.newRangeQuery("field", min, max);
+
+ final Query fallbackQuery = LongPoint.newRangeQuery("field", min, max);
+ final Query q2 =
+ new IndexSortSortedNumericDocValuesRangeQuery("field", min, max, fallbackQuery);
+ final Weight weight1 = q1.createWeight(searcher, ScoreMode.COMPLETE, 1.0f);
+ final Weight weight2 = q2.createWeight(searcher, ScoreMode.COMPLETE, 1.0f);
+ assertSameCount(weight1, weight2, searcher);
+ }
+
+ reader.close();
+ dir.close();
}
+ }
- writer.close();
- reader.close();
- dir.close();
+ private void assertSameCount(Weight weight1, Weight weight2, IndexSearcher searcher)
+ throws IOException {
+ for (LeafReaderContext context : searcher.getLeafContexts()) {
+ assertEquals(weight1.count(context), weight2.count(context));
+ }
}
- public void testFallbackCount() throws IOException {
+ public void testCountBoundary() throws IOException {
Directory dir = newDirectory();
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
- Sort indexSort = new Sort(new SortedNumericSortField("field", SortField.Type.LONG));
+ SortField sortField = new SortedNumericSortField("field", SortField.Type.LONG);
+ // true: lower
+ // false: upper
+ boolean lowerOrUpper = random().nextBoolean();
Review comment:
Small comment, maybe `useLower` would be clearer here, then you wouldn't need the comment explanation.
##########
File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -59,7 +61,14 @@ public void testSameHitsAsPointRangeQuery() throws IOException {
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
boolean reverse = random().nextBoolean();
SortField sortField = new SortedNumericSortField("dv", SortField.Type.LONG, reverse);
- sortField.setMissingValue(random().nextLong());
+ boolean enableMissingValue = random().nextBoolean();
+ if (enableMissingValue) {
+ long missingValue =
Review comment:
I find this check a little hard to follow and the probabilities end up being surprising -- 1/2 for MIN_VALUE, 1/4 for MAX_VALUE, 1/4 a random long. Maybe we could do half the time a random long, half the time randomly choose between MIN_VALUE and MAX_VALUE.
##########
File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -459,56 +468,122 @@ public void testIndexSortOptimizationDeactivated(RandomIndexWriter writer) throw
reader.close();
}
- public void testCount() throws IOException {
- Directory dir = newDirectory();
- IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
- Sort indexSort = new Sort(new SortedNumericSortField("field", SortField.Type.LONG));
- iwc.setIndexSort(indexSort);
- RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
- Document doc = new Document();
- doc.add(new SortedNumericDocValuesField("field", 10));
- writer.addDocument(doc);
- IndexReader reader = writer.getReader();
- IndexSearcher searcher = newSearcher(reader);
+ public void testCompareCount() throws IOException {
+ final int iters = atLeast(10);
+ for (int iter = 0; iter < iters; ++iter) {
+ Directory dir = newDirectory();
+ IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
+ SortField sortField = new SortedNumericSortField("field", SortField.Type.LONG);
+ boolean enableMissingValue = random().nextBoolean();
+ if (enableMissingValue) {
+ long missingValue =
+ random().nextBoolean()
+ ? Long.MIN_VALUE
+ : (random().nextBoolean() ? Long.MAX_VALUE : random().nextLong());
+ sortField.setMissingValue(missingValue);
+ }
+ RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
- Query fallbackQuery = LongPoint.newRangeQuery("field", 1, 42);
- Query query = new IndexSortSortedNumericDocValuesRangeQuery("field", 1, 42, fallbackQuery);
- Weight weight = query.createWeight(searcher, ScoreMode.COMPLETE, 1.0f);
- for (LeafReaderContext context : searcher.getLeafContexts()) {
- assertEquals(1, weight.count(context));
+ final int numDocs = atLeast(100);
+ for (int i = 0; i < numDocs; ++i) {
+ Document doc = new Document();
+ final int numValues = TestUtil.nextInt(random(), 0, 1);
+ for (int j = 0; j < numValues; ++j) {
+ final long value = TestUtil.nextLong(random(), -100, 10000);
+ doc =
+ random().nextBoolean()
+ ? createMissingValueDocument()
+ : createSNDVAndPointDocument("field", value);
+ }
+ writer.addDocument(doc);
+ }
+
+ if (random().nextBoolean()) {
+ writer.deleteDocuments(LongPoint.newRangeQuery("field", 0L, 10L));
+ }
+
+ final IndexReader reader = writer.getReader();
+ final IndexSearcher searcher = newSearcher(reader);
+ writer.close();
+
+ for (int i = 0; i < 100; ++i) {
+ final long min =
+ random().nextBoolean() ? Long.MIN_VALUE : TestUtil.nextLong(random(), -100, 10000);
+ final long max =
+ random().nextBoolean() ? Long.MAX_VALUE : TestUtil.nextLong(random(), -100, 10000);
+ final Query q1 = LongPoint.newRangeQuery("field", min, max);
+
+ final Query fallbackQuery = LongPoint.newRangeQuery("field", min, max);
+ final Query q2 =
+ new IndexSortSortedNumericDocValuesRangeQuery("field", min, max, fallbackQuery);
+ final Weight weight1 = q1.createWeight(searcher, ScoreMode.COMPLETE, 1.0f);
+ final Weight weight2 = q2.createWeight(searcher, ScoreMode.COMPLETE, 1.0f);
+ assertSameCount(weight1, weight2, searcher);
+ }
+
+ reader.close();
+ dir.close();
}
+ }
- writer.close();
- reader.close();
- dir.close();
+ private void assertSameCount(Weight weight1, Weight weight2, IndexSearcher searcher)
+ throws IOException {
+ for (LeafReaderContext context : searcher.getLeafContexts()) {
+ assertEquals(weight1.count(context), weight2.count(context));
+ }
}
- public void testFallbackCount() throws IOException {
Review comment:
Could you explain why you removed this test? It seemed helpful to me.
##########
File path: lucene/CHANGES.txt
##########
@@ -56,14 +56,17 @@ API Changes
New Features
---------------------
-(No changes)
+
+* LUCENE-10385: Implement Weight#count on IndexSortSortedNumericDocValuesRangeQuery
+ to speed up computing the number of hits when possible. (Lu Xugang, Cavanna, Adrien Grand)
Review comment:
We could keep Luca's name here: Luca Cavanna :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jpountz commented on a change in pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
Posted by GitBox <gi...@apache.org>.
jpountz commented on a change in pull request #736:
URL: https://github.com/apache/lucene/pull/736#discussion_r827810798
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -198,16 +200,23 @@ public boolean isCacheable(LeafReaderContext ctx) {
@Override
public int count(LeafReaderContext context) throws IOException {
- BoundedDocSetIdIterator disi = getDocIdSetIteratorOrNull(context);
- if (disi != null) {
+
+ BoundedDocIdSetIterator disi = getDocIdSetIteratorOrNull(context);
+ if (disi != null && disi.delegate == null) {
return disi.lastDoc - disi.firstDoc;
}
- return fallbackWeight.count(context);
+
+ PointValues pointValues = context.reader().getPointValues(field);
+ // if no point indexed, PointRangeQuery#count equals 0, that's sometimes not what we want.
+ if (pointValues != null) {
+ return fallbackWeight.count(context);
+ }
Review comment:
I don't think we should do this, this query isn't making expectations about what `fallbackWeight` actually does. It's the responsibility of the caller to make sure to pass a fallback weight that makes sense. Let's not check points and just return `fallbackWeight.count(context)` as before?
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -306,14 +329,14 @@ private static ValueComparator loadComparator(
* A doc ID set iterator that wraps a delegate iterator and only returns doc IDs in the range
* [firstDocInclusive, lastDoc).
*/
- private static class BoundedDocSetIdIterator extends DocIdSetIterator {
- private final int firstDoc;
- private final int lastDoc;
+ private static class BoundedDocIdSetIterator extends DocIdSetIterator {
+ protected final int firstDoc;
+ protected final int lastDoc;
private final DocIdSetIterator delegate;
- private int docID = -1;
+ protected int docID = -1;
Review comment:
and here too?
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -278,7 +280,21 @@ private BoundedDocSetIdIterator getDocIdSetIterator(
}
int lastDocIdExclusive = high + 1;
- return new BoundedDocSetIdIterator(firstDocIdInclusive, lastDocIdExclusive, delegate);
+ Object missingValue = sortField.getMissingValue();
+ BoundedDocIdSetIterator disi;
+ LeafReader reader = context.reader();
+ PointValues pointValues = reader.getPointValues(field);
+ final long missingLongValue = missingValue == null ? 0L : (long) missingValue;
+ // all documents have docValues or missing value falls outside the range
+ if ((reader.hasDeletions() == false
Review comment:
Can you mave this `hasDeletions` check inside `count` instead as @jtibshirani suggested? It would still be ok to set the delegate to `null` for `scorer` if there are deletions since deletes are applied on top of the `Scorer` API.
##########
File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -59,7 +61,14 @@ public void testSameHitsAsPointRangeQuery() throws IOException {
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
boolean reverse = random().nextBoolean();
SortField sortField = new SortedNumericSortField("dv", SortField.Type.LONG, reverse);
- sortField.setMissingValue(random().nextLong());
+ boolean enableMissingValue = random().nextBoolean();
+ if (enableMissingValue) {
+ long missingValue =
+ random().nextBoolean()
+ ? random().nextLong()
Review comment:
The problem with a random long is that almost all the time it would fall outside of the query ranges that we test below, so we would have no coverage for the case when the missing value is set and falls within the query range.
Can you use a random long between -100 and 10,000 like other values or something like that instead?
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -306,14 +329,14 @@ private static ValueComparator loadComparator(
* A doc ID set iterator that wraps a delegate iterator and only returns doc IDs in the range
* [firstDocInclusive, lastDoc).
*/
- private static class BoundedDocSetIdIterator extends DocIdSetIterator {
- private final int firstDoc;
- private final int lastDoc;
+ private static class BoundedDocIdSetIterator extends DocIdSetIterator {
+ protected final int firstDoc;
+ protected final int lastDoc;
Review comment:
let's keep these private?
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -278,7 +287,21 @@ private BoundedDocSetIdIterator getDocIdSetIterator(
}
int lastDocIdExclusive = high + 1;
- return new BoundedDocSetIdIterator(firstDocIdInclusive, lastDocIdExclusive, delegate);
+ Object missingValue = sortField.getMissingValue();
+ BoundedDocIdSetIterator disi;
+ LeafReader reader = context.reader();
+ PointValues pointValues = reader.getPointValues(field);
+ final long missingLongValue = missingValue == null ? 0L : (long) missingValue;
+ if (reader.hasDeletions() == false
Review comment:
We shouldn't check `hasDeletions` here, only in `Weight#count`.
The reason is that the only thing we care about here is whether all documents have a value or not, whether these documents are deleted or not is only a concern for `Weight#count`.
##########
File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -471,44 +480,134 @@ public void testCount() throws IOException {
IndexReader reader = writer.getReader();
IndexSearcher searcher = newSearcher(reader);
- Query fallbackQuery = LongPoint.newRangeQuery("field", 1, 42);
- Query query = new IndexSortSortedNumericDocValuesRangeQuery("field", 1, 42, fallbackQuery);
+ // we use an unrealistic query that exposes its own Weight#count
+ Query fallbackQuery = new MatchNoDocsQuery();
+ // the index is not sorted on this field, the fallback query is used
+ Query query = new IndexSortSortedNumericDocValuesRangeQuery("another", 1, 42, fallbackQuery);
Weight weight = query.createWeight(searcher, ScoreMode.COMPLETE, 1.0f);
for (LeafReaderContext context : searcher.getLeafContexts()) {
- assertEquals(1, weight.count(context));
+ assertEquals(0, weight.count(context));
}
writer.close();
reader.close();
dir.close();
}
- public void testFallbackCount() throws IOException {
+ public void testCompareCount() throws IOException {
+ final int iters = atLeast(10);
+ for (int iter = 0; iter < iters; ++iter) {
+ Directory dir = newDirectory();
+ IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
+ SortField sortField = new SortedNumericSortField("field", SortField.Type.LONG);
+ boolean enableMissingValue = random().nextBoolean();
+ if (enableMissingValue) {
+ long missingValue =
+ random().nextBoolean()
+ ? random().nextLong()
+ : (random().nextBoolean() ? Long.MIN_VALUE : Long.MAX_VALUE);
+ sortField.setMissingValue(missingValue);
+ }
+ RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
+
+ final int numDocs = atLeast(100);
+ for (int i = 0; i < numDocs; ++i) {
+ Document doc = new Document();
+ final int numValues = TestUtil.nextInt(random(), 0, 1);
+ for (int j = 0; j < numValues; ++j) {
+ final long value = TestUtil.nextLong(random(), -100, 10000);
+ doc =
+ random().nextBoolean()
+ ? createMissingValueDocument()
Review comment:
Hmm, I don't understand this, are we not already creating a document that has a missing value when `numValues` is equal to 0?
##########
File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -471,44 +480,134 @@ public void testCount() throws IOException {
IndexReader reader = writer.getReader();
IndexSearcher searcher = newSearcher(reader);
- Query fallbackQuery = LongPoint.newRangeQuery("field", 1, 42);
- Query query = new IndexSortSortedNumericDocValuesRangeQuery("field", 1, 42, fallbackQuery);
+ // we use an unrealistic query that exposes its own Weight#count
+ Query fallbackQuery = new MatchNoDocsQuery();
+ // the index is not sorted on this field, the fallback query is used
+ Query query = new IndexSortSortedNumericDocValuesRangeQuery("another", 1, 42, fallbackQuery);
Weight weight = query.createWeight(searcher, ScoreMode.COMPLETE, 1.0f);
for (LeafReaderContext context : searcher.getLeafContexts()) {
- assertEquals(1, weight.count(context));
+ assertEquals(0, weight.count(context));
}
writer.close();
reader.close();
dir.close();
}
- public void testFallbackCount() throws IOException {
+ public void testCompareCount() throws IOException {
+ final int iters = atLeast(10);
+ for (int iter = 0; iter < iters; ++iter) {
+ Directory dir = newDirectory();
+ IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
+ SortField sortField = new SortedNumericSortField("field", SortField.Type.LONG);
+ boolean enableMissingValue = random().nextBoolean();
+ if (enableMissingValue) {
+ long missingValue =
+ random().nextBoolean()
+ ? random().nextLong()
Review comment:
and likewise here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jtibshirani commented on a change in pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
Posted by GitBox <gi...@apache.org>.
jtibshirani commented on a change in pull request #736:
URL: https://github.com/apache/lucene/pull/736#discussion_r828330417
##########
File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestIndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -459,54 +461,55 @@ public void testIndexSortOptimizationDeactivated(RandomIndexWriter writer) throw
reader.close();
}
- public void testCount() throws IOException {
+ public void testCountHasMissingValue() throws IOException {
Review comment:
It could be really helpful to add another test like `testSameHitsAsPointRangeQuery` that compares the counts of the two queries. Also in `testSameHitsAsPointRangeQuery` I noticed that we always set `sortField.setMissingValue(random().nextLong())`, it'd be great to randomize this more -- sometimes not setting it at all, sometimes setting it to `Long.MIN_VALUE` or `Long.MAX_VALUE`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jtibshirani commented on a change in pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
Posted by GitBox <gi...@apache.org>.
jtibshirani commented on a change in pull request #736:
URL: https://github.com/apache/lucene/pull/736#discussion_r828333005
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -198,16 +200,23 @@ public boolean isCacheable(LeafReaderContext ctx) {
@Override
public int count(LeafReaderContext context) throws IOException {
- BoundedDocSetIdIterator disi = getDocIdSetIteratorOrNull(context);
- if (disi != null) {
+
+ BoundedDocIdSetIterator disi = getDocIdSetIteratorOrNull(context);
+ if (disi != null && disi.delegate == null) {
return disi.lastDoc - disi.firstDoc;
}
- return fallbackWeight.count(context);
+
+ PointValues pointValues = context.reader().getPointValues(field);
Review comment:
If there's a fallback query provided, it's guaranteed to match the same documents (from the javadoc: "This fallback must be an equivalent range query -- it should produce the same documents and give constant scores"). There's nothing in this query that guarantees the fallback query uses point values, so the check feels out of place.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jtibshirani commented on a change in pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
Posted by GitBox <gi...@apache.org>.
jtibshirani commented on a change in pull request #736:
URL: https://github.com/apache/lucene/pull/736#discussion_r828316628
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -278,7 +287,21 @@ private BoundedDocSetIdIterator getDocIdSetIterator(
}
int lastDocIdExclusive = high + 1;
- return new BoundedDocSetIdIterator(firstDocIdInclusive, lastDocIdExclusive, delegate);
+ Object missingValue = sortField.getMissingValue();
Review comment:
It feels surprising to be checking deletions here, since it's not relevant to the query case -- maybe we could pull that into the `count` method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jpountz commented on a change in pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
Posted by GitBox <gi...@apache.org>.
jpountz commented on a change in pull request #736:
URL: https://github.com/apache/lucene/pull/736#discussion_r825981973
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -198,16 +198,22 @@ public boolean isCacheable(LeafReaderContext ctx) {
@Override
public int count(LeafReaderContext context) throws IOException {
- BoundedDocSetIdIterator disi = getDocIdSetIteratorOrNull(context);
- if (disi != null) {
- return disi.lastDoc - disi.firstDoc;
+ Sort indexSort = context.reader().getMetaData().getSort();
+ if (indexSort != null
+ && indexSort.getSort().length > 0
+ && indexSort.getSort()[0].getField().equals(field)
+ && indexSort.getSort()[0].getMissingValue() == null) {
Review comment:
I don't think that this is the right thing to check since the missing value is assumed to be zero if not set.
The best thing we can do that I can think of is to check if the field is dense via points (ie. no missing values) or if the missing value falls outside of the range so that the bounded iterator is accurate?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jpountz merged pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
Posted by GitBox <gi...@apache.org>.
jpountz merged pull request #736:
URL: https://github.com/apache/lucene/pull/736
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jtibshirani commented on a change in pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
Posted by GitBox <gi...@apache.org>.
jtibshirani commented on a change in pull request #736:
URL: https://github.com/apache/lucene/pull/736#discussion_r828339904
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -306,14 +329,14 @@ private static ValueComparator loadComparator(
* A doc ID set iterator that wraps a delegate iterator and only returns doc IDs in the range
* [firstDocInclusive, lastDoc).
*/
- private static class BoundedDocSetIdIterator extends DocIdSetIterator {
- private final int firstDoc;
- private final int lastDoc;
+ private static class BoundedDocIdSetIterator extends DocIdSetIterator {
+ protected final int firstDoc;
+ protected final int lastDoc;
private final DocIdSetIterator delegate;
- private int docID = -1;
+ protected int docID = -1;
Review comment:
I think this could still be private.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] LuXugang commented on a change in pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
Posted by GitBox <gi...@apache.org>.
LuXugang commented on a change in pull request #736:
URL: https://github.com/apache/lucene/pull/736#discussion_r826515036
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -198,16 +198,22 @@ public boolean isCacheable(LeafReaderContext ctx) {
@Override
public int count(LeafReaderContext context) throws IOException {
- BoundedDocSetIdIterator disi = getDocIdSetIteratorOrNull(context);
- if (disi != null) {
- return disi.lastDoc - disi.firstDoc;
+ Sort indexSort = context.reader().getMetaData().getSort();
+ if (indexSort != null
+ && indexSort.getSort().length > 0
+ && indexSort.getSort()[0].getField().equals(field)
+ && indexSort.getSort()[0].getMissingValue() == null) {
Review comment:
`indexSort.getSort()[0].getMissingValue() == null`
It indeed seems too aggressive, Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] iverase commented on a change in pull request #736: LUCENE-10458: BoundedDocSetIdIterator may supply error count in Weigth#count(LeafReaderContext) when missingValue enables
Posted by GitBox <gi...@apache.org>.
iverase commented on a change in pull request #736:
URL: https://github.com/apache/lucene/pull/736#discussion_r827815011
##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java
##########
@@ -278,7 +287,21 @@ private BoundedDocSetIdIterator getDocIdSetIterator(
}
int lastDocIdExclusive = high + 1;
- return new BoundedDocSetIdIterator(firstDocIdInclusive, lastDocIdExclusive, delegate);
+ Object missingValue = sortField.getMissingValue();
+ BoundedDocIdSetIterator disi;
+ LeafReader reader = context.reader();
+ PointValues pointValues = reader.getPointValues(field);
+ final long missingLongValue = missingValue == null ? 0L : (long) missingValue;
+ if (reader.hasDeletions() == false
+ && pointValues != null
+ && pointValues.getDocCount() == reader.maxDoc()
+ || missingLongValue < lowerValue
+ || missingLongValue > upperValue) {
Review comment:
This if condition is extremely difficult to read, I wonder if we should add some parenthesis or rewrite it somehow to make it clear
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org