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/07 22:32:28 UTC
svn commit: r1443736 [2/3] - in /lucene/dev/trunk/lucene: ./
demo/src/java/org/apache/lucene/demo/facet/adaptive/
demo/src/java/org/apache/lucene/demo/facet/multiCL/
facet/src/java/org/apache/lucene/facet/associations/search/
facet/src/java/org/apache/...
Modified: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/StandardFacetsAccumulator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/StandardFacetsAccumulator.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/StandardFacetsAccumulator.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/StandardFacetsAccumulator.java Thu Feb 7 21:32:27 2013
@@ -11,11 +11,15 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.lucene.facet.index.params.FacetIndexingParams;
+import org.apache.lucene.facet.partitions.search.PartitionsFacetResultsHandler;
+import org.apache.lucene.facet.search.FacetsCollector.MatchingDocs;
import org.apache.lucene.facet.search.aggregator.Aggregator;
+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;
import org.apache.lucene.facet.search.params.FacetSearchParams;
import org.apache.lucene.facet.search.results.FacetResult;
-import org.apache.lucene.facet.search.results.IntermediateFacetResult;
+import org.apache.lucene.facet.partitions.search.IntermediateFacetResult;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.util.PartitionsUtils;
import org.apache.lucene.facet.util.ScoredDocIdsUtils;
@@ -66,7 +70,23 @@ public class StandardFacetsAccumulator e
private static final Logger logger = Logger.getLogger(StandardFacetsAccumulator.class.getName());
- protected final FacetArrays facetArrays;
+ /**
+ * Default threshold for using the complements optimization.
+ * If accumulating facets for a document set larger than this ratio of the index size than
+ * perform the complement optimization.
+ * @see #setComplementThreshold(double) for more info on the complements optimization.
+ */
+ public static final double DEFAULT_COMPLEMENT_THRESHOLD = 0.6;
+
+ /**
+ * Passing this to {@link #setComplementThreshold(double)} will disable using complement optimization.
+ */
+ public static final double DISABLE_COMPLEMENT = Double.POSITIVE_INFINITY; // > 1 actually
+
+ /**
+ * Passing this to {@link #setComplementThreshold(double)} will force using complement optimization.
+ */
+ public static final double FORCE_COMPLEMENT = 0; // <=0
protected int partitionSize;
protected int maxPartitions;
@@ -76,15 +96,18 @@ public class StandardFacetsAccumulator e
private Object accumulateGuard;
+ private double complementThreshold;
+
+ public StandardFacetsAccumulator(FacetSearchParams searchParams, IndexReader indexReader,
+ TaxonomyReader taxonomyReader) {
+ this(searchParams, indexReader, taxonomyReader, new FacetArrays(
+ PartitionsUtils.partitionSize(searchParams.indexingParams, taxonomyReader)));
+ }
+
public StandardFacetsAccumulator(FacetSearchParams searchParams, IndexReader indexReader,
TaxonomyReader taxonomyReader, FacetArrays facetArrays) {
- super(searchParams,indexReader,taxonomyReader);
-
- if (facetArrays == null) {
- throw new IllegalArgumentException("facetArrays cannot be null");
- }
+ super(searchParams, indexReader, taxonomyReader, facetArrays);
- this.facetArrays = facetArrays;
// can only be computed later when docids size is known
isUsingComplements = false;
partitionSize = PartitionsUtils.partitionSize(searchParams.indexingParams, taxonomyReader);
@@ -92,13 +115,7 @@ public class StandardFacetsAccumulator e
accumulateGuard = new Object();
}
- public StandardFacetsAccumulator(FacetSearchParams searchParams,
- IndexReader indexReader, TaxonomyReader taxonomyReader) {
- this(searchParams, indexReader, taxonomyReader, new FacetArrays(
- PartitionsUtils.partitionSize(searchParams.indexingParams, taxonomyReader)));
- }
-
- @Override
+ // TODO: this should be removed once we clean the API
public List<FacetResult> accumulate(ScoredDocIDs docids) throws IOException {
// synchronize to prevent calling two accumulate()'s at the same time.
@@ -162,8 +179,8 @@ public class StandardFacetsAccumulator e
for (FacetRequest fr : searchParams.facetRequests) {
// Handle and merge only facet requests which were not already handled.
if (handledRequests.add(fr)) {
- FacetResultsHandler frHndlr = fr.createFacetResultsHandler(taxonomyReader);
- IntermediateFacetResult res4fr = frHndlr.fetchPartitionResult(facetArrays, offset);
+ PartitionsFacetResultsHandler frHndlr = createFacetResultsHandler(fr);
+ IntermediateFacetResult res4fr = frHndlr.fetchPartitionResult(offset);
IntermediateFacetResult oldRes = fr2tmpRes.get(fr);
if (oldRes != null) {
res4fr = frHndlr.mergeResults(oldRes, res4fr);
@@ -179,16 +196,14 @@ public class StandardFacetsAccumulator e
// gather results from all requests into a list for returning them
List<FacetResult> res = new ArrayList<FacetResult>();
for (FacetRequest fr : searchParams.facetRequests) {
- FacetResultsHandler frHndlr = fr.createFacetResultsHandler(taxonomyReader);
+ PartitionsFacetResultsHandler frHndlr = createFacetResultsHandler(fr);
IntermediateFacetResult tmpResult = fr2tmpRes.get(fr);
if (tmpResult == null) {
continue; // do not add a null to the list.
}
FacetResult facetRes = frHndlr.renderFacetResult(tmpResult);
// final labeling if allowed (because labeling is a costly operation)
- if (isAllowLabeling()) {
- frHndlr.labelResult(facetRes);
- }
+ frHndlr.labelResult(facetRes);
res.add(facetRes);
}
@@ -196,6 +211,25 @@ public class StandardFacetsAccumulator e
}
}
+ /** check if all requests are complementable */
+ protected boolean mayComplement() {
+ for (FacetRequest freq : searchParams.facetRequests) {
+ if (!(freq instanceof CountFacetRequest)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ protected PartitionsFacetResultsHandler createFacetResultsHandler(FacetRequest fr) {
+ if (fr.getResultMode() == ResultMode.PER_NODE_IN_TREE) {
+ return new TopKInEachNodeHandler(taxonomyReader, fr, facetArrays);
+ } else {
+ return new TopKFacetResultsHandler(taxonomyReader, fr, facetArrays);
+ }
+ }
+
/**
* Set the actual set of documents over which accumulation should take place.
* <p>
@@ -338,4 +372,43 @@ public class StandardFacetsAccumulator e
return categoryLists;
}
-}
\ No newline at end of file
+
+ @Override
+ public List<FacetResult> accumulate(List<MatchingDocs> matchingDocs) throws IOException {
+ return accumulate(new MatchingDocsAsScoredDocIDs(matchingDocs));
+ }
+
+ /**
+ * Returns the complement threshold.
+ * @see #setComplementThreshold(double)
+ */
+ public double getComplementThreshold() {
+ return complementThreshold;
+ }
+
+ /**
+ * Set the complement threshold.
+ * This threshold will dictate whether the complements optimization is applied.
+ * The optimization is to count for less documents. It is useful when the same
+ * FacetSearchParams are used for varying sets of documents. The first time
+ * complements is used the "total counts" are computed - counting for all the
+ * documents in the collection. Then, only the complementing set of documents
+ * is considered, and used to decrement from the overall counts, thereby
+ * walking through less documents, which is faster.
+ * <p>
+ * For the default settings see {@link #DEFAULT_COMPLEMENT_THRESHOLD}.
+ * <p>
+ * To forcing complements in all cases pass {@link #FORCE_COMPLEMENT}.
+ * This is mostly useful for testing purposes, as forcing complements when only
+ * tiny fraction of available documents match the query does not make sense and
+ * would incur performance degradations.
+ * <p>
+ * To disable complements pass {@link #DISABLE_COMPLEMENT}.
+ * @param complementThreshold the complement threshold to set
+ * @see #getComplementThreshold()
+ */
+ public void setComplementThreshold(double complementThreshold) {
+ this.complementThreshold = complementThreshold;
+ }
+
+}
Added: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/SumScoreFacetsAggregator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/SumScoreFacetsAggregator.java?rev=1443736&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/SumScoreFacetsAggregator.java (added)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/SumScoreFacetsAggregator.java Thu Feb 7 21:32:27 2013
@@ -0,0 +1,78 @@
+package org.apache.lucene.facet.search;
+
+import java.io.IOException;
+
+import org.apache.lucene.facet.index.params.CategoryListParams;
+import org.apache.lucene.facet.search.FacetsCollector.MatchingDocs;
+import org.apache.lucene.facet.taxonomy.TaxonomyReader;
+import org.apache.lucene.util.IntsRef;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * A {@link FacetsAggregator} which updates the weight of a category by summing the
+ * scores of documents it was found in.
+ */
+public class SumScoreFacetsAggregator implements FacetsAggregator {
+
+ private final IntsRef ordinals = new IntsRef(32);
+
+ @Override
+ public void aggregate(MatchingDocs matchingDocs, CategoryListParams clp, FacetArrays facetArrays) throws IOException {
+ CategoryListIterator cli = clp.createCategoryListIterator(0);
+ if (!cli.setNextReader(matchingDocs.context)) {
+ return;
+ }
+
+ int doc = 0;
+ int length = matchingDocs.bits.length();
+ float[] scores = facetArrays.getFloatArray();
+ while (doc < length && (doc = matchingDocs.bits.nextSetBit(doc)) != -1) {
+ cli.getOrdinals(doc, ordinals);
+ int upto = ordinals.offset + ordinals.length;
+ for (int i = ordinals.offset; i < upto; i++) {
+ scores[ordinals.ints[i]] += matchingDocs.scores[doc];
+ }
+ ++doc;
+ }
+ }
+
+ private float rollupScores(int ordinal, int[] children, int[] siblings, float[] scores) {
+ float score = 0f;
+ while (ordinal != TaxonomyReader.INVALID_ORDINAL) {
+ float childScore = scores[ordinal];
+ childScore += rollupScores(children[ordinal], children, siblings, scores);
+ scores[ordinal] = childScore;
+ score += childScore;
+ ordinal = siblings[ordinal];
+ }
+ return score;
+ }
+
+ @Override
+ public void rollupValues(int ordinal, int[] children, int[] siblings, FacetArrays facetArrays) {
+ float[] scores = facetArrays.getFloatArray();
+ scores[ordinal] += rollupScores(children[ordinal], children, siblings, scores);
+ }
+
+ @Override
+ public boolean requiresDocScores() {
+ return true;
+ }
+
+}
Modified: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TopKFacetResultsHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TopKFacetResultsHandler.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TopKFacetResultsHandler.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TopKFacetResultsHandler.java Thu Feb 7 21:32:27 2013
@@ -3,10 +3,11 @@ package org.apache.lucene.facet.search;
import java.io.IOException;
import java.util.ArrayList;
+import org.apache.lucene.facet.partitions.search.IntermediateFacetResult;
+import org.apache.lucene.facet.partitions.search.PartitionsFacetResultsHandler;
import org.apache.lucene.facet.search.params.FacetRequest;
import org.apache.lucene.facet.search.results.FacetResult;
import org.apache.lucene.facet.search.results.FacetResultNode;
-import org.apache.lucene.facet.search.results.IntermediateFacetResult;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays;
import org.apache.lucene.facet.util.ResultSortUtils;
@@ -28,30 +29,29 @@ import org.apache.lucene.facet.util.Resu
* limitations under the License.
*/
-/**
- * Generate Top-K results for a particular FacetRequest.
- * <p>
- * K is global (among all results) and is defined by {@link FacetRequest#getNumResults()}.
- * <p>
- * Note: Values of 0 (Zero) are ignored by this results handler.
+/**
+ * Generate Top-K results for a particular {@link FacetRequest}. K is global
+ * (among all results) and is defined by {@link FacetRequest#numResults}.
*
* @lucene.experimental
*/
-public class TopKFacetResultsHandler extends FacetResultsHandler {
+public class TopKFacetResultsHandler extends PartitionsFacetResultsHandler {
/**
- * Construct top-K results handler.
- * @param taxonomyReader taxonomy reader
- * @param facetRequest facet request being served
+ * Construct top-K results handler.
+ *
+ * @param taxonomyReader
+ * taxonomy reader
+ * @param facetRequest
+ * facet request being served
*/
- public TopKFacetResultsHandler(TaxonomyReader taxonomyReader,
- FacetRequest facetRequest) {
- super(taxonomyReader, facetRequest);
+ public TopKFacetResultsHandler(TaxonomyReader taxonomyReader, FacetRequest facetRequest, FacetArrays facetArrays) {
+ super(taxonomyReader, facetRequest, facetArrays);
}
// fetch top K for specific partition.
@Override
- public IntermediateFacetResult fetchPartitionResult(FacetArrays facetArrays, int offset)
+ public IntermediateFacetResult fetchPartitionResult(int offset)
throws IOException {
TopKFacetResult res = null;
int ordinal = taxonomyReader.getOrdinal(facetRequest.categoryPath);
@@ -65,7 +65,7 @@ public class TopKFacetResultsHandler ext
FacetResultNode parentResultNode = new FacetResultNode(ordinal, value);
Heap<FacetResultNode> heap = ResultSortUtils.createSuitableHeap(facetRequest);
- int totalFacets = heapDescendants(ordinal, heap, parentResultNode, facetArrays, offset);
+ int totalFacets = heapDescendants(ordinal, heap, parentResultNode, offset);
res = new TopKFacetResult(facetRequest, parentResultNode, totalFacets);
res.setHeap(heap);
}
@@ -113,7 +113,7 @@ public class TopKFacetResultsHandler ext
* @return total number of descendants considered here by pq, excluding ordinal itself.
*/
private int heapDescendants(int ordinal, Heap<FacetResultNode> pq, FacetResultNode parentResultNode,
- FacetArrays facetArrays, int offset) throws IOException {
+ int offset) throws IOException {
int partitionSize = facetArrays.arrayLength;
int endOffset = offset + partitionSize;
ParallelTaxonomyArrays childrenArray = taxonomyReader.getParallelTaxonomyArrays();
Modified: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java Thu Feb 7 21:32:27 2013
@@ -4,11 +4,12 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.lucene.facet.partitions.search.IntermediateFacetResult;
+import org.apache.lucene.facet.partitions.search.PartitionsFacetResultsHandler;
import org.apache.lucene.facet.search.params.FacetRequest;
import org.apache.lucene.facet.search.params.FacetRequest.SortOrder;
import org.apache.lucene.facet.search.results.FacetResult;
import org.apache.lucene.facet.search.results.FacetResultNode;
-import org.apache.lucene.facet.search.results.IntermediateFacetResult;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays;
import org.apache.lucene.util.PriorityQueue;
@@ -33,20 +34,19 @@ import org.apache.lucene.util.collection
*/
/**
- * Generates {@link FacetResult} from the count arrays aggregated for a
+ * Generates {@link FacetResult} from the {@link FacetArrays} aggregated for a
* particular {@link FacetRequest}. The generated {@link FacetResult} is a
* subtree of the taxonomy tree. Its root node,
* {@link FacetResult#getFacetResultNode()}, is the facet specified by
* {@link FacetRequest#categoryPath}, and the enumerated children,
- * {@link FacetResultNode#subResults}, of each node in that
- * {@link FacetResult} are the top K ( = {@link FacetRequest#getNumResults()})
- * among its children in the taxonomy. Top in the sense
- * {@link FacetRequest#getSortBy()}, which can be by the values aggregated in
- * the count arrays, or by ordinal numbers; also specified is the sort order,
- * {@link FacetRequest#getSortOrder()}, ascending or descending, of these values
- * or ordinals before their top K are selected. The depth (number of levels
- * excluding the root) of the {@link FacetResult} tree is specified by
- * {@link FacetRequest#getDepth()}.
+ * {@link FacetResultNode#subResults}, of each node in that {@link FacetResult}
+ * are the top K ( = {@link FacetRequest#numResults}) among its children in the
+ * taxonomy. Top in the sense {@link FacetRequest#getSortBy()}, which can be by
+ * the values aggregated in the count arrays, or by ordinal numbers; also
+ * specified is the sort order, {@link FacetRequest#getSortOrder()}, ascending
+ * or descending, of these values or ordinals before their top K are selected.
+ * The depth (number of levels excluding the root) of the {@link FacetResult}
+ * tree is specified by {@link FacetRequest#getDepth()}.
* <p>
* Because the number of selected children of each node is restricted, and not
* the overall number of nodes in the {@link FacetResult}, facets not selected
@@ -67,45 +67,45 @@ import org.apache.lucene.util.collection
*
* @lucene.experimental
*/
-public class TopKInEachNodeHandler extends FacetResultsHandler {
+public class TopKInEachNodeHandler extends PartitionsFacetResultsHandler {
- public TopKInEachNodeHandler(TaxonomyReader taxonomyReader, FacetRequest facetRequest) {
- super(taxonomyReader, facetRequest);
+ public TopKInEachNodeHandler(TaxonomyReader taxonomyReader, FacetRequest facetRequest, FacetArrays facetArrays) {
+ super(taxonomyReader, facetRequest, facetArrays);
}
/**
* Recursively explore all facets that can be potentially included in the
* {@link FacetResult} to be generated, and that belong to the given
* partition, so that values can be examined and collected. For each such
- * node, gather its top K ({@link FacetRequest#getNumResults()}) children
- * among its children that are encountered in the given particular partition
- * (aka current counting list).
+ * node, gather its top K ({@link FacetRequest#numResults}) children among its
+ * children that are encountered in the given particular partition (aka
+ * current counting list).
+ * @param offset
+ * to <code>offset</code> + the length of the count arrays within
+ * <code>arrays</code> (exclusive)
*
* @return {@link IntermediateFacetResult} consisting of
- * {@link IntToObjectMap} that maps potential
- * {@link FacetResult} nodes to their top K children encountered in
- * the current partition. Note that the mapped potential tree nodes
- * need not belong to the given partition, only the top K children
- * mapped to. The aim is to identify nodes that are certainly excluded
- * from the {@link FacetResult} to be eventually (after going through
- * all the partitions) returned by this handler, because they have K
- * better siblings, already identified in this partition. For the
- * identified excluded nodes, we only count number of their
- * descendants in the subtree (to be included in
+ * {@link IntToObjectMap} that maps potential {@link FacetResult}
+ * nodes to their top K children encountered in the current partition.
+ * Note that the mapped potential tree nodes need not belong to the
+ * given partition, only the top K children mapped to. The aim is to
+ * identify nodes that are certainly excluded from the
+ * {@link FacetResult} to be eventually (after going through all the
+ * partitions) returned by this handler, because they have K better
+ * siblings, already identified in this partition. For the identified
+ * excluded nodes, we only count number of their descendants in the
+ * subtree (to be included in
* {@link FacetResult#getNumValidDescendants()}), but not bother with
* selecting top K in these generations, which, by definition, are,
* too, excluded from the FacetResult tree.
- * @param arrays the already filled in count array, potentially only covering
- * one partition: the ordinals ranging from
- * @param offset to <code>offset</code> + the length of the count arrays
- * within <code>arrays</code> (exclusive)
- * @throws IOException in case
- * {@link TaxonomyReader#getOrdinal(org.apache.lucene.facet.taxonomy.CategoryPath)}
- * does.
- * @see FacetResultsHandler#fetchPartitionResult(FacetArrays, int)
+ * @throws IOException
+ * in case
+ * {@link TaxonomyReader#getOrdinal(org.apache.lucene.facet.taxonomy.CategoryPath)}
+ * does.
+ * @see #fetchPartitionResult(int)
*/
@Override
- public IntermediateFacetResult fetchPartitionResult(FacetArrays arrays, int offset) throws IOException {
+ public IntermediateFacetResult fetchPartitionResult(int offset) throws IOException {
// get the root of the result tree to be returned, and the depth of that result tree
// (depth means number of node levels excluding the root).
@@ -114,12 +114,12 @@ public class TopKInEachNodeHandler exten
return null;
}
- int K = Math.min(facetRequest.getNumResults(),taxonomyReader.getSize()); // number of best results in each node
+ int K = Math.min(facetRequest.numResults,taxonomyReader.getSize()); // number of best results in each node
// this will grow into the returned IntermediateFacetResult
IntToObjectMap<AACO> AACOsOfOnePartition = new IntToObjectMap<AACO>();
- int partitionSize = arrays.arrayLength; // all partitions, except, possibly, the last,
+ int partitionSize = facetArrays.arrayLength; // all partitions, except, possibly, the last,
// have the same length. Hence modulo is OK.
int depth = facetRequest.getDepth();
@@ -128,9 +128,9 @@ public class TopKInEachNodeHandler exten
// Need to only have root node.
IntermediateFacetResultWithHash tempFRWH = new IntermediateFacetResultWithHash(
facetRequest, AACOsOfOnePartition);
- if (isSelfPartition(rootNode, arrays, offset)) {
+ if (isSelfPartition(rootNode, facetArrays, offset)) {
tempFRWH.isRootNodeIncluded = true;
- tempFRWH.rootNodeValue = this.facetRequest.getValueOf(arrays, rootNode % partitionSize);
+ tempFRWH.rootNodeValue = this.facetRequest.getValueOf(facetArrays, rootNode % partitionSize);
}
return tempFRWH;
}
@@ -274,7 +274,7 @@ public class TopKInEachNodeHandler exten
while (tosOrdinal >= offset) { // while tosOrdinal belongs to the given partition; here, too, we use the fact
// that TaxonomyReader.INVALID_ORDINAL == -1 < offset
- double value = facetRequest.getValueOf(arrays, tosOrdinal % partitionSize);
+ double value = facetRequest.getValueOf(facetArrays, tosOrdinal % partitionSize);
if (value != 0) { // the value of yc is not 0, it is to be considered.
totalNumOfDescendantsConsidered++;
@@ -291,7 +291,7 @@ public class TopKInEachNodeHandler exten
totalNumOfDescendantsConsidered--; // reduce the 1 earned when the excluded node entered the heap
// and now return it and all its descendants. These will never make it to FacetResult
totalNumOfDescendantsConsidered += countOnly (ac.ordinal, children,
- siblings, arrays, partitionSize, offset, endOffset, localDepth, depth);
+ siblings, partitionSize, offset, endOffset, localDepth, depth);
reusables[++tosReuslables] = ac;
}
}
@@ -343,9 +343,9 @@ public class TopKInEachNodeHandler exten
// now generate a TempFacetResult from AACOsOfOnePartition, and consider self.
IntermediateFacetResultWithHash tempFRWH = new IntermediateFacetResultWithHash(
facetRequest, AACOsOfOnePartition);
- if (isSelfPartition(rootNode, arrays, offset)) {
+ if (isSelfPartition(rootNode, facetArrays, offset)) {
tempFRWH.isRootNodeIncluded = true;
- tempFRWH.rootNodeValue = this.facetRequest.getValueOf(arrays, rootNode % partitionSize);
+ tempFRWH.rootNodeValue = this.facetRequest.getValueOf(facetArrays, rootNode % partitionSize);
}
tempFRWH.totalNumOfFacetsConsidered = totalNumOfDescendantsConsidered;
return tempFRWH;
@@ -367,24 +367,21 @@ public class TopKInEachNodeHandler exten
* @param youngestChild mapping a given ordinal to its youngest child in the taxonomy (of largest ordinal number),
* or to -1 if has no children.
* @param olderSibling mapping a given ordinal to its older sibling, or to -1
- * @param arrays values for the ordinals in the given partition
- * @param offset the first (smallest) ordinal in the given partition
* @param partitionSize number of ordinals in the given partition
+ * @param offset the first (smallest) ordinal in the given partition
* @param endOffset one larger than the largest ordinal that belong to this partition
* @param currentDepth the depth or ordinal in the TaxonomyTree (relative to rootnode of the facetRequest)
* @param maxDepth maximal depth of descendants to be considered here (measured relative to rootnode of the
* facetRequest).
- *
* @return the number of nodes, from ordinal down its descendants, of depth <= maxDepth,
* which reside in the current partition, and whose value != 0
*/
- private int countOnly(int ordinal, int[] youngestChild, int[] olderSibling,
- FacetArrays arrays, int partitionSize, int offset,
- int endOffset, int currentDepth, int maxDepth) {
+ private int countOnly(int ordinal, int[] youngestChild, int[] olderSibling, int partitionSize, int offset,
+ int endOffset, int currentDepth, int maxDepth) {
int ret = 0;
if (offset <= ordinal) {
// ordinal belongs to the current partition
- if (0 != facetRequest.getValueOf(arrays, ordinal % partitionSize)) {
+ if (0 != facetRequest.getValueOf(facetArrays, ordinal % partitionSize)) {
ret++;
}
}
@@ -398,8 +395,8 @@ public class TopKInEachNodeHandler exten
yc = olderSibling[yc];
}
while (yc > TaxonomyReader.INVALID_ORDINAL) { // assuming this is -1, smaller than any legal ordinal
- ret += countOnly (yc, youngestChild, olderSibling, arrays,
- partitionSize, offset, endOffset, currentDepth+1, maxDepth);
+ ret += countOnly (yc, youngestChild, olderSibling, partitionSize,
+ offset, endOffset, currentDepth+1, maxDepth);
yc = olderSibling[yc];
}
return ret;
@@ -409,11 +406,10 @@ public class TopKInEachNodeHandler exten
* Merge several partitions' {@link IntermediateFacetResult}-s into one of the
* same format
*
- * @see FacetResultsHandler#mergeResults(IntermediateFacetResult...)
+ * @see #mergeResults(IntermediateFacetResult...)
*/
@Override
- public IntermediateFacetResult mergeResults(IntermediateFacetResult... tmpResults)
- throws ClassCastException, IllegalArgumentException {
+ public IntermediateFacetResult mergeResults(IntermediateFacetResult... tmpResults) {
if (tmpResults.length == 0) {
return null;
@@ -428,7 +424,7 @@ public class TopKInEachNodeHandler exten
}
// i points to the first non-null input
- int K = this.facetRequest.getNumResults(); // number of best result in each node
+ int K = this.facetRequest.numResults; // number of best result in each node
IntermediateFacetResultWithHash tmpToReturn = (IntermediateFacetResultWithHash)tmpResults[i++];
// now loop over the rest of tmpResults and merge each into tmpToReturn
@@ -667,7 +663,7 @@ public class TopKInEachNodeHandler exten
* Enumerated in <i>ordinals</i> are siblings,
* potential nodes of the {@link FacetResult} tree
* (i.e., the descendants of the root node, no deeper than the specified depth).
- * No more than K ( = {@link FacetRequest#getNumResults()})
+ * No more than K ( = {@link FacetRequest#numResults})
* siblings are enumerated.
* @lucene.internal
*/
@@ -681,11 +677,6 @@ public class TopKInEachNodeHandler exten
}
@Override
- /**
- * Recursively label the first facetRequest.getNumLabel() sub results
- * of the root of a given {@link FacetResult}, or of an already labeled node in it.
- * I.e., a node is labeled only if it is the root or all its ancestors are labeled.
- */
public void labelResult(FacetResult facetResult) throws IOException {
if (facetResult == null) {
return; // any result to label?
@@ -700,10 +691,9 @@ public class TopKInEachNodeHandler exten
}
node.label = taxonomyReader.getPath(node.ordinal);
- // label the first numToLabel of these children, and recursively -- their children.
+ // recursively label the first numToLabel children of every node
int numLabeled = 0;
for (FacetResultNode frn : node.subResults) {
- // go over the children of node from first to last, no more than numToLable of them
recursivelyLabel(frn, numToLabel);
if (++numLabeled >= numToLabel) {
return;
@@ -719,7 +709,7 @@ public class TopKInEachNodeHandler exten
// so now we test and re-order if necessary.
public FacetResult rearrangeFacetResult(FacetResult facetResult) {
PriorityQueue<FacetResultNode> nodesHeap =
- new ResultNodeHeap(this.facetRequest.getNumResults(), this.getSuitableACComparator());
+ new ResultNodeHeap(this.facetRequest.numResults, this.getSuitableACComparator());
FacetResultNode topFrn = facetResult.getFacetResultNode();
rearrangeChilrenOfNode(topFrn, nodesHeap);
return facetResult;
Modified: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCounts.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCounts.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCounts.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCounts.java Thu Feb 7 21:32:27 2013
@@ -156,7 +156,7 @@ public class TotalFacetCounts {
final int[][] counts = new int[(int) Math.ceil(taxonomy.getSize() /(float) partitionSize)][partitionSize];
FacetSearchParams newSearchParams = new FacetSearchParams(facetIndexingParams, DUMMY_REQ);
//createAllListsSearchParams(facetIndexingParams, this.totalCounts);
- FacetsAccumulator fe = new StandardFacetsAccumulator(newSearchParams, indexReader, taxonomy) {
+ StandardFacetsAccumulator sfa = new StandardFacetsAccumulator(newSearchParams, indexReader, taxonomy) {
@Override
protected HashMap<CategoryListIterator, Aggregator> getCategoryListMap(
FacetArrays facetArrays, int partition) throws IOException {
@@ -169,8 +169,8 @@ public class TotalFacetCounts {
return map;
}
};
- fe.setComplementThreshold(FacetsAccumulator.DISABLE_COMPLEMENT);
- fe.accumulate(ScoredDocIdsUtils.createAllDocsScoredDocIDs(indexReader));
+ sfa.setComplementThreshold(StandardFacetsAccumulator.DISABLE_COMPLEMENT);
+ sfa.accumulate(ScoredDocIdsUtils.createAllDocsScoredDocIDs(indexReader));
return new TotalFacetCounts(taxonomy, facetIndexingParams, counts, CreationType.Computed);
}
Modified: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/CountFacetRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/CountFacetRequest.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/CountFacetRequest.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/CountFacetRequest.java Thu Feb 7 21:32:27 2013
@@ -31,15 +31,6 @@ import org.apache.lucene.facet.taxonomy.
*/
public class CountFacetRequest extends FacetRequest {
- /**
- * Create a count facet request for a given node in the taxonomy.
- *
- * @param path category path of the category of interest.
- * @param num number of child categories for which count info is requeted.
- * reqiested. Default implementation will find <b>top</b> categories, -
- * this behavior can be overridden by overriding
- * {@link #createFacetResultsHandler(TaxonomyReader)}.
- */
public CountFacetRequest(CategoryPath path, int num) {
super(path, num);
}
@@ -60,12 +51,8 @@ public class CountFacetRequest extends F
}
@Override
- public boolean supportsComplements() {
- return true;
+ public FacetArraysSource getFacetArraysSource() {
+ return FacetArraysSource.INT;
}
- @Override
- public boolean requireDocumentScore() {
- return false;
- }
}
Modified: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java Thu Feb 7 21:32:27 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() < 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/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java Thu Feb 7 21:32:27 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();
}
+
}
Copied: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/SumScoreFacetRequest.java (from r1442878, lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/ScoreFacetRequest.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/SumScoreFacetRequest.java?p2=lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/SumScoreFacetRequest.java&p1=lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/ScoreFacetRequest.java&r1=1442878&r2=1443736&rev=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/ScoreFacetRequest.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/SumScoreFacetRequest.java Thu Feb 7 21:32:27 2013
@@ -24,14 +24,15 @@ import org.apache.lucene.facet.taxonomy.
*/
/**
- * Facet request for weighting facets according to document scores.
+ * A {@link FacetRequest} for weighting facets by summing the scores of matching
+ * documents.
*
* @lucene.experimental
*/
-public class ScoreFacetRequest extends FacetRequest {
+public class SumScoreFacetRequest extends FacetRequest {
/** Create a score facet request for a given node in the taxonomy. */
- public ScoreFacetRequest(CategoryPath path, int num) {
+ public SumScoreFacetRequest(CategoryPath path, int num) {
super(path, num);
}
@@ -47,13 +48,8 @@ public class ScoreFacetRequest extends F
}
@Override
- public boolean supportsComplements() {
- return false;
+ public FacetArraysSource getFacetArraysSource() {
+ return FacetArraysSource.FLOAT;
}
-
- @Override
- public boolean requireDocumentScore() {
- return true;
- }
-
+
}
Modified: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationFloatSumFacetRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationFloatSumFacetRequest.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationFloatSumFacetRequest.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationFloatSumFacetRequest.java Thu Feb 7 21:32:27 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/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationIntSumFacetRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationIntSumFacetRequest.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationIntSumFacetRequest.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationIntSumFacetRequest.java Thu Feb 7 21:32:27 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/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java Thu Feb 7 21:32:27 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/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResultNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResultNode.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResultNode.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResultNode.java Thu Feb 7 21:32:27 2013
@@ -47,7 +47,7 @@ public class FacetResultNode {
* <p>
* <b>NOTE:</b> by default, all nodes are labeled. Only when
* {@link FacetRequest#getNumLabel()} <
- * {@link FacetRequest#getNumResults()} there will be unlabeled nodes.
+ * {@link FacetRequest#numResults} there will be unlabeled nodes.
*/
public CategoryPath label;
Modified: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java Thu Feb 7 21:32:27 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/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java Thu Feb 7 21:32:27 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/trunk/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/util/ResultSortUtils.java Thu Feb 7 21:32:27 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/trunk/lucene/facet/src/java/org/apache/lucene/facet/util/TaxonomyMergeUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/util/TaxonomyMergeUtils.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/util/TaxonomyMergeUtils.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/util/TaxonomyMergeUtils.java Thu Feb 7 21:32:27 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/trunk/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java (original)
+++ lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java Thu Feb 7 21:32:27 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/trunk/lucene/facet/src/test/org/apache/lucene/facet/index/OrdinalMappingReaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/index/OrdinalMappingReaderTest.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/index/OrdinalMappingReaderTest.java (original)
+++ lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/index/OrdinalMappingReaderTest.java Thu Feb 7 21:32:27 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/trunk/lucene/facet/src/test/org/apache/lucene/facet/index/TestFacetsPayloadMigrationReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/index/TestFacetsPayloadMigrationReader.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/index/TestFacetsPayloadMigrationReader.java (original)
+++ lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/index/TestFacetsPayloadMigrationReader.java Thu Feb 7 21:32:27 2013
@@ -268,7 +268,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/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/AdaptiveAccumulatorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/AdaptiveAccumulatorTest.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/AdaptiveAccumulatorTest.java (original)
+++ lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/AdaptiveAccumulatorTest.java Thu Feb 7 21:32:27 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);
Copied: lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsAggregatorTest.java (from r1442490, lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsCollectorTest.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsAggregatorTest.java?p2=lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsAggregatorTest.java&p1=lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsCollectorTest.java&r1=1442490&r2=1443736&rev=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsCollectorTest.java (original)
+++ lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsAggregatorTest.java Thu Feb 7 21:32:27 2013
@@ -20,11 +20,7 @@ import org.apache.lucene.facet.index.par
import org.apache.lucene.facet.index.params.FacetIndexingParams;
import org.apache.lucene.facet.index.params.PerDimensionOrdinalPolicy;
import org.apache.lucene.facet.search.params.CountFacetRequest;
-import org.apache.lucene.facet.search.params.FacetRequest;
-import org.apache.lucene.facet.search.params.FacetRequest.SortBy;
-import org.apache.lucene.facet.search.params.FacetRequest.SortOrder;
import org.apache.lucene.facet.search.params.FacetSearchParams;
-import org.apache.lucene.facet.search.params.ScoreFacetRequest;
import org.apache.lucene.facet.search.results.FacetResult;
import org.apache.lucene.facet.search.results.FacetResultNode;
import org.apache.lucene.facet.taxonomy.CategoryPath;
@@ -33,6 +29,7 @@ import org.apache.lucene.facet.taxonomy.
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.NoMergePolicy;
@@ -43,8 +40,6 @@ import org.apache.lucene.search.TermQuer
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.collections.ObjectToIntMap;
-import org.apache.lucene.util.encoding.IntEncoder;
-import org.apache.lucene.util.encoding.VInt8IntEncoder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -66,7 +61,7 @@ import org.junit.Test;
* limitations under the License.
*/
-public class CountingFacetsCollectorTest extends FacetTestCase {
+public class CountingFacetsAggregatorTest extends FacetTestCase {
private static final Term A = new Term("f", "a");
private static final CategoryPath CP_A = new CategoryPath("A"), CP_B = new CategoryPath("B");
@@ -104,7 +99,7 @@ public class CountingFacetsCollectorTest
private static FacetIndexingParams fip;
@AfterClass
- public static void afterClassCountingFacetsCollectorTest() throws Exception {
+ public static void afterClassCountingFacetsAggregatorTest() throws Exception {
IOUtils.close(indexDir, taxoDir);
}
@@ -237,7 +232,7 @@ public class CountingFacetsCollectorTest
}
@BeforeClass
- public static void beforeClassCountingFacetsCollectorTest() throws Exception {
+ public static void beforeClassCountingFacetsAggregatorTest() throws Exception {
indexDir = newDirectory();
taxoDir = newDirectory();
@@ -277,72 +272,16 @@ public class CountingFacetsCollectorTest
IOUtils.close(indexWriter, taxoWriter);
}
- @Test
- public void testInvalidParams() throws Exception {
- final CategoryPath dummyCP = new CategoryPath("a");
- final FacetRequest dummyFR = new CountFacetRequest(dummyCP, 10);
-
- // only CountFacetRequests are allowed
- assertNotNull("only CountFacetRequests should be allowed",
- CountingFacetsCollector.assertParams(new FacetSearchParams(new ScoreFacetRequest(dummyCP, 10))));
-
- // only depth=1
- FacetRequest cfr = new CountFacetRequest(dummyCP, 10);
- cfr.setDepth(2);
- assertNotNull("only depth 1 should be allowed", CountingFacetsCollector.assertParams(new FacetSearchParams(cfr)));
-
- // only SortOrder.DESCENDING
- cfr = new CountFacetRequest(dummyCP, 10);
- cfr.setSortOrder(SortOrder.ASCENDING);
- assertNotNull("only SortOrder.DESCENDING should be allowed", CountingFacetsCollector.assertParams(new FacetSearchParams(cfr)));
-
- // only SortBy.VALUE
- cfr = new CountFacetRequest(dummyCP, 10);
- cfr.setSortBy(SortBy.ORDINAL);
- assertNotNull("only SortBy.VALUE should be allowed", CountingFacetsCollector.assertParams(new FacetSearchParams(cfr)));
-
- // no numToLabel
- cfr = new CountFacetRequest(dummyCP, 10);
- cfr.setNumLabel(2);
- assertNotNull("numToLabel should not be allowed", CountingFacetsCollector.assertParams(new FacetSearchParams(cfr)));
-
- FacetIndexingParams fip = new FacetIndexingParams() {
+ private FacetsAccumulator randomAccumulator(FacetSearchParams fsp, IndexReader indexReader, TaxonomyReader taxoReader) {
+ final FacetsAggregator aggregator = random().nextBoolean() ? new CountingFacetsAggregator() : new FastCountingFacetsAggregator();
+ return new FacetsAccumulator(fsp, indexReader, taxoReader) {
@Override
- public CategoryListParams getCategoryListParams(CategoryPath category) {
- return new CategoryListParams();
+ public FacetsAggregator getAggregator() {
+ return aggregator;
}
};
- assertNotNull("only one CLP should be allowed", CountingFacetsCollector.assertParams(new FacetSearchParams(fip, dummyFR,
- new CountFacetRequest(new CategoryPath("moo"), 10))));
-
- fip = new FacetIndexingParams(new CategoryListParams("moo")) {
- final CategoryListParams clp = new CategoryListParams() {
- @Override
- public IntEncoder createEncoder() {
- return new VInt8IntEncoder();
- }
- };
- @Override
- public List<CategoryListParams> getAllCategoryListParams() {
- return Collections.singletonList(clp);
- }
-
- @Override
- public CategoryListParams getCategoryListParams(CategoryPath category) {
- return clp;
- }
- };
- assertNotNull("only DGapVIntEncoder should be allowed", CountingFacetsCollector.assertParams(new FacetSearchParams(fip, dummyFR)));
-
- fip = new FacetIndexingParams(new CategoryListParams("moo")) {
- @Override
- public int getPartitionSize() {
- return 2;
- }
- };
- assertNotNull("partitions should be allowed", CountingFacetsCollector.assertParams(new FacetSearchParams(fip, dummyFR)));
}
-
+
@Test
public void testDifferentNumResults() throws Exception {
// test the collector w/ FacetRequests and different numResults
@@ -352,7 +291,7 @@ public class CountingFacetsCollectorTest
FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(CP_A, NUM_CHILDREN_CP_A),
new CountFacetRequest(CP_B, NUM_CHILDREN_CP_B));
- FacetsCollector fc = new CountingFacetsCollector(fsp , taxoReader);
+ FacetsCollector fc = FacetsCollector.create(randomAccumulator(fsp, indexReader, taxoReader));
TermQuery q = new TermQuery(A);
searcher.search(q, fc);
@@ -377,7 +316,7 @@ public class CountingFacetsCollectorTest
FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(CP_A, NUM_CHILDREN_CP_A),
new CountFacetRequest(CP_B, NUM_CHILDREN_CP_B));
- FacetsCollector fc = new CountingFacetsCollector(fsp , taxoReader);
+ FacetsCollector fc = FacetsCollector.create(randomAccumulator(fsp, indexReader, taxoReader));
searcher.search(new MatchAllDocsQuery(), fc);
List<FacetResult> facetResults = fc.getFacetResults();
@@ -409,7 +348,7 @@ public class CountingFacetsCollectorTest
FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(CP_A, Integer.MAX_VALUE),
new CountFacetRequest(CP_B, Integer.MAX_VALUE));
- FacetsCollector fc = new CountingFacetsCollector(fsp , taxoReader);
+ FacetsCollector fc = FacetsCollector.create(randomAccumulator(fsp, indexReader, taxoReader));
searcher.search(new MatchAllDocsQuery(), fc);
List<FacetResult> facetResults = fc.getFacetResults();
@@ -426,37 +365,13 @@ public class CountingFacetsCollectorTest
}
@Test
- public void testDirectSource() throws Exception {
- DirectoryReader indexReader = DirectoryReader.open(indexDir);
- TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
- IndexSearcher searcher = new IndexSearcher(indexReader);
-
- FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(CP_A, NUM_CHILDREN_CP_A),
- new CountFacetRequest(CP_B, NUM_CHILDREN_CP_B));
- FacetsCollector fc = new CountingFacetsCollector(fsp , taxoReader, new FacetArrays(taxoReader.getSize()), true);
- searcher.search(new MatchAllDocsQuery(), fc);
-
- List<FacetResult> facetResults = fc.getFacetResults();
- assertEquals("invalid number of facet results", 2, facetResults.size());
- for (FacetResult res : facetResults) {
- FacetResultNode root = res.getFacetResultNode();
- assertEquals("wrong count for " + root.label, allExpectedCounts.get(root.label), (int) root.value);
- for (FacetResultNode child : root.subResults) {
- assertEquals("wrong count for " + child.label, allExpectedCounts.get(child.label), (int) child.value);
- }
- }
-
- IOUtils.close(indexReader, taxoReader);
- }
-
- @Test
public void testNoParents() throws Exception {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
IndexSearcher searcher = new IndexSearcher(indexReader);
FacetSearchParams fsp = new FacetSearchParams(fip, new CountFacetRequest(CP_C, NUM_CHILDREN_CP_C),
new CountFacetRequest(CP_D, NUM_CHILDREN_CP_D));
- FacetsCollector fc = new CountingFacetsCollector(fsp , taxoReader);
+ FacetsCollector fc = FacetsCollector.create(randomAccumulator(fsp, indexReader, taxoReader));
searcher.search(new MatchAllDocsQuery(), fc);
List<FacetResult> facetResults = fc.getFacetResults();
Modified: lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/SamplingWrapperTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/SamplingWrapperTest.java?rev=1443736&r1=1443735&r2=1443736&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/SamplingWrapperTest.java (original)
+++ lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/search/SamplingWrapperTest.java Thu Feb 7 21:32:27 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);
}
}