You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2013/02/08 06:15:55 UTC

svn commit: r1443839 [2/2] - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/demo/ lucene/demo/src/java/org/apache/lucene/demo/facet/adaptive/ lucene/demo/src/java/org/apache/lucene/demo/facet/multiCL/ lucene/facet/ lucene/facet/src/java/org/apach...

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java Fri Feb  8 05:15:53 2013
@@ -4,8 +4,6 @@ import java.io.IOException;
 
 import org.apache.lucene.facet.search.FacetArrays;
 import org.apache.lucene.facet.search.FacetResultsHandler;
-import org.apache.lucene.facet.search.TopKFacetResultsHandler;
-import org.apache.lucene.facet.search.TopKInEachNodeHandler;
 import org.apache.lucene.facet.search.aggregator.Aggregator;
 import org.apache.lucene.facet.taxonomy.CategoryPath;
 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
@@ -40,28 +38,67 @@ import org.apache.lucene.facet.taxonomy.
  * 
  * @lucene.experimental
  */
-public abstract class FacetRequest implements Cloneable {
+public abstract class FacetRequest {
+
+  /**
+   * Result structure manner of applying request's limits such as
+   * {@link FacetRequest#getNumLabel()} and {@link FacetRequest#numResults}.
+   * Only relevant when {@link FacetRequest#getDepth()} is > 1.
+   */
+  public enum ResultMode { 
+    /** Limits are applied per node, and the result has a full tree structure. */
+    PER_NODE_IN_TREE, 
+
+    /** Limits are applied globally, on total number of results, and the result has a flat structure. */
+    GLOBAL_FLAT
+  }
+  
+  /**
+   * Specifies which array of {@link FacetArrays} should be used to resolve
+   * values. When set to {@link #INT} or {@link #FLOAT}, allows creating an
+   * optimized {@link FacetResultsHandler}, which does not call
+   * {@link FacetRequest#getValueOf(FacetArrays, int)} for every ordinals.
+   * <p>
+   * If set to {@link #BOTH}, the {@link FacetResultsHandler} will use
+   * {@link FacetRequest#getValueOf(FacetArrays, int)} to resolve ordinal
+   * values, although it is recommended that you consider writing a specialized
+   * {@link FacetResultsHandler}.
+   */
+  public enum FacetArraysSource { INT, FLOAT, BOTH }
+
+  /** Sort options for facet results. */
+  public enum SortBy { 
+    /** sort by category ordinal with the taxonomy */
+    ORDINAL, 
+
+    /** sort by computed category value */ 
+    VALUE 
+  }
+
+  /** Requested sort order for the results. */
+  public enum SortOrder { ASCENDING, DESCENDING }
 
   /**
    * Default depth for facets accumulation.
    * @see #getDepth()
    */
   public static final int DEFAULT_DEPTH = 1;
-
+  
   /**
    * Default sort mode.
    * @see #getSortBy()
    */
   public static final SortBy DEFAULT_SORT_BY = SortBy.VALUE;
-
+  
   /**
    * Default result mode
    * @see #getResultMode()
    */
   public static final ResultMode DEFAULT_RESULT_MODE = ResultMode.PER_NODE_IN_TREE;
-
+  
   public final CategoryPath categoryPath;
-  private final int numResults;
+  public final int numResults;
+  
   private int numLabel;
   private int depth;
   private SortOrder sortOrder;
@@ -72,7 +109,7 @@ public abstract class FacetRequest imple
    * {@link CategoryPath} and <code>numResults</code>
    */
   private final int hashCode;
-  
+
   private ResultMode resultMode = DEFAULT_RESULT_MODE;
 
   /**
@@ -107,26 +144,35 @@ public abstract class FacetRequest imple
     hashCode = categoryPath.hashCode() ^ this.numResults;
   }
 
-  @Override
-  public FacetRequest clone() throws CloneNotSupportedException {
-    // Overridden to make it public
-    return (FacetRequest)super.clone();
-  }
-  
-  public void setNumLabel(int numLabel) {
-    this.numLabel = numLabel;
-  }
-
-  public void setDepth(int depth) {
-    this.depth = depth;
-  }
-
-  public void setSortOrder(SortOrder sortOrder) {
-    this.sortOrder = sortOrder;
-  }
+  /**
+   * Create an aggregator for this facet request. Aggregator action depends on
+   * request definition. For a count request, it will usually increment the
+   * count for that facet.
+   * 
+   * @param useComplements
+   *          whether the complements optimization is being used for current
+   *          computation.
+   * @param arrays
+   *          provider for facet arrays in use for current computation.
+   * @param taxonomy
+   *          reader of taxonomy in effect.
+   * @throws IOException If there is a low-level I/O error.
+   */
+  public abstract Aggregator createAggregator(boolean useComplements, FacetArrays arrays, TaxonomyReader taxonomy) 
+      throws IOException;
 
-  public void setSortBy(SortBy sortBy) {
-    this.sortBy = sortBy;
+  @Override
+  public boolean equals(Object o) {
+    if (o instanceof FacetRequest) {
+      FacetRequest that = (FacetRequest)o;
+      return that.hashCode == this.hashCode &&
+          that.categoryPath.equals(this.categoryPath) &&
+          that.numResults == this.numResults &&
+          that.depth == this.depth &&
+          that.resultMode == this.resultMode &&
+          that.numLabel == this.numLabel;
+    }
+    return false;
   }
 
   /**
@@ -134,12 +180,18 @@ public abstract class FacetRequest imple
    * only the category itself is counted. If the depth is 1, its immediate
    * children are also counted, and so on. If the depth is Integer.MAX_VALUE,
    * all the category's descendants are counted.<br>
-   * TODO (Facet): add AUTO_EXPAND option  
    */
   public final int getDepth() {
+    // TODO add AUTO_EXPAND option  
     return depth;
   }
-
+  
+  /**
+   * Returns the {@link FacetArraysSource} this {@link FacetRequest} uses in
+   * {@link #getValueOf(FacetArrays, int)}.
+   */
+  public abstract FacetArraysSource getFacetArraysSource();
+  
   /**
    * If getNumLabel() &lt; getNumResults(), only the first getNumLabel() results
    * will have their category paths calculated, and the rest will only be
@@ -167,34 +219,9 @@ public abstract class FacetRequest imple
     return numLabel;
   }
 
-  /**
-   * The number of sub-categories to return (at most). If the sub-categories are
-   * returned.
-   * <p>
-   * If Integer.MAX_VALUE is specified, all sub-categories are returned.
-   * <p>
-   * Depending on the {@link #getResultMode() LimitsMode}, this limit is applied
-   * globally or per results node. In the global mode, if this limit is 3, only
-   * 3 top results would be computed. In the per-node mode, if this limit is 3,
-   * 3 top children of {@link #categoryPath the target category} would be
-   * returned, as well as 3 top children of each of them, and so forth, until
-   * the depth defined by {@link #getDepth()}.
-   * 
-   * @see #getResultMode()
-   */
-  public final int getNumResults() {
-    return numResults;
-  }
-
-  /**
-   * Sort options for facet results.
-   */
-  public enum SortBy { 
-    /** sort by category ordinal with the taxonomy */
-    ORDINAL, 
-
-    /** sort by computed category value */ 
-    VALUE 
+  /** Return the requested result mode. */
+  public final ResultMode getResultMode() {
+    return resultMode;
   }
 
   /** Specify how should results be sorted. */
@@ -202,104 +229,11 @@ public abstract class FacetRequest imple
     return sortBy;
   }
 
-  /** Requested sort order for the results. */
-  public enum SortOrder { ASCENDING, DESCENDING }
-
   /** Return the requested order of results. */
   public final SortOrder getSortOrder() {
     return sortOrder;
   }
 
-  @Override
-  public String toString() {
-    return categoryPath.toString()+" nRes="+numResults+" nLbl="+numLabel;
-  }
-
-  /**
-   * Creates a new {@link FacetResultsHandler} that matches the request logic
-   * and current settings, such as {@link #getDepth() depth},
-   * {@link #getResultMode() limits-mode}, etc, as well as the passed in
-   * {@link TaxonomyReader}.
-   * 
-   * @param taxonomyReader taxonomy reader is needed e.g. for knowing the
-   *        taxonomy size.
-   */
-  public FacetResultsHandler createFacetResultsHandler(TaxonomyReader taxonomyReader) {
-    try {
-      if (resultMode == ResultMode.PER_NODE_IN_TREE) {
-        return new TopKInEachNodeHandler(taxonomyReader, clone());
-      } 
-      return new TopKFacetResultsHandler(taxonomyReader, clone());
-    } catch (CloneNotSupportedException e) {
-      // Shouldn't happen since we implement Cloneable. If it does happen, it is
-      // probably because the class was changed to not implement Cloneable
-      // anymore.
-      throw new RuntimeException(e);
-    }
-  }
-
-  /**
-   * Result structure manner of applying request's limits such as 
-   * {@link #getNumLabel()} and
-   * {@link #getNumResults()}.
-   */
-  public enum ResultMode { 
-    /** Limits are applied per node, and the result has a full tree structure. */
-    PER_NODE_IN_TREE, 
-
-    /** Limits are applied globally, on total number of results, and the result has a flat structure. */
-    GLOBAL_FLAT
-  }
-
-  /** Return the requested result mode. */
-  public final ResultMode getResultMode() {
-    return resultMode;
-  }
-
-  /**
-   * @param resultMode the resultMode to set
-   * @see #getResultMode()
-   */
-  public void setResultMode(ResultMode resultMode) {
-    this.resultMode = resultMode;
-  }
-
-  @Override
-  public int hashCode() {
-    return hashCode; 
-  }
-  
-  @Override
-  public boolean equals(Object o) {
-    if (o instanceof FacetRequest) {
-      FacetRequest that = (FacetRequest)o;
-      return that.hashCode == this.hashCode &&
-          that.categoryPath.equals(this.categoryPath) &&
-          that.numResults == this.numResults &&
-          that.depth == this.depth &&
-          that.resultMode == this.resultMode &&
-          that.numLabel == this.numLabel;
-    }
-    return false;
-  }
-
-  /**
-   * Create an aggregator for this facet request. Aggregator action depends on
-   * request definition. For a count request, it will usually increment the
-   * count for that facet.
-   * 
-   * @param useComplements
-   *          whether the complements optimization is being used for current
-   *          computation.
-   * @param arrays
-   *          provider for facet arrays in use for current computation.
-   * @param taxonomy
-   *          reader of taxonomy in effect.
-   * @throws IOException If there is a low-level I/O error.
-   */
-  public abstract Aggregator createAggregator(boolean useComplements, FacetArrays arrays, TaxonomyReader taxonomy) 
-      throws IOException;
-
   /**
    * Return the value of a category used for facets computations for this
    * request. For a count request this would be the count for that facet, i.e.
@@ -319,16 +253,44 @@ public abstract class FacetRequest imple
    *          <code>getValueOf</code> would be invoked with <code>idx</code>
    *          being <i>n</i> % <i>partitionSize</i>.
    */
+  // TODO perhaps instead of getValueOf we can have a postProcess(FacetArrays)
+  // That, together with getFacetArraysSource should allow ResultHandlers to
+  // efficiently obtain the values from the arrays directly
   public abstract double getValueOf(FacetArrays arrays, int idx);
+
+  @Override
+  public int hashCode() {
+    return hashCode; 
+  }
+
+  public void setDepth(int depth) {
+    this.depth = depth;
+  }
+
+  public void setNumLabel(int numLabel) {
+    this.numLabel = numLabel;
+  }
   
   /**
-   * Indicates whether this facet request is eligible for applying the complements optimization.
+   * @param resultMode the resultMode to set
+   * @see #getResultMode()
    */
-  public boolean supportsComplements() {
-    return false; // by default: no
+  public void setResultMode(ResultMode resultMode) {
+    this.resultMode = resultMode;
   }
 
-  /** Indicates whether the results of this request depends on each result document's score */
-  public abstract boolean requireDocumentScore();
+  public void setSortBy(SortBy sortBy) {
+    this.sortBy = sortBy;
+  }
+
+  public void setSortOrder(SortOrder sortOrder) {
+    this.sortOrder = sortOrder;
+  }
+  
+  @Override
+  public String toString() {
+    return categoryPath.toString()+" nRes="+numResults+" nLbl="+numLabel;
+  }
 
 }
+  
\ No newline at end of file

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java Fri Feb  8 05:15:53 2013
@@ -42,20 +42,20 @@ public class FacetSearchParams {
    * Initializes with the given {@link FacetRequest requests} and default
    * {@link FacetIndexingParams#ALL_PARENTS}. If you used a different
    * {@link FacetIndexingParams}, you should use
-   * {@link #FacetSearchParams(List, FacetIndexingParams)}.
+   * {@link #FacetSearchParams(FacetIndexingParams, List)}.
    */
   public FacetSearchParams(FacetRequest... facetRequests) {
-    this(Arrays.asList(facetRequests), FacetIndexingParams.ALL_PARENTS);
+    this(FacetIndexingParams.ALL_PARENTS, Arrays.asList(facetRequests));
   }
   
   /**
    * Initializes with the given {@link FacetRequest requests} and default
    * {@link FacetIndexingParams#ALL_PARENTS}. If you used a different
    * {@link FacetIndexingParams}, you should use
-   * {@link #FacetSearchParams(List, FacetIndexingParams)}.
+   * {@link #FacetSearchParams(FacetIndexingParams, List)}.
    */
   public FacetSearchParams(List<FacetRequest> facetRequests) {
-    this(facetRequests, FacetIndexingParams.ALL_PARENTS);
+    this(FacetIndexingParams.ALL_PARENTS, facetRequests);
   }
   
   /**
@@ -63,34 +63,35 @@ public class FacetSearchParams {
    * {@link FacetIndexingParams}.
    */
   public FacetSearchParams(FacetIndexingParams indexingParams, FacetRequest... facetRequests) {
-    this(Arrays.asList(facetRequests), indexingParams);
+    this(indexingParams, Arrays.asList(facetRequests));
   }
 
   /**
    * Initializes with the given {@link FacetRequest requests} and
    * {@link FacetIndexingParams}.
    */
-  public FacetSearchParams(List<FacetRequest> facetRequests, FacetIndexingParams indexingParams) {
+  public FacetSearchParams(FacetIndexingParams indexingParams, List<FacetRequest> facetRequests) {
     if (facetRequests == null || facetRequests.size() == 0) {
       throw new IllegalArgumentException("at least one FacetRequest must be defined");
     }
     this.facetRequests = facetRequests;
     this.indexingParams = indexingParams;
   }
-
+  
   @Override
   public String toString() {
-    final char TAB = '\t';
+    final String INDENT = "  ";
     final char NEWLINE = '\n';
 
     StringBuilder sb = new StringBuilder("IndexingParams: ");
-    sb.append(NEWLINE).append(TAB).append(indexingParams);
+    sb.append(NEWLINE).append(INDENT).append(indexingParams);
     
     sb.append(NEWLINE).append("FacetRequests:");
     for (FacetRequest facetRequest : facetRequests) {
-      sb.append(NEWLINE).append(TAB).append(facetRequest);
+      sb.append(NEWLINE).append(INDENT).append(facetRequest);
     }
     
     return sb.toString();
   }
+  
 }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationFloatSumFacetRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationFloatSumFacetRequest.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationFloatSumFacetRequest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationFloatSumFacetRequest.java Fri Feb  8 05:15:53 2013
@@ -58,13 +58,8 @@ public class AssociationFloatSumFacetReq
   }
 
   @Override
-  public boolean supportsComplements() {
-    return false;
-  }
-  
-  @Override
-  public boolean requireDocumentScore() {
-    return false;
+  public FacetArraysSource getFacetArraysSource() {
+    return FacetArraysSource.FLOAT;
   }
   
 }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationIntSumFacetRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationIntSumFacetRequest.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationIntSumFacetRequest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationIntSumFacetRequest.java Fri Feb  8 05:15:53 2013
@@ -54,18 +54,13 @@ public class AssociationIntSumFacetReque
   }
 
   @Override
-  public double getValueOf(FacetArrays arrays, int ordinal) {
-    return arrays.getIntArray()[ordinal];
+  public FacetArraysSource getFacetArraysSource() {
+    return FacetArraysSource.INT;
   }
 
   @Override
-  public boolean supportsComplements() {
-    return false;
-  }
-  
-  @Override
-  public boolean requireDocumentScore() {
-    return false;
+  public double getValueOf(FacetArrays arrays, int ordinal) {
+    return arrays.getIntArray()[ordinal];
   }
-  
+
 }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java Fri Feb  8 05:15:53 2013
@@ -46,11 +46,10 @@ public class FacetResult {
   }
   
   /**
-   * Number of descendants of {@link #getFacetResultNode() root facet result node}, 
-   * up till the requested depth, which are valid by the 
-   * {@link FacetRequest#createFacetResultsHandler(org.apache.lucene.facet.taxonomy.TaxonomyReader)
-   * results handler in effect}. Typically -- have value != 0.
-   * This number does not include the root node. 
+   * Number of descendants of {@link #getFacetResultNode() root facet result
+   * node}, up till the requested depth. Typically -- have value != 0. This
+   * number does not include the root node.
+   * 
    * @see #getFacetRequest()
    * @see FacetRequest#getDepth()
    */

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResultNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResultNode.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResultNode.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResultNode.java Fri Feb  8 05:15:53 2013
@@ -47,7 +47,7 @@ public class FacetResultNode {
    * <p>
    * <b>NOTE:</b> by default, all nodes are labeled. Only when
    * {@link FacetRequest#getNumLabel()} &lt;
-   * {@link FacetRequest#getNumResults()} there will be unlabeled nodes.
+   * {@link FacetRequest#numResults} there will be unlabeled nodes.
    */
   public CategoryPath label;
   

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java Fri Feb  8 05:15:53 2013
@@ -168,7 +168,7 @@ public abstract class Sampler {
     FacetRequest origFrq = sampledFreq.orig;
 
     FacetResultNode trimmedRootNode = facetResult.getFacetResultNode();
-    trimSubResults(trimmedRootNode, origFrq.getNumResults());
+    trimSubResults(trimmedRootNode, origFrq.numResults);
     
     return new FacetResult(origFrq, trimmedRootNode, facetResult.getNumValidDescendants());
   }
@@ -199,10 +199,10 @@ public abstract class Sampler {
     if (overSampleFactor > 1) { // any factoring to do?
       List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
       for (FacetRequest frq : original.facetRequests) {
-        int overSampledNumResults = (int) Math.ceil(frq.getNumResults() * overSampleFactor);
+        int overSampledNumResults = (int) Math.ceil(frq.numResults * overSampleFactor);
         facetRequests.add(new OverSampledFacetRequest(frq, overSampledNumResults));
       }
-      res = new FacetSearchParams(facetRequests, original.indexingParams);
+      res = new FacetSearchParams(original.indexingParams, facetRequests);
     }
     return res;
   }
@@ -233,18 +233,13 @@ public abstract class Sampler {
     }
 
     @Override
-    public double getValueOf(FacetArrays arrays, int idx) {
-      return orig.getValueOf(arrays, idx);
-    }
-    
-    @Override
-    public boolean requireDocumentScore() {
-      return orig.requireDocumentScore();
+    public FacetArraysSource getFacetArraysSource() {
+      return orig.getFacetArraysSource();
     }
-    
+
     @Override
-    public boolean supportsComplements() {
-      return orig.supportsComplements();
+    public double getValueOf(FacetArrays arrays, int idx) {
+      return orig.getValueOf(arrays, idx);
     }
   }
 

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java Fri Feb  8 05:15:53 2013
@@ -4,8 +4,8 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.lucene.facet.partitions.search.PartitionsFacetResultsHandler;
 import org.apache.lucene.facet.search.FacetArrays;
-import org.apache.lucene.facet.search.FacetResultsHandler;
 import org.apache.lucene.facet.search.FacetsAccumulator;
 import org.apache.lucene.facet.search.SamplingWrapper;
 import org.apache.lucene.facet.search.ScoredDocIDs;
@@ -42,7 +42,8 @@ import org.apache.lucene.index.IndexRead
  * directly extends {@link StandardFacetsAccumulator}.</li>
  * <li>This class can effectively apply sampling on the complement set of
  * matching document, thereby working efficiently with the complement
- * optimization - see {@link FacetsAccumulator#getComplementThreshold()}.</li>
+ * optimization - see {@link StandardFacetsAccumulator#getComplementThreshold()}
+ * .</li>
  * </ol>
  * <p>
  * Note: Sampling accumulation (Accumulation over a sampled-set of the results),
@@ -77,36 +78,26 @@ public class SamplingAccumulator extends
 
   @Override
   public List<FacetResult> accumulate(ScoredDocIDs docids) throws IOException {
-    // first let delegee accumulate without labeling at all (though
-    // currently it doesn't matter because we have to label all returned anyhow)
-    boolean origAllowLabeling = isAllowLabeling();
-    setAllowLabeling(false);
-    
     // Replacing the original searchParams with the over-sampled
     FacetSearchParams original = searchParams;
     searchParams = sampler.overSampledSearchParams(original);
     
     List<FacetResult> sampleRes = super.accumulate(docids);
-    setAllowLabeling(origAllowLabeling);
     
     List<FacetResult> fixedRes = new ArrayList<FacetResult>();
     for (FacetResult fres : sampleRes) {
       // for sure fres is not null because this is guaranteed by the delegee.
-      FacetResultsHandler frh = fres.getFacetRequest().createFacetResultsHandler(
-          taxonomyReader);
+      PartitionsFacetResultsHandler frh = createFacetResultsHandler(fres.getFacetRequest());
       // fix the result of current request
-      sampler.getSampleFixer(indexReader, taxonomyReader, searchParams)
-          .fixResult(docids, fres);
+      sampler.getSampleFixer(indexReader, taxonomyReader, searchParams).fixResult(docids, fres);
       
-      fres = frh.rearrangeFacetResult(fres); // let delegee's handler do any
+      fres = frh.rearrangeFacetResult(fres); // let delegee's handler do any arranging it needs to
 
       // Using the sampler to trim the extra (over-sampled) results
       fres = sampler.trimResult(fres);
-                                              // arranging it needs to
+
       // final labeling if allowed (because labeling is a costly operation)
-      if (isAllowLabeling()) {
-        frh.labelResult(fres);
-      }
+      frh.labelResult(fres);
       fixedRes.add(fres); // add to final results
     }
     

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.java Fri Feb  8 05:15:53 2013
@@ -41,7 +41,7 @@ public class ResultSortUtils {
    * @throws IllegalArgumentException is provided facet request is not supported 
    */
   public static Heap<FacetResultNode> createSuitableHeap(FacetRequest facetRequest) {
-    int nresults = facetRequest.getNumResults();
+    int nresults = facetRequest.numResults;
     boolean accending = (facetRequest.getSortOrder() == SortOrder.ASCENDING);
 
     if (nresults == Integer.MAX_VALUE) {

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/util/TaxonomyMergeUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/util/TaxonomyMergeUtils.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/util/TaxonomyMergeUtils.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/util/TaxonomyMergeUtils.java Fri Feb  8 05:15:53 2013
@@ -6,17 +6,13 @@ import java.util.List;
 import org.apache.lucene.facet.index.OrdinalMappingAtomicReader;
 import org.apache.lucene.facet.index.params.FacetIndexingParams;
 import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
-import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.DiskOrdinalMap;
-import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.MemoryOrdinalMap;
 import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.OrdinalMap;
 import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.MultiReader;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.Version;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -42,40 +38,6 @@ import org.apache.lucene.util.Version;
 public class TaxonomyMergeUtils {
 
   /**
-   * Merges the given taxonomy and index directories. Note that this method
-   * opens {@link DirectoryTaxonomyWriter} and {@link IndexWriter} on the
-   * respective destination indexes. Therefore if you have a writer open on any
-   * of them, it should be closed, or you should use
-   * {@link #merge(Directory, Directory, IndexWriter, DirectoryTaxonomyWriter, FacetIndexingParams)}
-   * instead.
-   * 
-   * @see #merge(Directory, Directory, IndexWriter, DirectoryTaxonomyWriter, FacetIndexingParams)
-   */
-  public static void merge(Directory srcIndexDir, Directory srcTaxDir, Directory destIndexDir, Directory destTaxDir, 
-      FacetIndexingParams params) throws IOException {
-    IndexWriter destIndexWriter = new IndexWriter(destIndexDir, new IndexWriterConfig(Version.LUCENE_42, null));
-    DirectoryTaxonomyWriter destTaxWriter = new DirectoryTaxonomyWriter(destTaxDir);
-    merge(srcIndexDir, srcTaxDir, new MemoryOrdinalMap(), destIndexWriter, destTaxWriter, params);
-    destTaxWriter.close();
-    destIndexWriter.close();
-  }
-
-  /**
-   * Merges the given taxonomy and index directories and commits the changes to
-   * the given writers. This method uses {@link MemoryOrdinalMap} to store the
-   * mapped ordinals. If you cannot afford the memory, you can use
-   * {@link #merge(Directory, Directory, DirectoryTaxonomyWriter.OrdinalMap, IndexWriter, DirectoryTaxonomyWriter, FacetIndexingParams)}
-   * by passing {@link DiskOrdinalMap}.
-   * 
-   * @see #merge(Directory, Directory, DirectoryTaxonomyWriter.OrdinalMap,
-   *      IndexWriter, DirectoryTaxonomyWriter, FacetIndexingParams)
-   */
-  public static void merge(Directory srcIndexDir, Directory srcTaxDir, IndexWriter destIndexWriter, 
-      DirectoryTaxonomyWriter destTaxWriter, FacetIndexingParams params) throws IOException {
-    merge(srcIndexDir, srcTaxDir, new MemoryOrdinalMap(), destIndexWriter, destTaxWriter, params);
-  }
-  
-  /**
    * Merges the given taxonomy and index directories and commits the changes to
    * the given writers.
    */

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java Fri Feb  8 05:15:53 2013
@@ -234,7 +234,7 @@ public abstract class FacetTestBase exte
    * test with different faceted search params.
    */
   protected FacetSearchParams getFacetSearchParams(List<FacetRequest> facetRequests, FacetIndexingParams iParams) {
-    return new FacetSearchParams(facetRequests, iParams);
+    return new FacetSearchParams(iParams, facetRequests);
   }
 
   /**
@@ -329,7 +329,7 @@ public abstract class FacetTestBase exte
       if (VERBOSE) {
         System.out.println(freq.categoryPath.toString()+ "\t\t" + topResNode);
       }
-      assertCountsAndCardinality(facetCountsTruth, topResNode, freq.getNumResults());
+      assertCountsAndCardinality(facetCountsTruth, topResNode, freq.numResults);
     }
   }
     

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/OrdinalMappingReaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/OrdinalMappingReaderTest.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/OrdinalMappingReaderTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/OrdinalMappingReaderTest.java Fri Feb  8 05:15:53 2013
@@ -17,13 +17,16 @@ import org.apache.lucene.facet.search.re
 import org.apache.lucene.facet.taxonomy.CategoryPath;
 import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
 import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
+import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.MemoryOrdinalMap;
 import org.apache.lucene.facet.util.TaxonomyMergeUtils;
 import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.IOUtils;
 import org.junit.Test;
 
 /*
@@ -58,7 +61,13 @@ public class OrdinalMappingReaderTest ex
     Directory taxDir1 = newDirectory();
     buildIndexWithFacets(dir1, taxDir1, false, fip);
     
-    TaxonomyMergeUtils.merge(dir, taxDir, dir1, taxDir1, fip);
+    IndexWriter destIndexWriter = new IndexWriter(dir1, new IndexWriterConfig(TEST_VERSION_CURRENT, null));
+    DirectoryTaxonomyWriter destTaxWriter = new DirectoryTaxonomyWriter(taxDir1);
+    try {
+      TaxonomyMergeUtils.merge(dir, taxDir, new MemoryOrdinalMap(), destIndexWriter, destTaxWriter, fip);
+    } finally {
+      IOUtils.close(destIndexWriter, destTaxWriter);
+    }
     
     verifyResults(dir1, taxDir1, fip);
     dir1.close();

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/TestFacetsPayloadMigrationReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/TestFacetsPayloadMigrationReader.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/TestFacetsPayloadMigrationReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/index/TestFacetsPayloadMigrationReader.java Fri Feb  8 05:15:53 2013
@@ -269,7 +269,7 @@ public class TestFacetsPayloadMigrationR
     for (String dim : expectedCounts.keySet()) {
       requests.add(new CountFacetRequest(new CategoryPath(dim), 5));
     }
-    FacetSearchParams fsp = new FacetSearchParams(requests, fip);
+    FacetSearchParams fsp = new FacetSearchParams(fip, requests);
     FacetsCollector fc = FacetsCollector.create(fsp, indexReader, taxoReader);
     MatchAllDocsQuery base = new MatchAllDocsQuery();
     searcher.search(base, fc);

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/AdaptiveAccumulatorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/AdaptiveAccumulatorTest.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/AdaptiveAccumulatorTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/AdaptiveAccumulatorTest.java Fri Feb  8 05:15:53 2013
@@ -29,7 +29,7 @@ import org.apache.lucene.facet.taxonomy.
 public class AdaptiveAccumulatorTest extends BaseSampleTestTopK {
 
   @Override
-  protected FacetsAccumulator getSamplingAccumulator(Sampler sampler, TaxonomyReader taxoReader, 
+  protected StandardFacetsAccumulator getSamplingAccumulator(Sampler sampler, TaxonomyReader taxoReader, 
       IndexReader indexReader, FacetSearchParams searchParams) {
     AdaptiveFacetsAccumulator res = new AdaptiveFacetsAccumulator(searchParams, indexReader, taxoReader);
     res.setSampler(sampler);

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/SamplingWrapperTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/SamplingWrapperTest.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/SamplingWrapperTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/SamplingWrapperTest.java Fri Feb  8 05:15:53 2013
@@ -29,10 +29,9 @@ import org.apache.lucene.facet.taxonomy.
 public class SamplingWrapperTest extends BaseSampleTestTopK {
 
   @Override
-  protected FacetsAccumulator getSamplingAccumulator(Sampler sampler, TaxonomyReader taxoReader, 
+  protected StandardFacetsAccumulator getSamplingAccumulator(Sampler sampler, TaxonomyReader taxoReader, 
       IndexReader indexReader, FacetSearchParams searchParams) {
-    FacetsAccumulator fa = new StandardFacetsAccumulator(searchParams, indexReader, taxoReader);
-    return new SamplingWrapper(fa, sampler);
+    return new SamplingWrapper(new StandardFacetsAccumulator(searchParams, indexReader, taxoReader), sampler);
   }
   
 }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsAccumulatorWithComplement.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsAccumulatorWithComplement.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsAccumulatorWithComplement.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsAccumulatorWithComplement.java Fri Feb  8 05:15:53 2013
@@ -3,28 +3,22 @@ package org.apache.lucene.facet.search;
 import java.io.IOException;
 import java.util.List;
 
+import org.apache.lucene.facet.FacetTestBase;
+import org.apache.lucene.facet.index.params.FacetIndexingParams;
+import org.apache.lucene.facet.search.params.CountFacetRequest;
+import org.apache.lucene.facet.search.params.FacetSearchParams;
+import org.apache.lucene.facet.search.results.FacetResult;
+import org.apache.lucene.facet.search.results.FacetResultNode;
+import org.apache.lucene.facet.taxonomy.CategoryPath;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.MultiReader;
 import org.apache.lucene.index.ParallelAtomicReader;
 import org.apache.lucene.index.SlowCompositeReaderWrapper;
 import org.apache.lucene.search.MatchAllDocsQuery;
-import org.apache.lucene.search.Query;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import org.apache.lucene.facet.FacetTestBase;
-import org.apache.lucene.facet.index.params.FacetIndexingParams;
-import org.apache.lucene.facet.search.FacetsAccumulator;
-import org.apache.lucene.facet.search.ScoredDocIDs;
-import org.apache.lucene.facet.search.ScoredDocIdCollector;
-import org.apache.lucene.facet.search.StandardFacetsAccumulator;
-import org.apache.lucene.facet.search.params.CountFacetRequest;
-import org.apache.lucene.facet.search.params.FacetSearchParams;
-import org.apache.lucene.facet.search.results.FacetResult;
-import org.apache.lucene.facet.search.results.FacetResultNode;
-import org.apache.lucene.facet.taxonomy.CategoryPath;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -104,17 +98,9 @@ public class TestFacetsAccumulatorWithCo
   }
   
   private void doTestComplements() throws Exception {
-    Query q = new MatchAllDocsQuery(); //new TermQuery(new Term(TEXT,"white"));
-    if (VERBOSE) {
-      System.out.println("Query: "+q);
-    }
-    ScoredDocIdCollector dCollector = 
-      ScoredDocIdCollector.create(indexReader.maxDoc(),false); // scoring is disabled
-    searcher.search(q, dCollector);
-    
     // verify by facet values
-    List<FacetResult> countResWithComplement = findFacets(dCollector.getScoredDocIDs(), true);
-    List<FacetResult> countResNoComplement = findFacets(dCollector.getScoredDocIDs(), false);
+    List<FacetResult> countResWithComplement = findFacets(true);
+    List<FacetResult> countResNoComplement = findFacets(false);
     
     assertEquals("Wrong number of facet count results with complement!",1,countResWithComplement.size());
     assertEquals("Wrong number of facet count results no complement!",1,countResNoComplement.size());
@@ -124,20 +110,17 @@ public class TestFacetsAccumulatorWithCo
     
     assertEquals("Wrong number of top count aggregated categories with complement!",3,parentResWithComp.subResults.size());
     assertEquals("Wrong number of top count aggregated categories no complement!",3,parentResNoComp.subResults.size());
-    
   }
   
   /** compute facets with certain facet requests and docs */
-  private List<FacetResult> findFacets(ScoredDocIDs sDocids, boolean withComplement) throws IOException {
+  private List<FacetResult> findFacets(boolean withComplement) throws IOException {
     FacetSearchParams fsp = new FacetSearchParams(fip, new CountFacetRequest(new CategoryPath("root","a"), 10));
-    FacetsAccumulator fAccumulator = new StandardFacetsAccumulator(fsp, indexReader, taxoReader);
-    
-    fAccumulator.setComplementThreshold(
-        withComplement ? 
-            FacetsAccumulator.FORCE_COMPLEMENT: 
-              FacetsAccumulator.DISABLE_COMPLEMENT);
+    StandardFacetsAccumulator sfa = new StandardFacetsAccumulator(fsp, indexReader, taxoReader);
+    sfa.setComplementThreshold(withComplement ? StandardFacetsAccumulator.FORCE_COMPLEMENT : StandardFacetsAccumulator.DISABLE_COMPLEMENT);
+    FacetsCollector fc = FacetsCollector.create(sfa);
+    searcher.search(new MatchAllDocsQuery(), fc);
     
-    List<FacetResult> res = fAccumulator.accumulate(sDocids);
+    List<FacetResult> res = fc.getFacetResults();
     
     // Results are ready, printing them...
     int i = 0;
@@ -147,7 +130,7 @@ public class TestFacetsAccumulatorWithCo
       }
     }
     
-    assertEquals(withComplement, ((StandardFacetsAccumulator) fAccumulator).isUsingComplements);
+    assertEquals(withComplement, sfa.isUsingComplements);
     
     return res;
   }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsCollector.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsCollector.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestFacetsCollector.java Fri Feb  8 05:15:53 2013
@@ -1,7 +1,11 @@
 package org.apache.lucene.facet.search;
 
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
@@ -9,8 +13,13 @@ import org.apache.lucene.document.Field.
 import org.apache.lucene.document.StringField;
 import org.apache.lucene.facet.FacetTestCase;
 import org.apache.lucene.facet.index.FacetFields;
+import org.apache.lucene.facet.index.params.CategoryListParams;
+import org.apache.lucene.facet.index.params.FacetIndexingParams;
+import org.apache.lucene.facet.index.params.PerDimensionIndexingParams;
+import org.apache.lucene.facet.search.FacetsCollector.MatchingDocs;
+import org.apache.lucene.facet.search.params.CountFacetRequest;
 import org.apache.lucene.facet.search.params.FacetSearchParams;
-import org.apache.lucene.facet.search.params.ScoreFacetRequest;
+import org.apache.lucene.facet.search.params.SumScoreFacetRequest;
 import org.apache.lucene.facet.search.results.FacetResult;
 import org.apache.lucene.facet.taxonomy.CategoryPath;
 import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
@@ -18,7 +27,6 @@ import org.apache.lucene.facet.taxonomy.
 import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.MultiCollector;
@@ -47,16 +55,15 @@ import org.junit.Test;
 public class TestFacetsCollector extends FacetTestCase {
 
   @Test
-  public void testFacetsWithDocScore() throws Exception {
+  public void testSumScoreAggregator() throws Exception {
     Directory indexDir = newDirectory();
     Directory taxoDir = newDirectory();
 
     TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
-    IndexWriter iw = new IndexWriter(indexDir, new IndexWriterConfig(
-        TEST_VERSION_CURRENT, new MockAnalyzer(random())));
+    IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
 
     FacetFields facetFields = new FacetFields(taxonomyWriter);
-    for(int i = atLeast(2000); i > 0; --i) {
+    for(int i = atLeast(30); i > 0; --i) {
       Document doc = new Document();
       doc.add(new StringField("f", "v", Store.NO));
       facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a")));
@@ -66,12 +73,17 @@ public class TestFacetsCollector extends
     taxonomyWriter.close();
     iw.close();
     
-    FacetSearchParams sParams = new FacetSearchParams(new ScoreFacetRequest(new CategoryPath("a"), 10));
-    
     DirectoryReader r = DirectoryReader.open(indexDir);
     DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
     
-    FacetsCollector fc = FacetsCollector.create(sParams, r, taxo);
+    FacetSearchParams sParams = new FacetSearchParams(new SumScoreFacetRequest(new CategoryPath("a"), 10));
+    FacetsAccumulator fa = new FacetsAccumulator(sParams, r, taxo) {
+      @Override
+      public FacetsAggregator getAggregator() {
+        return new SumScoreFacetsAggregator();
+      }
+    };
+    FacetsCollector fc = FacetsCollector.create(fa);
     TopScoreDocCollector topDocs = TopScoreDocCollector.create(10, false);
     new IndexSearcher(r).search(new MatchAllDocsQuery(), MultiCollector.wrap(fc, topDocs));
     
@@ -83,4 +95,119 @@ public class TestFacetsCollector extends
     IOUtils.close(taxo, taxoDir, r, indexDir);
   }
   
+  @Test
+  public void testMultiCountingLists() throws Exception {
+    Directory indexDir = newDirectory();
+    Directory taxoDir = newDirectory();
+    
+    TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
+    IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
+    FacetIndexingParams fip = new PerDimensionIndexingParams(Collections.singletonMap(new CategoryPath("b"), new CategoryListParams("$b")));
+    
+    FacetFields facetFields = new FacetFields(taxonomyWriter, fip);
+    for(int i = atLeast(30); i > 0; --i) {
+      Document doc = new Document();
+      doc.add(new StringField("f", "v", Store.NO));
+      List<CategoryPath> cats = new ArrayList<CategoryPath>();
+      cats.add(new CategoryPath("a"));
+      cats.add(new CategoryPath("b"));
+      facetFields.addFields(doc, cats);
+      iw.addDocument(doc);
+    }
+    
+    taxonomyWriter.close();
+    iw.close();
+    
+    DirectoryReader r = DirectoryReader.open(indexDir);
+    DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
+    
+    FacetSearchParams sParams = new FacetSearchParams(fip,
+        new CountFacetRequest(new CategoryPath("a"), 10), 
+        new CountFacetRequest(new CategoryPath("b"), 10));
+    FacetsCollector fc = FacetsCollector.create(sParams, r, taxo);
+    new IndexSearcher(r).search(new MatchAllDocsQuery(), fc);
+    
+    for (FacetResult res : fc.getFacetResults()) {
+      assertEquals("unexpected count for " + res, r.maxDoc(), (int) res.getFacetResultNode().value);
+    }
+    
+    IOUtils.close(taxo, taxoDir, r, indexDir);
+  }
+  
+  @Test
+  public void testCountAndSumScore() throws Exception {
+    Directory indexDir = newDirectory();
+    Directory taxoDir = newDirectory();
+    
+    TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
+    IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
+    FacetIndexingParams fip = new PerDimensionIndexingParams(Collections.singletonMap(new CategoryPath("b"), new CategoryListParams("$b")));
+    
+    FacetFields facetFields = new FacetFields(taxonomyWriter, fip);
+    for(int i = atLeast(30); i > 0; --i) {
+      Document doc = new Document();
+      doc.add(new StringField("f", "v", Store.NO));
+      List<CategoryPath> cats = new ArrayList<CategoryPath>();
+      cats.add(new CategoryPath("a"));
+      cats.add(new CategoryPath("b"));
+      facetFields.addFields(doc, cats);
+      iw.addDocument(doc);
+    }
+    
+    taxonomyWriter.close();
+    iw.close();
+    
+    DirectoryReader r = DirectoryReader.open(indexDir);
+    DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
+    
+    FacetSearchParams sParams = new FacetSearchParams(fip,
+        new CountFacetRequest(new CategoryPath("a"), 10), 
+        new SumScoreFacetRequest(new CategoryPath("b"), 10));
+    
+    final Map<CategoryListParams,FacetsAggregator> clpAggregator = new HashMap<CategoryListParams,FacetsAggregator>();
+    clpAggregator.put(fip.getCategoryListParams(new CategoryPath("a")), new FastCountingFacetsAggregator());
+    clpAggregator.put(fip.getCategoryListParams(new CategoryPath("b")), new SumScoreFacetsAggregator());
+    FacetsAccumulator fa = new FacetsAccumulator(sParams, r, taxo) {
+      @Override
+      public FacetsAggregator getAggregator() {
+        return new FacetsAggregator() {
+          
+          @Override
+          public void rollupValues(int ordinal, int[] children, int[] siblings, FacetArrays facetArrays) {
+            throw new UnsupportedOperationException("not supported yet");
+          }
+          
+          @Override
+          public boolean requiresDocScores() {
+            for (FacetsAggregator aggregator : clpAggregator.values()) {
+              if (aggregator.requiresDocScores()) {
+                return true;
+              }
+            }
+            return false;
+          }
+          
+          @Override
+          public void aggregate(MatchingDocs matchingDocs, CategoryListParams clp, FacetArrays facetArrays) throws IOException {
+            clpAggregator.get(clp).aggregate(matchingDocs, clp, facetArrays);
+          }
+        };
+      }
+    };
+    
+    FacetsCollector fc = FacetsCollector.create(fa);
+    TopScoreDocCollector topDocs = TopScoreDocCollector.create(10, false);
+    new IndexSearcher(r).search(new MatchAllDocsQuery(), MultiCollector.wrap(fc, topDocs));
+    
+    List<FacetResult> facetResults = fc.getFacetResults();
+    FacetResult fresA = facetResults.get(0);
+    assertEquals("unexpected count for " + fresA, r.maxDoc(), (int) fresA.getFacetResultNode().value);
+    
+    FacetResult fresB = facetResults.get(1);
+    double expected = topDocs.topDocs().getMaxScore() * r.numDocs();
+    assertEquals("unexpected value for " + fresB, expected, fresB.getFacetResultNode().value, 1E-10);
+    
+    IOUtils.close(taxo, taxoDir, r, indexDir);
+  }
+
 }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java Fri Feb  8 05:15:53 2013
@@ -332,7 +332,7 @@ public class TestMultipleCategoryLists e
     facetRequests.add(new CountFacetRequest(new CategoryPath("Band", "Rock & Pop"), 10));
 
     // Faceted search parameters indicate which facets are we interested in
-    FacetSearchParams facetSearchParams = new FacetSearchParams(facetRequests, iParams);
+    FacetSearchParams facetSearchParams = new FacetSearchParams(iParams, facetRequests);
 
     // perform documents search and facets accumulation
     FacetsCollector facetsCollector = FacetsCollector.create(facetSearchParams, ir, tr);

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestStandardFacetsAccumulator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestStandardFacetsAccumulator.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestStandardFacetsAccumulator.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestStandardFacetsAccumulator.java Fri Feb  8 05:15:53 2013
@@ -101,14 +101,9 @@ public class TestStandardFacetsAccumulat
     
     // search for "f:a", only segments 1 and 3 should match results
     Query q = new TermQuery(new Term("f", "a"));
-    FacetRequest countNoComplements = new CountFacetRequest(new CategoryPath("A"), 10) {
-      @Override
-      public boolean supportsComplements() {
-        return false; // disable complements
-      }
-    };
+    FacetRequest countNoComplements = new CountFacetRequest(new CategoryPath("A"), 10);
     FacetSearchParams fsp = new FacetSearchParams(fip, countNoComplements);
-    FacetsCollector fc = new StandardFacetsCollector(fsp , indexReader, taxoReader);
+    FacetsCollector fc = FacetsCollector.create(fsp , indexReader, taxoReader);
     indexSearcher.search(q, fc);
     List<FacetResult> results = fc.getFacetResults();
     assertEquals("received too many facet results", 1, results.size());

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java Fri Feb  8 05:15:53 2013
@@ -109,48 +109,36 @@ public class TestTopKInEachNodeResultHan
       // Get all of the documents and run the query, then do different
       // facet counts and compare to control
       Query q = new TermQuery(new Term("content", "alpha"));
-      ScoredDocIdCollector scoredDoc = ScoredDocIdCollector.create(ir.maxDoc(), true);
 
-      // Collector collector = new MultiCollector(scoredDoc);
-      is.search(q, scoredDoc);
-
-      CountFacetRequest cfra23 = new CountFacetRequest(
-          new CategoryPath("a"), 2);
+      CountFacetRequest cfra23 = new CountFacetRequest(new CategoryPath("a"), 2);
       cfra23.setDepth(3);
       cfra23.setResultMode(ResultMode.PER_NODE_IN_TREE);
 
-      CountFacetRequest cfra22 = new CountFacetRequest(
-          new CategoryPath("a"), 2);
+      CountFacetRequest cfra22 = new CountFacetRequest(new CategoryPath("a"), 2);
       cfra22.setDepth(2);
       cfra22.setResultMode(ResultMode.PER_NODE_IN_TREE);
 
-      CountFacetRequest cfra21 = new CountFacetRequest(
-          new CategoryPath("a"), 2);
+      CountFacetRequest cfra21 = new CountFacetRequest(new CategoryPath("a"), 2);
       cfra21.setDepth(1);
       cfra21.setResultMode(ResultMode.PER_NODE_IN_TREE);
 
-      CountFacetRequest cfrb22 = new CountFacetRequest(
-          new CategoryPath("a", "b"), 2);
+      CountFacetRequest cfrb22 = new CountFacetRequest(new CategoryPath("a", "b"), 2);
       cfrb22.setDepth(2);
       cfrb22.setResultMode(ResultMode.PER_NODE_IN_TREE);
 
-      CountFacetRequest cfrb23 = new CountFacetRequest(
-          new CategoryPath("a", "b"), 2);
+      CountFacetRequest cfrb23 = new CountFacetRequest(new CategoryPath("a", "b"), 2);
       cfrb23.setDepth(3);
       cfrb23.setResultMode(ResultMode.PER_NODE_IN_TREE);
 
-      CountFacetRequest cfrb21 = new CountFacetRequest(
-          new CategoryPath("a", "b"), 2);
+      CountFacetRequest cfrb21 = new CountFacetRequest(new CategoryPath("a", "b"), 2);
       cfrb21.setDepth(1);
       cfrb21.setResultMode(ResultMode.PER_NODE_IN_TREE);
 
-      CountFacetRequest doctor = new CountFacetRequest(
-          new CategoryPath("Doctor"), 2);
+      CountFacetRequest doctor = new CountFacetRequest(new CategoryPath("Doctor"), 2);
       doctor.setDepth(1);
       doctor.setResultMode(ResultMode.PER_NODE_IN_TREE);
 
-      CountFacetRequest cfrb20 = new CountFacetRequest(
-          new CategoryPath("a", "b"), 2);
+      CountFacetRequest cfrb20 = new CountFacetRequest(new CategoryPath("a", "b"), 2);
       cfrb20.setDepth(0);
       cfrb20.setResultMode(ResultMode.PER_NODE_IN_TREE);
 
@@ -163,20 +151,16 @@ public class TestTopKInEachNodeResultHan
       facetRequests.add(cfrb21);
       facetRequests.add(doctor);
       facetRequests.add(cfrb20);
-      FacetSearchParams facetSearchParams = new FacetSearchParams(facetRequests, iParams);
+      FacetSearchParams facetSearchParams = new FacetSearchParams(iParams, facetRequests);
       
       FacetArrays facetArrays = new FacetArrays(PartitionsUtils.partitionSize(facetSearchParams.indexingParams, tr));
-      FacetsAccumulator fctExtrctr = new StandardFacetsAccumulator(facetSearchParams, is.getIndexReader(), tr, facetArrays);
-      fctExtrctr.setComplementThreshold(FacetsAccumulator.DISABLE_COMPLEMENT);
-      long start = System.currentTimeMillis();
-
-      List<FacetResult> facetResults = fctExtrctr.accumulate(scoredDoc.getScoredDocIDs());
-
-      long end = System.currentTimeMillis();
-      if (VERBOSE) {
-        System.out.println("Time: " + (end - start));
-      }
+      StandardFacetsAccumulator sfa = new StandardFacetsAccumulator(facetSearchParams, is.getIndexReader(), tr, facetArrays);
+      sfa.setComplementThreshold(StandardFacetsAccumulator.DISABLE_COMPLEMENT);
+      FacetsCollector fc = FacetsCollector.create(sfa);
       
+      is.search(q, fc);
+      List<FacetResult> facetResults = fc.getFacetResults();
+
       FacetResult fr = facetResults.get(0); // a, depth=3, K=2
       boolean hasDoctor = "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
       assertEquals(9, fr.getNumValidDescendants());
@@ -203,7 +187,7 @@ public class TestTopKInEachNodeResultHan
       }
       // now rearrange
       double [] expectedValues00 = { 6.0, 1.0, 5.0, 3.0, 2.0 };
-      fr = cfra23.createFacetResultsHandler(tr).rearrangeFacetResult(fr);
+      fr = sfa.createFacetResultsHandler(cfra23).rearrangeFacetResult(fr);
       i = 0;
       for (FacetResultNode node : parentRes.subResults) {
         assertEquals(expectedValues00[i++], node.value, Double.MIN_VALUE);

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandler.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandler.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandler.java Fri Feb  8 05:15:53 2013
@@ -13,8 +13,6 @@ import org.apache.lucene.facet.search.pa
 import org.apache.lucene.facet.search.results.FacetResult;
 import org.apache.lucene.facet.search.results.FacetResultNode;
 import org.apache.lucene.facet.taxonomy.CategoryPath;
-import org.apache.lucene.facet.taxonomy.TaxonomyReader;
-import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.junit.Test;
 
@@ -92,15 +90,7 @@ public class TestTopKResultsHandler exte
       
       // do different facet counts and compare to control
       FacetSearchParams sParams = getFacetSearchParams(facetRequests, fip);
-      
-      FacetsCollector fc = new StandardFacetsCollector(sParams, indexReader, taxoReader) {
-        @Override
-        protected FacetsAccumulator initFacetsAccumulator(FacetSearchParams facetSearchParams, IndexReader indexReader, TaxonomyReader taxonomyReader) {
-          FacetsAccumulator fa = new StandardFacetsAccumulator(facetSearchParams, indexReader, taxonomyReader);
-          fa.setComplementThreshold(FacetsAccumulator.DISABLE_COMPLEMENT);
-          return fa;
-        }
-      };
+      FacetsCollector fc = FacetsCollector.create(sParams, indexReader, taxoReader);
       
       searcher.search(new MatchAllDocsQuery(), fc);
       List<FacetResult> facetResults = fc.getFacetResults();
@@ -169,15 +159,7 @@ public class TestTopKResultsHandler exte
       // do different facet counts and compare to control
       CategoryPath path = new CategoryPath("a", "b");
       FacetSearchParams sParams = getFacetSearchParams(fip, new CountFacetRequest(path, Integer.MAX_VALUE));
-
-      FacetsCollector fc = new StandardFacetsCollector(sParams, indexReader, taxoReader) {
-        @Override
-        protected FacetsAccumulator initFacetsAccumulator(FacetSearchParams facetSearchParams, IndexReader indexReader, TaxonomyReader taxonomyReader) {
-          FacetsAccumulator fa = new StandardFacetsAccumulator(facetSearchParams, indexReader, taxonomyReader);
-          fa.setComplementThreshold(FacetsAccumulator.DISABLE_COMPLEMENT);
-          return fa;
-        }
-      };
+      FacetsCollector fc = FacetsCollector.create(sParams, indexReader, taxoReader);
       
       searcher.search(new MatchAllDocsQuery(), fc);
       List<FacetResult> results = fc.getFacetResults();
@@ -187,17 +169,8 @@ public class TestTopKResultsHandler exte
       assertEquals(path + " should only have 4 desendants", 4, res.getNumValidDescendants());
 
       // As a control base results, ask for top-1000 results
-      FacetSearchParams sParams2 = getFacetSearchParams(
-          fip, new CountFacetRequest(path, Integer.MAX_VALUE));
-
-      FacetsCollector fc2 = new StandardFacetsCollector(sParams2, indexReader, taxoReader) {
-        @Override
-        protected FacetsAccumulator initFacetsAccumulator(FacetSearchParams facetSearchParams, IndexReader indexReader, TaxonomyReader taxonomyReader) {
-          FacetsAccumulator fa = new StandardFacetsAccumulator(facetSearchParams, indexReader, taxonomyReader);
-          fa.setComplementThreshold(FacetsAccumulator.DISABLE_COMPLEMENT);
-          return fa;
-        }
-      };
+      FacetSearchParams sParams2 = getFacetSearchParams(fip, new CountFacetRequest(path, Integer.MAX_VALUE));
+      FacetsCollector fc2 = FacetsCollector.create(sParams2, indexReader, taxoReader);
       
       searcher.search(new MatchAllDocsQuery(), fc2);
       List<FacetResult> baseResults = fc2.getFacetResults();

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandlerRandom.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandlerRandom.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandlerRandom.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandlerRandom.java Fri Feb  8 05:15:53 2013
@@ -8,8 +8,6 @@ import org.apache.lucene.facet.index.par
 import org.apache.lucene.facet.search.params.FacetSearchParams;
 import org.apache.lucene.facet.search.results.FacetResult;
 import org.apache.lucene.facet.search.results.FacetResultNode;
-import org.apache.lucene.facet.taxonomy.TaxonomyReader;
-import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.Query;
 import org.junit.Test;
@@ -37,17 +35,9 @@ public class TestTopKResultsHandlerRando
       throws IOException {
     Query q = new MatchAllDocsQuery();
     FacetSearchParams facetSearchParams = searchParamsWithRequests(numResults, fip);
-    FacetsCollector fc = new StandardFacetsCollector(facetSearchParams, indexReader, taxoReader) {
-      @Override
-      protected FacetsAccumulator initFacetsAccumulator(
-          FacetSearchParams facetSearchParams, IndexReader indexReader,
-          TaxonomyReader taxonomyReader) {
-        FacetsAccumulator accumulator = new StandardFacetsAccumulator(facetSearchParams, indexReader, taxonomyReader);
-        double complement = doComplement ? FacetsAccumulator.FORCE_COMPLEMENT : FacetsAccumulator.DISABLE_COMPLEMENT;
-        accumulator.setComplementThreshold(complement);
-        return accumulator;
-      }
-    };
+    StandardFacetsAccumulator sfa = new StandardFacetsAccumulator(facetSearchParams, indexReader, taxoReader);
+    sfa.setComplementThreshold(doComplement ? StandardFacetsAccumulator.FORCE_COMPLEMENT : StandardFacetsAccumulator.DISABLE_COMPLEMENT);
+    FacetsCollector fc = FacetsCollector.create(sfa);
     searcher.search(q, fc);
     List<FacetResult> facetResults = fc.getFacetResults();
     return facetResults;

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/associations/AssociationsFacetRequestTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/associations/AssociationsFacetRequestTest.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/associations/AssociationsFacetRequestTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/associations/AssociationsFacetRequestTest.java Fri Feb  8 05:15:53 2013
@@ -117,8 +117,8 @@ public class AssociationsFacetRequestTes
     
     assertNotNull("No results!",res);
     assertEquals("Wrong number of results!",2, res.size());
-    assertEquals("Wrong count for category 'a'!",200, (int) res.get(0).getFacetResultNode().value);
-    assertEquals("Wrong count for category 'b'!",150, (int) res.get(1).getFacetResultNode().value);
+    assertEquals("Wrong count for category 'a'!", 200, (int) res.get(0).getFacetResultNode().value);
+    assertEquals("Wrong count for category 'b'!", 150, (int) res.get(1).getFacetResultNode().value);
     
     taxo.close();
   }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java Fri Feb  8 05:15:53 2013
@@ -1,13 +1,7 @@
 package org.apache.lucene.facet.search.params;
 
 import org.apache.lucene.facet.FacetTestCase;
-import org.apache.lucene.facet.search.FacetResultsHandler;
 import org.apache.lucene.facet.taxonomy.CategoryPath;
-import org.apache.lucene.facet.taxonomy.TaxonomyReader;
-import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.store.Directory;
 import org.junit.Test;
 
 /*
@@ -49,47 +43,4 @@ public class FacetRequestTest extends Fa
     assertFalse("equals() should return false as fr1.depth != fr2.depth", fr1.equals(fr2));
   }
   
-  @Test
-  public void testGetFacetResultHandlerDifferentTaxonomy() throws Exception {
-    FacetRequest fr = new CountFacetRequest(new CategoryPath("a"), 10);
-    Directory dir1 = newDirectory();
-    Directory dir2 = newDirectory();
-    // create empty indexes, so that LTR ctor won't complain about a missing index.
-    new IndexWriter(dir1, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close();
-    new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close();
-    TaxonomyReader tr1 = new DirectoryTaxonomyReader(dir1);
-    TaxonomyReader tr2 = new DirectoryTaxonomyReader(dir2);
-    FacetResultsHandler frh1 = fr.createFacetResultsHandler(tr1);
-    FacetResultsHandler frh2 = fr.createFacetResultsHandler(tr2);
-    assertTrue("should not return the same FacetResultHandler instance for different TaxonomyReader instances", frh1 != frh2);
-    tr1.close();
-    tr2.close();
-    dir1.close();
-    dir2.close();
-  }
-  
-  @Test
-  public void testImmutability() throws Exception {
-    // Tests that after a FRH is created by FR, changes to FR are not reflected
-    // in the FRH.
-    FacetRequest fr = new CountFacetRequest(new CategoryPath("a"), 10);
-    Directory dir = newDirectory();
-    // create empty indexes, so that LTR ctor won't complain about a missing index.
-    new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close();
-    TaxonomyReader tr = new DirectoryTaxonomyReader(dir);
-    FacetResultsHandler frh = fr.createFacetResultsHandler(tr);
-    fr.setDepth(10);
-    assertEquals(FacetRequest.DEFAULT_DEPTH, frh.getFacetRequest().getDepth());
-    tr.close();
-    dir.close();
-  }
-  
-  @Test
-  public void testClone() throws Exception {
-    FacetRequest fr = new CountFacetRequest(new CategoryPath("a"), 10);
-    FacetRequest clone = fr.clone();
-    fr.setDepth(10);
-    assertEquals("depth should not have been affected in the clone", FacetRequest.DEFAULT_DEPTH, clone.getDepth());
-  }
-  
 }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java Fri Feb  8 05:15:53 2013
@@ -5,11 +5,8 @@ import java.util.Random;
 
 import org.apache.lucene.facet.index.params.FacetIndexingParams;
 import org.apache.lucene.facet.search.BaseTestTopK;
-import org.apache.lucene.facet.search.FacetsAccumulator;
 import org.apache.lucene.facet.search.FacetsCollector;
-import org.apache.lucene.facet.search.ScoredDocIDs;
-import org.apache.lucene.facet.search.ScoredDocIdCollector;
-import org.apache.lucene.facet.search.StandardFacetsCollector;
+import org.apache.lucene.facet.search.StandardFacetsAccumulator;
 import org.apache.lucene.facet.search.params.FacetRequest;
 import org.apache.lucene.facet.search.params.FacetRequest.ResultMode;
 import org.apache.lucene.facet.search.params.FacetSearchParams;
@@ -17,7 +14,6 @@ import org.apache.lucene.facet.search.re
 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.search.MultiCollector;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermQuery;
 
@@ -60,7 +56,7 @@ public abstract class BaseSampleTestTopK
     return res;
   }
   
-  protected abstract FacetsAccumulator getSamplingAccumulator(Sampler sampler, TaxonomyReader taxoReader, 
+  protected abstract StandardFacetsAccumulator getSamplingAccumulator(Sampler sampler, TaxonomyReader taxoReader, 
       IndexReader indexReader, FacetSearchParams searchParams);
   
   /**
@@ -79,12 +75,11 @@ public abstract class BaseSampleTestTopK
         // Get all of the documents and run the query, then do different
         // facet counts and compare to control
         Query q = new TermQuery(new Term(CONTENT_FIELD, BETA)); // 90% of the docs
-        ScoredDocIdCollector docCollector = ScoredDocIdCollector.create(indexReader.maxDoc(), false);
         
         FacetSearchParams expectedSearchParams = searchParamsWithRequests(K, fip); 
         FacetsCollector fc = FacetsCollector.create(expectedSearchParams, indexReader, taxoReader);
         
-        searcher.search(q, MultiCollector.wrap(docCollector, fc));
+        searcher.search(q, fc);
         
         List<FacetResult> expectedResults = fc.getFacetResults();
         
@@ -95,7 +90,7 @@ public abstract class BaseSampleTestTopK
         for (int nTrial = 0; nTrial < RETRIES; nTrial++) {
           try {
             // complement with sampling!
-            final Sampler sampler = createSampler(nTrial, docCollector.getScoredDocIDs(), useRandomSampler);
+            final Sampler sampler = createSampler(nTrial, useRandomSampler);
             
             assertSampling(expectedResults, q, sampler, samplingSearchParams, false);
             assertSampling(expectedResults, q, sampler, samplingSearchParams, true);
@@ -124,19 +119,12 @@ public abstract class BaseSampleTestTopK
   
   private FacetsCollector samplingCollector(final boolean complement, final Sampler sampler,
       FacetSearchParams samplingSearchParams) {
-    FacetsCollector samplingFC = new StandardFacetsCollector(samplingSearchParams, indexReader, taxoReader) {
-      @Override
-      protected FacetsAccumulator initFacetsAccumulator(FacetSearchParams facetSearchParams, IndexReader indexReader,
-          TaxonomyReader taxonomyReader) {
-        FacetsAccumulator acc = getSamplingAccumulator(sampler, taxonomyReader, indexReader, facetSearchParams);
-        acc.setComplementThreshold(complement ? FacetsAccumulator.FORCE_COMPLEMENT : FacetsAccumulator.DISABLE_COMPLEMENT);
-        return acc;
-      }
-    };
-    return samplingFC;
+    StandardFacetsAccumulator sfa = getSamplingAccumulator(sampler, taxoReader, indexReader, samplingSearchParams);
+    sfa.setComplementThreshold(complement ? StandardFacetsAccumulator.FORCE_COMPLEMENT : StandardFacetsAccumulator.DISABLE_COMPLEMENT);
+    return FacetsCollector.create(sfa);
   }
   
-  private Sampler createSampler(int nTrial, ScoredDocIDs scoredDocIDs, boolean useRandomSampler) {
+  private Sampler createSampler(int nTrial, boolean useRandomSampler) {
     SamplingParams samplingParams = new SamplingParams();
     
     final double retryFactor = Math.pow(1.01, nTrial);
@@ -149,7 +137,6 @@ public abstract class BaseSampleTestTopK
     Sampler sampler = useRandomSampler ? 
         new RandomSampler(samplingParams, new Random(random().nextLong())) :
           new RepeatableSampler(samplingParams);
-    assertTrue("must enable sampling for this test!",sampler.shouldSample(scoredDocIDs));
     return sampler;
   }
   

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/OversampleWithDepthTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/OversampleWithDepthTest.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/OversampleWithDepthTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/OversampleWithDepthTest.java Fri Feb  8 05:15:53 2013
@@ -7,9 +7,8 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.facet.FacetTestCase;
 import org.apache.lucene.facet.index.FacetFields;
 import org.apache.lucene.facet.index.params.FacetIndexingParams;
-import org.apache.lucene.facet.search.FacetsAccumulator;
 import org.apache.lucene.facet.search.FacetsCollector;
-import org.apache.lucene.facet.search.StandardFacetsCollector;
+import org.apache.lucene.facet.search.StandardFacetsAccumulator;
 import org.apache.lucene.facet.search.params.CountFacetRequest;
 import org.apache.lucene.facet.search.params.FacetRequest;
 import org.apache.lucene.facet.search.params.FacetRequest.ResultMode;
@@ -112,14 +111,9 @@ public class OversampleWithDepthTest ext
   private FacetResult searchWithFacets(IndexReader r, TaxonomyReader tr, FacetSearchParams fsp, 
       final SamplingParams params) throws IOException {
     // a FacetsCollector with a sampling accumulator
-    FacetsCollector fcWithSampling = new StandardFacetsCollector(fsp, r, tr) {
-      @Override
-      protected FacetsAccumulator initFacetsAccumulator(FacetSearchParams facetSearchParams, IndexReader indexReader,
-          TaxonomyReader taxonomyReader) {
-        Sampler sampler = new RandomSampler(params, random());
-        return new SamplingAccumulator(sampler, facetSearchParams, indexReader, taxonomyReader);
-      }
-    };
+    Sampler sampler = new RandomSampler(params, random());
+    StandardFacetsAccumulator sfa = new SamplingAccumulator(sampler, fsp, r, tr);
+    FacetsCollector fcWithSampling = FacetsCollector.create(sfa);
     
     IndexSearcher s = new IndexSearcher(r);
     s.search(new MatchAllDocsQuery(), fcWithSampling);

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/SamplingAccumulatorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/SamplingAccumulatorTest.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/SamplingAccumulatorTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/sampling/SamplingAccumulatorTest.java Fri Feb  8 05:15:53 2013
@@ -1,11 +1,10 @@
 package org.apache.lucene.facet.search.sampling;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.util.LuceneTestCase.Slow;
-
-import org.apache.lucene.facet.search.FacetsAccumulator;
+import org.apache.lucene.facet.search.StandardFacetsAccumulator;
 import org.apache.lucene.facet.search.params.FacetSearchParams;
 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.util.LuceneTestCase.Slow;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -28,7 +27,7 @@ import org.apache.lucene.facet.taxonomy.
 public class SamplingAccumulatorTest extends BaseSampleTestTopK {
 
   @Override
-  protected FacetsAccumulator getSamplingAccumulator(Sampler sampler, TaxonomyReader taxoReader, 
+  protected StandardFacetsAccumulator getSamplingAccumulator(Sampler sampler, TaxonomyReader taxoReader, 
       IndexReader indexReader, FacetSearchParams searchParams) {
     return new SamplingAccumulator(sampler, searchParams, indexReader, taxoReader);
   }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/util/TestScoredDocIDsUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/util/TestScoredDocIDsUtils.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/util/TestScoredDocIDsUtils.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/util/TestScoredDocIDsUtils.java Fri Feb  8 05:15:53 2013
@@ -12,19 +12,13 @@ import org.apache.lucene.document.String
 import org.apache.lucene.facet.FacetTestCase;
 import org.apache.lucene.facet.search.ScoredDocIDs;
 import org.apache.lucene.facet.search.ScoredDocIDsIterator;
-import org.apache.lucene.facet.search.ScoredDocIdCollector;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.MultiFields;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.DocIdSet;
 import org.apache.lucene.search.DocIdSetIterator;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.FixedBitSet;
 import org.junit.Test;
 
@@ -101,79 +95,6 @@ public class TestScoredDocIDsUtils exten
     }
   }
   
-  @Test
-  public void testWithDeletions() throws Exception {
-    int N_DOCS = 100;
-
-    DocumentFactory docFactory = new DocumentFactory(N_DOCS) {
-      @Override
-      public boolean markedDeleted(int docNum) {
-        return (docNum % 3 == 0 ||        // every 3rd documents, including first 
-            docNum == numDocs - 1 ||     // last document
-            docNum == numDocs / 2 ||     // 3 consecutive documents in the middle
-            docNum == 1 + numDocs / 2 ||
-            docNum == 2 + numDocs / 2);
-      }
-      
-      // every 6th document (starting from the 2nd) would contain 'alpha'
-      @Override
-      public boolean haveAlpha(int docNum) {
-        return (docNum % 6 == 1);
-      }
-    };
-    
-    Directory dir = newDirectory();
-    IndexReader reader = createReaderWithNDocs(random(), N_DOCS, docFactory, dir);
-    try {
-      ScoredDocIDs allDocs = ScoredDocIdsUtils.createAllDocsScoredDocIDs(reader);
-      ScoredDocIDsIterator it = allDocs.iterator();
-      int numIteratedDocs = 0;
-      while (it.next()) {
-        numIteratedDocs++;
-        int docNum = it.getDocID();
-        assertNull(
-            "Deleted docs must not appear in the allDocsScoredDocIds set: " + docNum, 
-            reader.document(docNum).getField("del"));
-      }
-
-      assertEquals("Wrong number of (live) documents", allDocs.size(), numIteratedDocs);
-
-      // Get all 'alpha' documents
-      ScoredDocIdCollector collector = ScoredDocIdCollector.create(reader.maxDoc(), false);
-      Query q = new TermQuery(new Term(DocumentFactory.field, DocumentFactory.alphaTxt));
-      IndexSearcher searcher = newSearcher(reader);
-      searcher.search(q, collector);
-
-      ScoredDocIDs scoredDocIds = collector.getScoredDocIDs();
-      FixedBitSet resultSet = (FixedBitSet) scoredDocIds.getDocIDs();
-      
-      // Getting the complement set of the query result
-      ScoredDocIDs complementSet = ScoredDocIdsUtils.getComplementSet(scoredDocIds, reader);
-
-      assertEquals("Number of documents in complement set mismatch",
-          reader.numDocs() - scoredDocIds.size(), complementSet.size());
-
-      // now make sure the documents in the complement set are not deleted
-      // and not in the original result set
-      ScoredDocIDsIterator compIterator = complementSet.iterator();
-      Bits live = MultiFields.getLiveDocs(reader);
-      while (compIterator.next()) {
-        int docNum = compIterator.getDocID();
-        assertFalse(
-            "Complement-Set must not contain deleted documents (doc="+docNum+")",
-            live != null && !live.get(docNum));
-        assertNull("Complement-Set must not contain docs from the original set (doc="+ docNum+")", 
-            reader.document(docNum).getField("del"));
-        assertFalse(
-            "Complement-Set must not contain docs from the original set (doc="+docNum+")",
-            resultSet.get(docNum));
-      }
-    } finally {
-      reader.close();
-      dir.close();
-    }
-  }
-  
   /**
    * Creates an index with n documents, this method is meant for testing purposes ONLY
    */
@@ -189,10 +110,7 @@ public class TestScoredDocIDsUtils exten
     private final static Field deletionMark = new StringField(field, delTxt, Field.Store.NO);
     private final static Field alphaContent = new StringField(field, alphaTxt, Field.Store.NO);
     
-    protected final int numDocs;
-    
     public DocumentFactory(int totalNumDocs) {
-      this.numDocs = totalNumDocs;
     }
     
     public boolean markedDeleted(int docNum) {

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/util/collections/ObjectToIntMapTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/util/collections/ObjectToIntMapTest.java?rev=1443839&r1=1443838&r2=1443839&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/util/collections/ObjectToIntMapTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/util/collections/ObjectToIntMapTest.java Fri Feb  8 05:15:53 2013
@@ -4,12 +4,8 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Random;
 
-import org.junit.Test;
-
 import org.apache.lucene.facet.FacetTestCase;
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.collections.IntIterator;
-import org.apache.lucene.util.collections.ObjectToIntMap;
+import org.junit.Test;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more