magibney commented on a change in pull request #592:
URL: https://github.com/apache/solr/pull/592#discussion_r799196159



##########
File path: solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
##########
@@ -1384,16 +1385,24 @@ private void getDocListC(QueryResult qr, QueryCommand 
cmd) throws IOException {
     // - we don't want score returned.
 
     // check if we should try and use the filter cache
-    boolean useFilterCache = false;
-    if ((flags & (GET_SCORES | NO_CHECK_FILTERCACHE)) == 0 && 
useFilterForSortedQuery && cmd.getSort() != null
-        && filterCache != null) {
-      useFilterCache = true;
-      SortField[] sfields = cmd.getSort().getSort();
-      for (SortField sf : sfields) {
-        if (sf.getType() == SortField.Type.SCORE) {
-          useFilterCache = false;
-          break;
-        }
+    final boolean needSort;
+    final boolean useFilterCache;
+    if ((flags & (GET_SCORES | NO_CHECK_FILTERCACHE)) != 0 || filterCache == 
null) {
+      needSort = true; // this value should be irrelevant when 
`useFilterCache=false`
+      useFilterCache = false;
+    } else {
+      final Sort sort;
+      if (q instanceof  MatchAllDocsQuery // special-case MatchAllDocsQuery: 
implicit default useFilterForSortedQuery=true
+              || (useFilterForSortedQuery && q instanceof ConstantScoreQuery)) 
{ // default behavior should not risk filterCache thrashing
+        final SortField[] sortFields;
+        // We only need to sort if we're returning results AND sorting by 
something other than SCORE (sort by
+        // "score" alone is pointless for these constant score queries)
+        needSort = cmd.getLen() > 0 && (sort = cmd.getSort()) != null && 
((sortFields = sort.getSort()).length > 1 || sortFields[0].getType() != 
Type.SCORE);

Review comment:
       :+1: ... refactored this (and a couple of other) complex 1-liner 
conditionals into methods with more transparent names.




-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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

Reply via email to