Skip to content
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

Short-circuit single slice searches in ContextIndexSearcher #111126

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -327,33 +327,35 @@ public <C extends Collector, T> T search(Query query, CollectorManager<C, T> col
* */
private <C extends Collector, T> T search(Weight weight, CollectorManager<C, T> collectorManager, C firstCollector) throws IOException {
LeafSlice[] leafSlices = getSlices();
if (leafSlices.length == 0) {
assert leafContexts.isEmpty();
doAggregationPostCollection(firstCollector);
if (leafSlices.length <= 1) {
if (leafSlices.length == 0) {
assert leafContexts.isEmpty();
doAggregationPostCollection(firstCollector);
} else {
search(Arrays.asList(leafSlices[0].leaves), weight, firstCollector);
}
return collectorManager.reduce(Collections.singletonList(firstCollector));
} else {
final List<C> collectors = new ArrayList<>(leafSlices.length);
collectors.add(firstCollector);
final ScoreMode scoreMode = firstCollector.scoreMode();
for (int i = 1; i < leafSlices.length; ++i) {
final C collector = collectorManager.newCollector();
collectors.add(collector);
}
final ScoreMode scoreMode = firstCollector.scoreMode();
final List<Callable<C>> listTasks = new ArrayList<>(leafSlices.length);
for (int i = 0; i < leafSlices.length; ++i) {
final C collector;
if (i == 0) {
collector = firstCollector;
} else {
collector = collectorManager.newCollector();
if (scoreMode != collector.scoreMode()) {
throw new IllegalStateException("CollectorManager does not always produce collectors with the same score mode");
}
}
final List<Callable<C>> listTasks = new ArrayList<>(leafSlices.length);
for (int i = 0; i < leafSlices.length; ++i) {
final LeafReaderContext[] leaves = leafSlices[i].leaves;
final C collector = collectors.get(i);
listTasks.add(() -> {
search(Arrays.asList(leaves), weight, collector);
return collector;
});
}
List<C> collectedCollectors = getTaskExecutor().invokeAll(listTasks);
return collectorManager.reduce(collectedCollectors);
final LeafReaderContext[] leaves = leafSlices[i].leaves;
listTasks.add(() -> {
search(Arrays.asList(leaves), weight, collector);
return collector;
});
}
List<C> collectedCollectors = getTaskExecutor().invokeAll(listTasks);
return collectorManager.reduce(collectedCollectors);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2842,8 +2842,8 @@ public void testSlicingBehaviourForParallelCollection() throws Exception {
searcher.search(termQuery, new TotalHitCountCollectorManager());
assertBusy(
() -> assertEquals(
"The number of slices should be 1 as FETCH does not support parallel collection.",
1,
"The number of slices should be 0 as FETCH does not support parallel collection.",
0,
executor.getCompletedTaskCount() - priorExecutorTaskCount
)
);
Expand All @@ -2857,8 +2857,8 @@ public void testSlicingBehaviourForParallelCollection() throws Exception {
searcher.search(termQuery, new TotalHitCountCollectorManager());
assertBusy(
() -> assertEquals(
"The number of slices should be 1 as NONE does not support parallel collection.",
1,
"The number of slices should be 0 as NONE does not support parallel collection.",
0,
executor.getCompletedTaskCount() - priorExecutorTaskCount
)
);
Expand All @@ -2880,8 +2880,8 @@ public void testSlicingBehaviourForParallelCollection() throws Exception {
searcher.search(termQuery, new TotalHitCountCollectorManager());
assertBusy(
() -> assertEquals(
"The number of slices should be 1 when QUERY parallel collection is disabled.",
1,
"The number of slices should be 0 when QUERY parallel collection is disabled.",
0,
executor.getCompletedTaskCount() - priorExecutorTaskCount
)
);
Expand Down