dsmiley commented on a change in pull request #230: URL: https://github.com/apache/solr/pull/230#discussion_r679492857
########## File path: solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java ########## @@ -804,15 +806,39 @@ public BitDocSet getDocSetBits(Query q) throws IOException { } // only handle positive (non negative) queries - DocSet getPositiveDocSet(Query q) throws IOException { - DocSet answer; - if (filterCache != null) { - answer = filterCache.get(q); - if (answer != null) return answer; + DocSet getPositiveDocSet(Query query) throws IOException { + // TODO duplicated code with getDocSet? + boolean doCache = filterCache != null; + if (query instanceof ExtendedQuery) { + if (!((ExtendedQuery) query).getCache()) { + doCache = false; + } + if (query instanceof WrappedQuery) { + query = ((WrappedQuery) query).getWrappedQuery(); + } } - answer = getDocSetNC(q, null); - if (filterCache != null) filterCache.put(q, answer); - return answer; + + if (doCache) { + return getAndCacheDocSet(query); + } + + return getDocSetNC(query, null); + } + + /** + * Attempt to read the query from the filter cache, if not will compute the result and insert back into the cache + * <p>Callers must ensure that: + * <ul><li>The query is unwrapped + * <li>The query has caching enabled + * <li>The filter cache exists + * @param query the query to compute. + * @return the DocSet answer + */ + private DocSet getAndCacheDocSet(Query query) throws IOException { + assert !(query instanceof WrappedQuery) : "should have unwrapped"; + assert filterCache != null : "must check for caching before calling this method"; + + return filterCache.computeIfAbsent(query, q -> getDocSetNC(q, null)); Review comment: Sweet :-) -- 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