munendrasn commented on a change in pull request #1334: SOLR-8306: Enhance 
ExpandComponent to allow expand.hits=0
URL: https://github.com/apache/lucene-solr/pull/1334#discussion_r392043206
 
 

 ##########
 File path: 
solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
 ##########
 @@ -420,37 +421,48 @@ public void process(ResponseBuilder rb) throws 
IOException {
     CharsRefBuilder charsRef = new CharsRefBuilder();
     for (LongObjectCursor<Collector> cursor : groups) {
       long groupValue = cursor.key;
-      TopDocsCollector<?> topDocsCollector = 
TopDocsCollector.class.cast(cursor.value);
-      TopDocs topDocs = topDocsCollector.topDocs();
-      ScoreDoc[] scoreDocs = topDocs.scoreDocs;
-      if (scoreDocs.length > 0) {
-        if (returnFields.wantsScore() && sort != null) {
-          TopFieldCollector.populateScores(scoreDocs, searcher, query);
-        }
-        int[] docs = new int[scoreDocs.length];
-        float[] scores = new float[scoreDocs.length];
-        for (int i = 0; i < docs.length; i++) {
-          ScoreDoc scoreDoc = scoreDocs[i];
-          docs[i] = scoreDoc.doc;
-          scores[i] = scoreDoc.score;
+      if (cursor.value instanceof TopDocsCollector) {
+        TopDocsCollector<?> topDocsCollector = 
TopDocsCollector.class.cast(cursor.value);
+        TopDocs topDocs = topDocsCollector.topDocs();
+        ScoreDoc[] scoreDocs = topDocs.scoreDocs;
+        if (scoreDocs.length > 0) {
+          if (returnFields.wantsScore() && sort != null) {
+            TopFieldCollector.populateScores(scoreDocs, searcher, query);
+          }
+          int[] docs = new int[scoreDocs.length];
+          float[] scores = new float[scoreDocs.length];
+          for (int i = 0; i < docs.length; i++) {
+            ScoreDoc scoreDoc = scoreDocs[i];
+            docs[i] = scoreDoc.doc;
+            scores[i] = scoreDoc.score;
+          }
+          assert topDocs.totalHits.relation == TotalHits.Relation.EQUAL_TO;
+          DocSlice slice = new DocSlice(0, docs.length, docs, scores, 
topDocs.totalHits.value, Float.NaN);
+          addGroupSliceToOutputMap(fieldType, ordBytes, outMap, charsRef, 
groupValue, slice);
         }
-        assert topDocs.totalHits.relation == TotalHits.Relation.EQUAL_TO;
-        DocSlice slice = new DocSlice(0, docs.length, docs, scores, 
topDocs.totalHits.value, Float.NaN);
-
-        if(fieldType instanceof StrField) {
-          final BytesRef bytesRef = ordBytes.get((int)groupValue);
-          fieldType.indexedToReadable(bytesRef, charsRef);
-          String group = charsRef.toString();
-          outMap.add(group, slice);
-        } else {
-          outMap.add(numericToString(fieldType, groupValue), slice);
+      } else {
+        int totalHits = ((TotalHitCountCollector) cursor.value).getTotalHits();
+        if (totalHits > 0) {
+          DocSlice slice = new DocSlice(0, 0, null, null, totalHits, 0);
 
 Review comment:
   Here, maxScore is always 0 even if score is requested and I think this needs 
to be documented

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to