Skip to content

Commit 3bd41b2

Browse files
authored
Remove QueryCollectorContext abstraction (#95383)
The QueryCollectorContext abstraction was introduced by #24864 based on the requirement that the top docs collector creation needed to be delayed until after all the other collectors had been created. At the same time, collectors get wrapped depending on the search features enabled by the request, but the top score / total hit count collector is the root collector where the wrapping starts, which is why its corresponding context gets added at position 0 in the list of collector contexts. Requirements have changed since #27666 , which means that we can go back to a simpler way of creating collectors and wrapping them. We no longer need a QueryCollectorContext abstraction, and we can instead create collectors straight-away, and wrap them as needed. This is much easier to follow compared to the very generic create(Collector) method that the context exposes. TopDocsCollectorContext adds some value in that it incorporates all the logic around creating the top docs collector, yet it can be further simplified as well by making the postProcess method more specific.
1 parent b275d91 commit 3bd41b2

File tree

6 files changed

+124
-246
lines changed

6 files changed

+124
-246
lines changed

server/src/main/java/org/elasticsearch/search/profile/query/CollectorResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class CollectorResult implements ToXContentObject, Writeable {
6767
/**
6868
* A list of children collectors "embedded" inside this collector
6969
*/
70-
private List<CollectorResult> children;
70+
private final List<CollectorResult> children;
7171

7272
public CollectorResult(String collectorName, String reason, long time, List<CollectorResult> children) {
7373
this.collectorName = collectorName;

server/src/main/java/org/elasticsearch/search/profile/query/InternalProfileCollector.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ public class InternalProfileCollector implements Collector {
4747
*/
4848
private final InternalProfileCollector[] children;
4949

50-
public InternalProfileCollector(Collector collector, String reason, InternalProfileCollector... children) {
50+
public InternalProfileCollector(Collector collector, String reason, Collector... children) {
5151
this.collector = new ProfileCollector(collector);
5252
this.reason = reason;
5353
this.collectorName = deriveCollectorName(collector);
5454
Objects.requireNonNull(children, "children collectors cannot be null");
55-
for (InternalProfileCollector child : children) {
56-
Objects.requireNonNull(child, "child collector cannot be null");
55+
this.children = new InternalProfileCollector[children.length];
56+
for (int i = 0; i < children.length; i++) {
57+
this.children[i] = (InternalProfileCollector) Objects.requireNonNull(children[i], "child collector cannot be null");
5758
}
58-
this.children = children;
5959
}
6060

6161
/**

server/src/main/java/org/elasticsearch/search/query/QueryCollectorContext.java

Lines changed: 0 additions & 169 deletions
This file was deleted.

0 commit comments

Comments
 (0)