You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2021/04/25 13:48:25 UTC

[lucene-solr] branch branch_8x updated: SOLR-15067: Child doc transformer should use the perSegFilter cache (#92)

This is an automated email from the ASF dual-hosted git repository.

dsmiley pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new a7ebd29  SOLR-15067: Child doc transformer should use the perSegFilter cache (#92)
a7ebd29 is described below

commit a7ebd290e39a5b4260e5659dea39fb6c85600b60
Author: bszabo97 <79...@users.noreply.github.com>
AuthorDate: Sun Apr 25 16:45:44 2021 +0300

    SOLR-15067: Child doc transformer should use the perSegFilter cache (#92)
    
    Co-authored-by: bszabo2 <bs...@cloudera.com>
---
 solr/CHANGES.txt                                        |  2 ++
 .../response/transform/ChildDocTransformerFactory.java  | 17 +++++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 83d4e9f..df34c40 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -55,6 +55,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.java
index e841a59..66a32e1 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";
 
   @Override
   public 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 docSet
     if (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);
+    }
+  }
 }