Skip to content

Commit

Permalink
LUCENE-9449 Skip docs with _doc sort and "after" (#1725)
Browse files Browse the repository at this point in the history
- Enhance DocComparator to provide an iterator over competitive
documents when searching with "after". This iterator can quickly position
on the desired "after" document skipping all documents and segments before
"after".

- Redesign numeric comparators to provide skipping functionality
by default.

Relates to LUCENE-9280
  • Loading branch information
mayya-sharipova authored Sep 8, 2020
1 parent 98e55f0 commit 9922067
Show file tree
Hide file tree
Showing 25 changed files with 1,384 additions and 1,002 deletions.
7 changes: 7 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ Improvements

* LUCENE-9313: Add SerbianAnalyzer based on the snowball stemmer. (Dragan Ivanovic)

* LUCENE-9449: Enhance DocComparator to provide an iterator over competitive
documents when searching with "after". This iterator can quickly position
on the desired "after" document skipping all documents and segments before
"after". Also redesign numeric comparators to provide skipping functionality
by default. (Mayya Sharipova, Jim Ferenczi)


Bug fixes

* LUCENE-8663: NRTCachingDirectory.slowFileExists may open a file while
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.search.comparators.DoubleComparator;

/**
* Base class for producing {@link DoubleValues}
Expand Down Expand Up @@ -488,20 +489,26 @@ void setMissingValue(double missingValue) {
@Override
public FieldComparator<Double> newComparator(String fieldname, int numHits,
int sortPos, boolean reversed) {
return new FieldComparator.DoubleComparator(numHits, fieldname, missingValue){

LeafReaderContext ctx;
DoubleValuesHolder holder = new DoubleValuesHolder();

@Override
protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
ctx = context;
return asNumericDocValues(holder, Double::doubleToLongBits);
}

return new DoubleComparator(numHits, fieldname, missingValue, reversed, sortPos) {
@Override
public void setScorer(Scorable scorer) throws IOException {
holder.values = producer.getValues(ctx, fromScorer(scorer));
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
DoubleValuesHolder holder = new DoubleValuesHolder();

return new DoubleComparator.DoubleLeafComparator(context) {
LeafReaderContext ctx;

@Override
protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) {
ctx = context;
return asNumericDocValues(holder, Double::doubleToLongBits);
}

@Override
public void setScorer(Scorable scorer) throws IOException {
holder.values = producer.getValues(ctx, fromScorer(scorer));
super.setScorer(scorer);
}
};
}
};
}
Expand Down
Loading

0 comments on commit 9922067

Please sign in to comment.