New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LUCENE-10385: Implement Weight#count on IndexSortSortedNumericDocValuesRangeQuery #635
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,20 +156,9 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo | |
return new ConstantScoreWeight(this, boost) { | ||
@Override | ||
public Scorer scorer(LeafReaderContext context) throws IOException { | ||
SortedNumericDocValues sortedNumericValues = | ||
DocValues.getSortedNumeric(context.reader(), field); | ||
NumericDocValues numericValues = DocValues.unwrapSingleton(sortedNumericValues); | ||
|
||
if (numericValues != null) { | ||
Sort indexSort = context.reader().getMetaData().getSort(); | ||
if (indexSort != null | ||
&& indexSort.getSort().length > 0 | ||
&& indexSort.getSort()[0].getField().equals(field)) { | ||
|
||
SortField sortField = indexSort.getSort()[0]; | ||
DocIdSetIterator disi = getDocIdSetIterator(sortField, context, numericValues); | ||
return new ConstantScoreScorer(this, score(), scoreMode, disi); | ||
} | ||
DocIdSetIterator disi = getDocIdSetIteratorOrNull(context); | ||
if (disi != null) { | ||
return new ConstantScoreScorer(this, score(), scoreMode, disi); | ||
} | ||
return fallbackWeight.scorer(context); | ||
} | ||
|
@@ -180,9 +169,36 @@ public boolean isCacheable(LeafReaderContext ctx) { | |
// if the fallback query is cacheable. | ||
return fallbackWeight.isCacheable(ctx); | ||
} | ||
|
||
@Override | ||
public int count(LeafReaderContext context) throws IOException { | ||
BoundedDocSetIdIterator disi = getDocIdSetIteratorOrNull(context); | ||
if (disi != null) { | ||
return disi.lastDoc - disi.firstDoc; | ||
} | ||
return fallbackWeight.count(context); | ||
} | ||
}; | ||
} | ||
|
||
private BoundedDocSetIdIterator getDocIdSetIteratorOrNull(LeafReaderContext context) | ||
throws IOException { | ||
SortedNumericDocValues sortedNumericValues = | ||
DocValues.getSortedNumeric(context.reader(), field); | ||
NumericDocValues numericValues = DocValues.unwrapSingleton(sortedNumericValues); | ||
if (numericValues != null) { | ||
Sort indexSort = context.reader().getMetaData().getSort(); | ||
if (indexSort != null | ||
&& indexSort.getSort().length > 0 | ||
&& indexSort.getSort()[0].getField().equals(field)) { | ||
|
||
SortField sortField = indexSort.getSort()[0]; | ||
return getDocIdSetIterator(sortField, context, numericValues); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Computes the document IDs that lie within the range [lowerValue, upperValue] by performing | ||
* binary search on the field's doc values. | ||
|
@@ -195,7 +211,7 @@ public boolean isCacheable(LeafReaderContext ctx) { | |
* {@link DocIdSetIterator} makes sure to wrap the original docvalues to skip over documents with | ||
* no value. | ||
*/ | ||
private DocIdSetIterator getDocIdSetIterator( | ||
private BoundedDocSetIdIterator getDocIdSetIterator( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this a typo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'm pretty sure it is. If you open a PR to rename, I'll merge it. |
||
SortField sortField, LeafReaderContext context, DocIdSetIterator delegate) | ||
throws IOException { | ||
long lower = sortField.getReverse() ? upperValue : lowerValue; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure I deserve having my name on this one :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eheh, I thought you get the credit because you merge it :)