lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cpoersc...@apache.org
Subject [27/37] lucene-solr:jira/solr-8542-v2: SOLR-9704: optimization: use filters after blockChildren for acceptDocs
Date Mon, 31 Oct 2016 14:06:20 GMT
SOLR-9704: optimization: use filters after blockChildren for acceptDocs


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0f8802ba
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0f8802ba
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0f8802ba

Branch: refs/heads/jira/solr-8542-v2
Commit: 0f8802ba20de35daac75f6bbcc28a1789a27b06a
Parents: d8d3a8b
Author: yonik <yonik@apache.org>
Authored: Sat Oct 29 20:43:54 2016 -0400
Committer: yonik <yonik@apache.org>
Committed: Sat Oct 29 20:43:54 2016 -0400

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  5 +++
 .../solr/search/facet/FacetProcessor.java       | 34 +++++++++++++-------
 2 files changed, 27 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0f8802ba/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 50639ab..3b3fba7 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -86,6 +86,11 @@ New Features
   Example:  { type:terms, field:category, filter:"user:yonik" } 
   (yonik)
 
+Optimizations
+----------------------
+* SOLR-9704: Facet Module / JSON Facet API: Optimize blockChildren facets that have
+  filters specified by using those filters as acceptDocs. (yonik)
+
 Other Changes
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0f8802ba/solr/core/src/java/org/apache/solr/search/facet/FacetProcessor.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetProcessor.java b/solr/core/src/java/org/apache/solr/search/facet/FacetProcessor.java
index e610478..a8914f1 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/FacetProcessor.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetProcessor.java
@@ -28,7 +28,6 @@ import java.util.Map;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.Query;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.util.SimpleOrderedMap;
@@ -88,14 +87,14 @@ public abstract class FacetProcessor<FacetRequestT extends FacetRequest>
 {
   public void process() throws IOException {
     // Check filters... if we do have filters they apply after domain changes.
     // We still calculate them first because we can use it in a parent->child domain change.
-    handleFilters();
-    handleDomainChanges();
-    if (filter != null) {
+    evalFilters();
+    boolean appliedFilters = handleDomainChanges();
+    if (filter != null && !appliedFilters) {
       fcontext.base = fcontext.base.intersection( filter );
     }
   }
 
-  private void handleFilters() throws IOException {
+  private void evalFilters() throws IOException {
     if (freq.filters == null || freq.filters.isEmpty()) return;
 
     List<Query> qlist = new ArrayList<>(freq.filters.size());
@@ -120,10 +119,11 @@ public abstract class FacetProcessor<FacetRequestT extends FacetRequest>
 {
     this.filter = fcontext.searcher.getDocSet(qlist);
   }
 
-  private void handleDomainChanges() throws IOException {
-    if (freq.domain == null) return;
+  private boolean handleDomainChanges() throws IOException {
+    if (freq.domain == null) return false;
     handleFilterExclusions();
-    handleBlockJoin();
+    boolean appliedFilters = handleBlockJoin();
+    return appliedFilters;
   }
 
   private void handleFilterExclusions() throws IOException {
@@ -187,8 +187,10 @@ public abstract class FacetProcessor<FacetRequestT extends FacetRequest>
 {
     fcontext.base = fcontext.searcher.getDocSet(qlist);
   }
 
-  private void handleBlockJoin() throws IOException {
-    if (!(freq.domain.toChildren || freq.domain.toParent)) return;
+  // returns "true" if filters have already been applied.
+  private boolean handleBlockJoin() throws IOException {
+    boolean appliedFilters = false;
+    if (!(freq.domain.toChildren || freq.domain.toParent)) return appliedFilters;
 
     // TODO: avoid query parsing per-bucket somehow...
     String parentStr = freq.domain.parents;
@@ -205,13 +207,21 @@ public abstract class FacetProcessor<FacetRequestT extends FacetRequest>
 {
     DocSet result;
 
     if (freq.domain.toChildren) {
-      DocSet filt = fcontext.searcher.getDocSetBits( new MatchAllDocsQuery() );
-      result = BlockJoin.toChildren(input, parents, filt, fcontext.qcontext);
+      // If there are filters on this facet, then use them as acceptDocs when executing toChildren.
+      // We need to remember to not redundantly re-apply these filters after.
+      DocSet acceptDocs = this.filter;
+      if (acceptDocs == null) {
+        acceptDocs = fcontext.searcher.getLiveDocs();
+      } else {
+        appliedFilters = true;
+      }
+      result = BlockJoin.toChildren(input, parents, acceptDocs, fcontext.qcontext);
     } else {
       result = BlockJoin.toParents(input, parents, fcontext.qcontext);
     }
 
     fcontext.base = result;
+    return appliedFilters;
   }
 
   protected void processStats(SimpleOrderedMap<Object> bucket, DocSet docs, int docCount)
throws IOException {


Mime
View raw message