benediktarnold commented on a change in pull request #212:
URL: https://github.com/apache/solr/pull/212#discussion_r668497734



##########
File path: 
solr/core/src/java/org/apache/solr/search/SignificantTermsQParserPlugin.java
##########
@@ -89,10 +87,43 @@ public SignificantTermsQuery(String field, int numTerms, 
float minDocs, float ma
 
     @Override
     public DelegatingCollector getAnalyticsCollector(ResponseBuilder rb, 
IndexSearcher searcher) {
+      if (searcher.getIndexReader().maxDoc() <= 0) {
+        return new NoOpTermsCollector(rb);
+      }
       return new SignifcantTermsCollector(rb, searcher, field, numTerms, 
minDocs, maxDocs, minTermLength);
     }
   }
 
+  private static class NoOpTermsCollector extends DelegatingCollector {
+    private ResponseBuilder rb;
+
+    private NoOpTermsCollector(ResponseBuilder rb) {
+      this.rb = rb;
+    }
+
+    @Override
+    public void collect(int doc) throws IOException {
+    }
+
+    @Override
+    public void finish() throws IOException {
+      List<String> outTerms = new ArrayList<>();
+      List<Integer> outFreq = new ArrayList<>();
+      List<Integer> outQueryFreq = new ArrayList<>();
+      List<Double> scores = new ArrayList<>();
+
+      LinkedHashMap<String, Object> response = new LinkedHashMap<>();
+
+      rb.rsp.add("significantTerms", response);
+
+      response.put("numDocs", 0);
+      response.put("sterms", outTerms);
+      response.put("scores", scores);
+      response.put("docFreq", outFreq);
+      response.put("queryDocFreq", outQueryFreq);

Review comment:
       Unfortunately not. At least the class 
`org.apache.solr.client.solrj.io.stream.SignificantTermsStream` requires all 
attributes in the response and fails otherwise.
   That's just SolrJ. I don't know the behaviour of other clients and don't 
want to break them.




-- 
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]

Reply via email to