Skip to content

Commit 8a4c342

Browse files
Add sort optimization with after from Lucene
Lucene 8.7 introduces numeric sort optimization directly in comparators. This means we don't need to have it in ES. This removes the sort optimization code in ES, and the only thing that is needed is setCanUsePoints on sortField. This also will introduce sort optimization with search_after, as Lucene directly suports sort optimization with search_after.
1 parent 57bd64a commit 8a4c342

File tree

5 files changed

+147
-455
lines changed

5 files changed

+147
-455
lines changed

server/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ public Weight createWeight(Query query, ScoreMode scoreMode, float boost) throws
176176
@SuppressWarnings({"unchecked", "rawtypes"})
177177
public void search(List<LeafReaderContext> leaves, Weight weight, CollectorManager manager,
178178
QuerySearchResult result, DocValueFormat[] formats, TotalHits totalHits) throws IOException {
179+
// As a single collector expects segments in order of doc,
180+
// and we reordered segments, we have to create a separate collector for each segment.
179181
final List<Collector> collectors = new ArrayList<>(leaves.size());
180182
for (LeafReaderContext ctx : leaves) {
181183
final Collector collector = manager.newCollector();
@@ -195,7 +197,7 @@ public void search(List<LeafReaderContext> leaves, Weight weight, CollectorManag
195197
}
196198

197199
@Override
198-
protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector) throws IOException {
200+
public void search(List<LeafReaderContext> leaves, Weight weight, Collector collector) throws IOException {
199201
for (LeafReaderContext ctx : leaves) { // search each subreader
200202
searchLeaf(ctx, weight, collector);
201203
}

0 commit comments

Comments
 (0)