lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1676077 - in /lucene/dev/trunk/solr/core/src: java/org/apache/solr/search/facet/FacetRange.java test/org/apache/solr/search/facet/TestJsonFacets.java
Date Sun, 26 Apr 2015 01:14:47 GMT
Author: yonik
Date: Sun Apr 26 01:14:47 2015
New Revision: 1676077

URL: http://svn.apache.org/r1676077
Log:
SOLR-7446: refactor range faceting to use slots

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java?rev=1676077&r1=1676076&r2=1676077&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java Sun Apr
26 01:14:47 2015
@@ -23,7 +23,9 @@ import java.util.Date;
 import java.util.EnumSet;
 import java.util.List;
 
+import org.apache.lucene.index.Term;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.FacetParams;
 import org.apache.solr.common.util.SimpleOrderedMap;
@@ -31,6 +33,7 @@ import org.apache.solr.schema.FieldType;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.schema.TrieDateField;
 import org.apache.solr.schema.TrieField;
+import org.apache.solr.search.DocSet;
 import org.apache.solr.util.DateMathParser;
 
 public class FacetRange extends FacetRequest {
@@ -214,24 +217,70 @@ class FacetRangeProcessor extends FacetP
 
   private  SimpleOrderedMap getRangeCountsIndexed() throws IOException {
 
-    final SimpleOrderedMap<Object> res = new SimpleOrderedMap<>();
+    int slotCount = rangeList.size() + otherList.size();
+    intersections = new DocSet[slotCount];
+    createAccs(fcontext.base.size(), slotCount);
+    prepareForCollection();
 
-    List<SimpleOrderedMap<Object>> buckets = null;
+    for (int idx = 0; idx<rangeList.size(); idx++) {
+      rangeStats(rangeList.get(idx), idx);
+    }
+
+    for (int idx = 0; idx<otherList.size(); idx++) {
+      rangeStats(otherList.get(idx), rangeList.size() + idx);
+    }
 
-    buckets = new ArrayList<>();
+
+    final SimpleOrderedMap res = new SimpleOrderedMap<>();
+    List<SimpleOrderedMap> buckets = new ArrayList<>();
     res.add("buckets", buckets);
-    
-    for (Range range : rangeList) {
-      buckets.add( rangeStats( range, false) );
+
+    for (int idx = 0; idx<rangeList.size(); idx++) {
+      Range range = rangeList.get(idx);
+      SimpleOrderedMap bucket = new SimpleOrderedMap();
+      buckets.add(bucket);
+      bucket.add("val", range.label);
+      addStats(bucket, idx);
+      doSubs(bucket, idx);
     }
 
-    for (Range range : otherList) {
-      res.add(range.label.toString(), rangeStats( range, true));
+    for (int idx = 0; idx<otherList.size(); idx++) {
+      Range range = otherList.get(idx);
+      SimpleOrderedMap bucket = new SimpleOrderedMap();
+      res.add(range.label.toString(), bucket);
+      addStats(bucket, rangeList.size() + idx);
+      doSubs(bucket, rangeList.size() + idx);
     }
 
     return res;
   }
 
+  private DocSet[] intersections;
+  private void rangeStats(Range range, int slot) throws IOException {
+    Query rangeQ = sf.getType().getRangeQuery(null, sf, range.low == null ? null : calc.formatValue(range.low),
range.high==null ? null : calc.formatValue(range.high), range.includeLower, range.includeUpper);
+    // TODO: specialize count only
+    DocSet intersection = fcontext.searcher.getDocSet(rangeQ, fcontext.base);
+    intersections[slot] = intersection;  // save for later
+    int num = collect(intersection, slot);
+    countAcc.incrementCount(slot, num); // TODO: roll this into collect()
+  }
+
+  private void doSubs(SimpleOrderedMap bucket, int slot) throws IOException {
+    // handle sub-facets for this bucket
+    if (freq.getSubFacets().size() > 0) {
+      DocSet subBase = intersections[slot];
+      if (subBase.size() == 0) return;
+      FacetContext subContext = fcontext.sub();
+      subContext.base = subBase;
+      try {
+        fillBucketSubs(bucket, subContext);
+      } finally {
+        // subContext.base.decref();  // OFF-HEAP
+        // subContext.base = null;  // do not modify context after creation... there may
be deferred execution (i.e. streaming)
+      }
+    }
+  }
+
   private  SimpleOrderedMap<Object> rangeStats(Range range, boolean special ) throws
IOException {
     SimpleOrderedMap<Object> bucket = new SimpleOrderedMap<>();
 

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java?rev=1676077&r1=1676076&r2=1676077&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java Sun
Apr 26 01:14:47 2015
@@ -286,7 +286,6 @@ public class TestJsonFacets extends Solr
 
   @Test
   public void testStats() throws Exception {
-    // single valued strings
     doStats(Client.localClient, params());
   }
 



Mime
View raw message