Apache Solr open-source search software
SOLR-15067: Child doc transformer should use the perSegFilter cache (#92)
bszabo971adedf548839
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex adb9eebaf29..d1a04f00284 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -341,6 +341,8 @@ Optimizations* SOLR-15120 Reduce duplicated core creation work (Mike Drob, Mark Miller)+* SOLR-15067 ChildDocTransformerFactory uses perSegFilter cache (Bence Szabo via David Smiley)+Bug Fixes---------------------* SOLR-15078: Fix ExpandComponent behavior when expanding on numeric fields to differentiate '0' group from null group (hossman)diff --git a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.javaindex d2a557ec144..7983fd31c59 100644--- a/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java+++ b/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java@@ -33,6 +33,7 @@ import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.schema.SchemaField;import org.apache.solr.search.DocSet;import org.apache.solr.search.QParser;+import org.apache.solr.search.SolrCache;import org.apache.solr.search.SolrReturnFields;import org.apache.solr.search.SyntaxError;@@ -64,6 +65,7 @@ public class ChildDocTransformerFactory extends TransformerFactory {private static final BooleanQuery rootFilter = new BooleanQuery.Builder().add(new BooleanClause(new MatchAllDocsQuery(), BooleanClause.Occur.MUST)).add(new BooleanClause(new DocValuesFieldExistsQuery(NEST_PATH_FIELD_NAME), BooleanClause.Occur.MUST_NOT)).build();+ public static final String CACHE_NAME="perSegFilter";@Overridepublic DocTransformer create(String field, SolrParams params, SolrQueryRequest req) {@@ -98,7 +100,7 @@ public class ChildDocTransformerFactory extends TransformerFactory {// DocSet parentDocSet = req.getSearcher().getDocSet(parentFilterQuery);// then return BitSetProducer with custom BitSet impl accessing the docSetif (parentFilterStr == null) {- parentsFilter = !buildHierarchy ? null : new QueryBitSetProducer(rootFilter);+ parentsFilter = !buildHierarchy ? null : getCachedBitSetProducer(req, rootFilter);} else {if(buildHierarchy) {throw new SolrException(ErrorCode.BAD_REQUEST, "Parent filter should not be sent when the schema is nested");@@ -107,7 +109,7 @@ public class ChildDocTransformerFactory extends TransformerFactory {if (query == null) {throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid Parent filter '" + parentFilterStr + "', resolves to null");}- parentsFilter = new QueryBitSetProducer(query);+ parentsFilter = getCachedBitSetProducer(req, query);}String childFilterStr = params.get( "childFilter" );@@ -171,5 +173,16 @@ public class ChildDocTransformerFactory extends TransformerFactory {"+" + NEST_PATH_FIELD_NAME + (isAbsolutePath? ":": ":*\\/") + path+ " +(" + remaining + ")";}++ public static BitSetProducer getCachedBitSetProducer(final SolrQueryRequest request, Query query) {+ @SuppressWarnings("unchecked")+ SolrCache<Query, BitSetProducer> parentCache = request.getSearcher().getCache(CACHE_NAME);+ // lazily retrieve from solr cache+ if (parentCache != null) {+ return parentCache.computeIfAbsent(query, QueryBitSetProducer::new);+ } else {+ return new QueryBitSetProducer(query);+ }+ }}