madrob commented on a change in pull request #592:
URL: https://github.com/apache/solr/pull/592#discussion_r798975829
##########
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:
This complex conditional with nested assignments is fairly difficult to
read, can we expand to something less terse?
--
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]