cpoerschke commented on code in PR #2248:
URL: https://github.com/apache/solr/pull/2248#discussion_r1489810761
##########
solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java:
##########
@@ -1917,6 +1963,203 @@ public ScoreMode scoreMode() {
qr.setDocList(new DocSlice(0, sliceLen, ids, scores, totalHits, maxScore,
hitsRelation));
}
+ SearchResult searchCollectorManagers(
+ int len,
+ QueryCommand cmd,
+ Query query,
+ boolean needTopDocs,
+ boolean needMaxScore,
+ boolean needDocSet)
+ throws IOException {
+ Collection<CollectorManager<Collector, Object>> collectors = new
ArrayList<>();
+ ScoreMode scoreMode = null;
+
+ Collector[] firstCollectors = new Collector[3];
+
+ if (needTopDocs) {
+
+ collectors.add(
+ new CollectorManager<>() {
+ @Override
+ public Collector newCollector() throws IOException {
+ @SuppressWarnings("rawtypes")
+ TopDocsCollector collector = buildTopDocsCollector(len, cmd);
+ if (firstCollectors[0] == null) {
+ firstCollectors[0] = collector;
+ }
+ return collector;
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ public Object reduce(Collection collectors) throws IOException {
+
+ TopDocs[] topDocs = new TopDocs[collectors.size()];
+
+ int totalHits = -1;
+ int i = 0;
+
+ Collector collector;
+ for (Object o : collectors) {
+ collector = (Collector) o;
+ if (collector instanceof TopDocsCollector) {
+ TopDocs td = ((TopDocsCollector) collector).topDocs(0, len);
+ assert td != null : Arrays.asList(topDocs);
+ topDocs[i++] = td;
+ }
+ }
+
+ TopDocs mergedTopDocs = null;
+
+ if (topDocs.length > 0 && topDocs[0] != null) {
+ if (topDocs[0] instanceof TopFieldDocs) {
+ TopFieldDocs[] topFieldDocs =
+ Arrays.copyOf(topDocs, topDocs.length,
TopFieldDocs[].class);
+ mergedTopDocs =
TopFieldDocs.merge(weightSort(cmd.getSort()), len, topFieldDocs);
+ } else {
+ mergedTopDocs = TopDocs.merge(0, len, topDocs);
+ }
+ totalHits = (int) mergedTopDocs.totalHits.value;
+ }
+ return new TopDocsResult(mergedTopDocs, totalHits);
+ }
+ });
+ }
+ if (needMaxScore) {
+ collectors.add(
+ new CollectorManager<>() {
+ @Override
+ public Collector newCollector() throws IOException {
+ MaxScoreCollector collector = new MaxScoreCollector();
+ if (firstCollectors[1] == null) {
+ firstCollectors[1] = collector;
+ }
+ return collector;
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ public Object reduce(Collection collectors) throws IOException {
+
+ MaxScoreCollector collector;
+ float maxScore = 0.0f;
+ for (Iterator var4 = collectors.iterator();
+ var4.hasNext();
+ maxScore = Math.max(maxScore, collector.getMaxScore())) {
+ collector = (MaxScoreCollector) var4.next();
+ }
+
+ return new MaxScoreResult(maxScore);
+ }
+ });
+ }
+ if (needDocSet) {
+ int maxDoc = rawReader.maxDoc();
+ log.error("raw read max={}", rawReader.maxDoc());
+
+ LeafSlice[] leaves = getSlices();
+ int[] docBase = new int[1];
+
+ // DocSetCollector collector = new DocSetCollector(maxDoc);
+
+ ThreadSafeBitSet bits = new ThreadSafeBitSet(14, 2);
+
+ collectors.add(
+ new CollectorManager<>() {
+ @Override
+ public Collector newCollector() throws IOException {
+ int numDocs = 0;
+
+ if (leaves != null) {
+ LeafSlice leaf = leaves[docBase[0]++];
+
+ for (LeafReaderContext reader : leaf.leaves) {
+ numDocs += reader.reader().maxDoc();
+ }
+ } else {
+ numDocs = maxDoc();
+ }
+ log.error("new docset collector for {} max={}", numDocs,
maxDoc());
+
+ return new ThreadSafeBitSetCollector(bits, maxDoc);
Review Comment:
Not sure yet if a `firstCollectors[2] = ...` was intended here or if not we
can reduce to `new Collector[2]` above it seems.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]