You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2013/01/18 19:31:23 UTC
svn commit: r1435287 [14/41] - in /lucene/dev/branches/LUCENE-2878: ./
dev-tools/ dev-tools/eclipse/ dev-tools/idea/.idea/libraries/
dev-tools/idea/lucene/analysis/icu/ dev-tools/maven/
dev-tools/maven/lucene/benchmark/ dev-tools/maven/solr/ dev-tools/...
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java Fri Jan 18 18:30:54 2013
@@ -4,16 +4,15 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import org.apache.lucene.util.PriorityQueue;
-
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.MutableFacetResultNode;
import org.apache.lucene.facet.search.results.IntermediateFacetResult;
-import org.apache.lucene.facet.taxonomy.ChildrenArrays;
+import org.apache.lucene.facet.search.results.MutableFacetResultNode;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
+import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays;
+import org.apache.lucene.util.PriorityQueue;
import org.apache.lucene.util.collections.IntIterator;
import org.apache.lucene.util.collections.IntToObjectMap;
@@ -35,35 +34,37 @@ import org.apache.lucene.util.collection
*/
/**
- * Generates {@link FacetResult} from the count arrays 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#getCategoryPath()},
- * and the enumerated children, {@link FacetResultNode#getSubResults()}, 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()}.
+ * Generates {@link FacetResult} from the count arrays 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#getSubResults()}, 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()}.
* <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
+ * 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
* into {@link FacetResult} might have better values, or ordinals, (typically,
* higher counts), than facets that are selected into the {@link FacetResult}.
* <p>
- * The generated {@link FacetResult} also provides with
- * {@link FacetResult#getNumValidDescendants()}, which returns the total number of facets
- * that are descendants of the root node, no deeper than {@link FacetRequest#getDepth()}, and
- * which have valid value. The rootnode itself is not counted here.
- * Valid value is determined by the {@link FacetResultsHandler}.
- * {@link TopKInEachNodeHandler} defines valid as != 0.
+ * The generated {@link FacetResult} also provides with
+ * {@link FacetResult#getNumValidDescendants()}, which returns the total number
+ * of facets that are descendants of the root node, no deeper than
+ * {@link FacetRequest#getDepth()}, and which have valid value. The rootnode
+ * itself is not counted here. Valid value is determined by the
+ * {@link FacetResultsHandler}. {@link TopKInEachNodeHandler} defines valid as
+ * != 0.
* <p>
- * <b>NOTE:</b> this code relies on the assumption that {@link TaxonomyReader#INVALID_ORDINAL} == -1, a smaller
- * value than any valid ordinal.
+ * <b>NOTE:</b> this code relies on the assumption that
+ * {@link TaxonomyReader#INVALID_ORDINAL} == -1, a smaller value than any valid
+ * ordinal.
*
* @lucene.experimental
*/
@@ -110,7 +111,7 @@ public class TopKInEachNodeHandler exten
// 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).
- int rootNode = this.taxonomyReader.getOrdinal(this.facetRequest.getCategoryPath());
+ int rootNode = this.taxonomyReader.getOrdinal(facetRequest.categoryPath);
if (rootNode == TaxonomyReader.INVALID_ORDINAL) {
return null;
}
@@ -120,7 +121,7 @@ public class TopKInEachNodeHandler exten
// this will grow into the returned IntermediateFacetResult
IntToObjectMap<AACO> AACOsOfOnePartition = new IntToObjectMap<AACO>();
- int partitionSize = arrays.getArraysLength(); // all partitions, except, possibly, the last,
+ int partitionSize = arrays.arrayLength; // all partitions, except, possibly, the last,
// have the same length. Hence modulo is OK.
int depth = facetRequest.getDepth();
@@ -141,9 +142,9 @@ public class TopKInEachNodeHandler exten
}
int endOffset = offset + partitionSize; // one past the largest ordinal in the partition
- ChildrenArrays childrenArray = taxonomyReader.getChildrenArrays();
- int[] youngestChild = childrenArray.getYoungestChildArray();
- int[] olderSibling = childrenArray.getOlderSiblingArray();
+ ParallelTaxonomyArrays childrenArray = taxonomyReader.getParallelTaxonomyArrays();
+ int[] children = childrenArray.children();
+ int[] siblings = childrenArray.siblings();
int totalNumOfDescendantsConsidered = 0; // total number of facets with value != 0,
// in the tree. These include those selected as top K in each node, and all the others that
// were not. Not including rootNode
@@ -217,7 +218,7 @@ public class TopKInEachNodeHandler exten
* we can continue to the older sibling of rootNode once the localDepth goes down, before we verify that
* it went that down)
*/
- ordinalStack[++localDepth] = youngestChild[rootNode];
+ ordinalStack[++localDepth] = children[rootNode];
siblingExplored[localDepth] = Integer.MAX_VALUE; // we have not verified position wrt current partition
siblingExplored[0] = -1; // as if rootNode resides to the left of current position
@@ -238,7 +239,7 @@ public class TopKInEachNodeHandler exten
// its child, now just removed, would not have been pushed on it.
// so the father is either inside the partition, or smaller ordinal
if (siblingExplored[localDepth] < 0 ) {
- ordinalStack[localDepth] = olderSibling[ordinalStack[localDepth]];
+ ordinalStack[localDepth] = siblings[ordinalStack[localDepth]];
continue;
}
// in this point, siblingExplored[localDepth] between 0 and number of bestSiblings
@@ -264,7 +265,7 @@ public class TopKInEachNodeHandler exten
//tosOrdinal was not examined yet for its position relative to current partition
// and the best K of current partition, among its siblings, have not been determined yet
while (tosOrdinal >= endOffset) {
- tosOrdinal = olderSibling[tosOrdinal];
+ tosOrdinal = siblings[tosOrdinal];
}
// now it is inside. Run it and all its siblings inside the partition through a heap
// and in doing so, count them, find best K, and sum into residue
@@ -297,12 +298,12 @@ public class TopKInEachNodeHandler exten
// update totalNumOfDescendants by the now excluded node and all its descendants
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, youngestChild,
- olderSibling, arrays, partitionSize, offset, endOffset, localDepth, depth);
+ totalNumOfDescendantsConsidered += countOnly (ac.ordinal, children,
+ siblings, arrays, partitionSize, offset, endOffset, localDepth, depth);
reusables[++tosReuslables] = ac;
}
}
- tosOrdinal = olderSibling[tosOrdinal];
+ tosOrdinal = siblings[tosOrdinal];
}
// now pq has best K children of ordinals that belong to the given partition.
// Populate a new AACO with them.
@@ -343,7 +344,7 @@ public class TopKInEachNodeHandler exten
ordinalStack[++localDepth] = TaxonomyReader.INVALID_ORDINAL;
continue;
}
- ordinalStack[++localDepth] = youngestChild[tosOrdinal];
+ ordinalStack[++localDepth] = children[tosOrdinal];
siblingExplored[localDepth] = Integer.MAX_VALUE;
} // endof loop while stack is not empty
@@ -592,7 +593,7 @@ public class TopKInEachNodeHandler exten
@Override
protected boolean leftGoesNow (int ord1, double val1, int ord2, double val2) {
- return (val1 < val2);
+ return (val1 == val2) ? (ord1 < ord2) : (val1 < val2);
}
}
@@ -602,7 +603,7 @@ public class TopKInEachNodeHandler exten
@Override
protected boolean leftGoesNow (int ord1, double val1, int ord2, double val2) {
- return (val1 > val2);
+ return (val1 == val2) ? (ord1 > ord2) : (val1 > val2);
}
}
@@ -656,6 +657,7 @@ public class TopKInEachNodeHandler exten
this.totalNumOfFacetsConsidered = 0;
}
+ @Override
public FacetRequest getFacetRequest() {
return this.facetRequest;
}
@@ -767,7 +769,7 @@ public class TopKInEachNodeHandler exten
@Override
public FacetResult renderFacetResult(IntermediateFacetResult tmpResult) throws IOException {
IntermediateFacetResultWithHash tmp = (IntermediateFacetResultWithHash) tmpResult;
- int ordinal = this.taxonomyReader.getOrdinal(this.facetRequest.getCategoryPath());
+ int ordinal = this.taxonomyReader.getOrdinal(this.facetRequest.categoryPath);
if ((tmp == null) || (ordinal == TaxonomyReader.INVALID_ORDINAL)) {
return null;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCounts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCounts.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCounts.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCounts.java Fri Jan 18 18:30:54 2013
@@ -8,21 +8,23 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.lucene.index.IndexReader;
-
import org.apache.lucene.facet.index.params.CategoryListParams;
import org.apache.lucene.facet.index.params.FacetIndexingParams;
import org.apache.lucene.facet.search.aggregator.Aggregator;
import org.apache.lucene.facet.search.aggregator.CountingAggregator;
-import org.apache.lucene.facet.search.cache.CategoryListCache;
-import org.apache.lucene.facet.search.cache.CategoryListData;
+import org.apache.lucene.facet.search.params.CountFacetRequest;
+import org.apache.lucene.facet.search.params.FacetRequest;
import org.apache.lucene.facet.search.params.FacetSearchParams;
+import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.util.PartitionsUtils;
import org.apache.lucene.facet.util.ScoredDocIdsUtils;
+import org.apache.lucene.index.IndexReader;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -146,13 +148,16 @@ public class TotalFacetCounts {
dos.close();
}
}
+
+ // needed because FacetSearchParams do not allow empty FacetRequests
+ private static final List<FacetRequest> DUMMY_REQ = Arrays.asList(
+ new FacetRequest[] { new CountFacetRequest(CategoryPath.EMPTY, 1) });
- static TotalFacetCounts compute(final IndexReader indexReader,
- final TaxonomyReader taxonomy, final FacetIndexingParams facetIndexingParams,
- final CategoryListCache clCache) throws IOException {
+ static TotalFacetCounts compute(final IndexReader indexReader, final TaxonomyReader taxonomy,
+ final FacetIndexingParams facetIndexingParams) throws IOException {
int partitionSize = PartitionsUtils.partitionSize(facetIndexingParams, taxonomy);
final int[][] counts = new int[(int) Math.ceil(taxonomy.getSize() /(float) partitionSize)][partitionSize];
- FacetSearchParams newSearchParams = new FacetSearchParams(facetIndexingParams);
+ FacetSearchParams newSearchParams = new FacetSearchParams(DUMMY_REQ, facetIndexingParams);
//createAllListsSearchParams(facetIndexingParams, this.totalCounts);
FacetsAccumulator fe = new StandardFacetsAccumulator(newSearchParams, indexReader, taxonomy) {
@Override
@@ -162,8 +167,7 @@ public class TotalFacetCounts {
Aggregator aggregator = new CountingAggregator(counts[partition]);
HashMap<CategoryListIterator, Aggregator> map = new HashMap<CategoryListIterator, Aggregator>();
for (CategoryListParams clp: facetIndexingParams.getAllCategoryListParams()) {
- final CategoryListIterator cli = clIteraor(clCache, clp, indexReader, partition);
- map.put(cli, aggregator);
+ map.put(clp.createCategoryListIterator(partition), aggregator);
}
return map;
}
@@ -173,14 +177,4 @@ public class TotalFacetCounts {
return new TotalFacetCounts(taxonomy, facetIndexingParams, counts, CreationType.Computed);
}
- static CategoryListIterator clIteraor(CategoryListCache clCache, CategoryListParams clp,
- IndexReader indexReader, int partition) throws IOException {
- if (clCache != null) {
- CategoryListData cld = clCache.get(clp);
- if (cld != null) {
- return cld.iterator(partition);
- }
- }
- return clp.createCategoryListIterator(indexReader, partition);
- }
}
\ No newline at end of file
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCountsCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCountsCache.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCountsCache.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/TotalFacetCountsCache.java Fri Jan 18 18:30:54 2013
@@ -7,12 +7,10 @@ import java.util.LinkedHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
-import org.apache.lucene.index.IndexReader;
-
import org.apache.lucene.facet.index.params.CategoryListParams;
import org.apache.lucene.facet.index.params.FacetIndexingParams;
-import org.apache.lucene.facet.search.cache.CategoryListCache;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
+import org.apache.lucene.index.IndexReader;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -80,16 +78,20 @@ public final class TotalFacetCountsCache
}
/**
- * Get the total facet counts for a reader/taxonomy pair and facet indexing parameters.
- * If not in cache, computed here and added to the cache for later use.
- * @param indexReader the documents index
- * @param taxonomy the taxonomy index
- * @param facetIndexingParams facet indexing parameters
- * @param clCache category list cache for faster computation, can be null
+ * Get the total facet counts for a reader/taxonomy pair and facet indexing
+ * parameters. If not in cache, computed here and added to the cache for later
+ * use.
+ *
+ * @param indexReader
+ * the documents index
+ * @param taxonomy
+ * the taxonomy index
+ * @param facetIndexingParams
+ * facet indexing parameters
* @return the total facet counts.
*/
public TotalFacetCounts getTotalCounts(IndexReader indexReader, TaxonomyReader taxonomy,
- FacetIndexingParams facetIndexingParams, CategoryListCache clCache) throws IOException {
+ FacetIndexingParams facetIndexingParams) throws IOException {
// create the key
TFCKey key = new TFCKey(indexReader, taxonomy, facetIndexingParams);
// it is important that this call is not synchronized, so that available TFC
@@ -99,7 +101,7 @@ public final class TotalFacetCountsCache
markRecentlyUsed(key);
return tfc;
}
- return computeAndCache(key, clCache);
+ return computeAndCache(key);
}
/**
@@ -149,10 +151,10 @@ public final class TotalFacetCountsCache
* matter this method is synchronized, which is not too bad, because there is
* lots of work done in the computations.
*/
- private synchronized TotalFacetCounts computeAndCache(TFCKey key, CategoryListCache clCache) throws IOException {
+ private synchronized TotalFacetCounts computeAndCache(TFCKey key) throws IOException {
TotalFacetCounts tfc = cache.get(key);
if (tfc == null) {
- tfc = TotalFacetCounts.compute(key.indexReader, key.taxonomy, key.facetIndexingParams, clCache);
+ tfc = TotalFacetCounts.compute(key.indexReader, key.taxonomy, key.facetIndexingParams);
lruKeys.add(key);
cache.put(key,tfc);
trimCache();
@@ -161,16 +163,22 @@ public final class TotalFacetCountsCache
}
/**
- * Load {@link TotalFacetCounts} matching input parameters from the provided outputFile
- * and add them into the cache for the provided indexReader, taxonomy, and facetIndexingParams.
- * If a {@link TotalFacetCounts} for these parameters already exists in the cache, it will be
- * replaced by the loaded one.
- * @param inputFile file from which to read the data
- * @param indexReader the documents index
- * @param taxonomy the taxonomy index
- * @param facetIndexingParams the facet indexing parameters
- * @throws IOException on error
- * @see #store(File, IndexReader, TaxonomyReader, FacetIndexingParams, CategoryListCache)
+ * Load {@link TotalFacetCounts} matching input parameters from the provided
+ * outputFile and add them into the cache for the provided indexReader,
+ * taxonomy, and facetIndexingParams. If a {@link TotalFacetCounts} for these
+ * parameters already exists in the cache, it will be replaced by the loaded
+ * one.
+ *
+ * @param inputFile
+ * file from which to read the data
+ * @param indexReader
+ * the documents index
+ * @param taxonomy
+ * the taxonomy index
+ * @param facetIndexingParams
+ * the facet indexing parameters
+ * @throws IOException
+ * on error
*/
public synchronized void load(File inputFile, IndexReader indexReader, TaxonomyReader taxonomy,
FacetIndexingParams facetIndexingParams) throws IOException {
@@ -185,21 +193,27 @@ public final class TotalFacetCountsCache
}
/**
- * Store the {@link TotalFacetCounts} matching input parameters into the provided outputFile,
- * making them available for a later call to {@link #load(File, IndexReader, TaxonomyReader, FacetIndexingParams)}.
- * If these {@link TotalFacetCounts} are available in the cache, they are used. But if they are
- * not in the cache, this call will first compute them (which will also add them to the cache).
- * @param outputFile file to store in.
- * @param indexReader the documents index
- * @param taxonomy the taxonomy index
- * @param facetIndexingParams the facet indexing parameters
- * @param clCache category list cache for faster computation, can be null
- * @throws IOException on error
+ * Store the {@link TotalFacetCounts} matching input parameters into the
+ * provided outputFile, making them available for a later call to
+ * {@link #load(File, IndexReader, TaxonomyReader, FacetIndexingParams)}. If
+ * these {@link TotalFacetCounts} are available in the cache, they are used.
+ * But if they are not in the cache, this call will first compute them (which
+ * will also add them to the cache).
+ *
+ * @param outputFile
+ * file to store in.
+ * @param indexReader
+ * the documents index
+ * @param taxonomy
+ * the taxonomy index
+ * @param facetIndexingParams
+ * the facet indexing parameters
+ * @throws IOException
+ * on error
* @see #load(File, IndexReader, TaxonomyReader, FacetIndexingParams)
- * @see #getTotalCounts(IndexReader, TaxonomyReader, FacetIndexingParams, CategoryListCache)
*/
public void store(File outputFile, IndexReader indexReader, TaxonomyReader taxonomy,
- FacetIndexingParams facetIndexingParams, CategoryListCache clCache) throws IOException {
+ FacetIndexingParams facetIndexingParams) throws IOException {
File parentFile = outputFile.getParentFile();
if (
( outputFile.exists() && (!outputFile.isFile() || !outputFile.canWrite())) ||
@@ -207,7 +221,7 @@ public final class TotalFacetCountsCache
) {
throw new IllegalArgumentException("Exepecting a writable file: "+outputFile);
}
- TotalFacetCounts tfc = getTotalCounts(indexReader, taxonomy, facetIndexingParams, clCache);
+ TotalFacetCounts tfc = getTotalCounts(indexReader, taxonomy, facetIndexingParams);
TotalFacetCounts.storeToFile(outputFile, tfc);
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/Aggregator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/Aggregator.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/Aggregator.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/Aggregator.java Fri Jan 18 18:30:54 2013
@@ -2,6 +2,9 @@ package org.apache.lucene.facet.search.a
import java.io.IOException;
+import org.apache.lucene.index.AtomicReaderContext;
+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
@@ -20,32 +23,26 @@ import java.io.IOException;
*/
/**
- * An Aggregator is the analogue of Lucene's Collector (see
- * {@link org.apache.lucene.search.Collector}), for processing the categories
- * belonging to a certain document. The Aggregator is responsible for doing
- * whatever it wishes with the categories it is fed, e.g., counting the number
- * of times that each category appears, or performing some computation on their
- * association values.
- * <P>
- * Much of the function of an Aggregator implementation is not described by this
- * interface. This includes the constructor and getter methods to retrieve the
- * results of the aggregation.
+ * Aggregates the categories of documents given to
+ * {@link #aggregate(int, float, IntsRef)}. Note that the document IDs are local
+ * to the reader given to {@link #setNextReader(AtomicReaderContext)}.
*
* @lucene.experimental
*/
public interface Aggregator {
/**
- * Specify the document (and its score in the search) that the following
- * {@link #aggregate(int)} calls will pertain to.
+ * Sets the {@link AtomicReaderContext} for which
+ * {@link #aggregate(int, float, IntsRef)} calls will be made. If this method
+ * returns false, {@link #aggregate(int, float, IntsRef)} should not be called
+ * for this reader.
*/
- void setNextDoc(int docid, float score) throws IOException;
-
+ public boolean setNextReader(AtomicReaderContext context) throws IOException;
+
/**
- * Collect (and do whatever an implementation deems appropriate) the
- * category given by its ordinal. This category belongs to a document
- * given earlier by {@link #setNextDoc(int, float)}.
+ * Aggregate the ordinals of the given document ID (and its score). The given
+ * ordinals offset is always zero.
*/
- void aggregate(int ordinal);
-
+ public void aggregate(int docID, float score, IntsRef ordinals) throws IOException;
+
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/ComplementCountingAggregator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/ComplementCountingAggregator.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/ComplementCountingAggregator.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/ComplementCountingAggregator.java Fri Jan 18 18:30:54 2013
@@ -1,5 +1,9 @@
package org.apache.lucene.facet.search.aggregator;
+import java.io.IOException;
+
+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
@@ -29,9 +33,12 @@ public class ComplementCountingAggregato
}
@Override
- public void aggregate(int ordinal) {
- assert counterArray[ordinal]!=0:"complement aggregation: count is about to become negative for ordinal "+ordinal;
- --counterArray[ordinal];
+ public void aggregate(int docID, float score, IntsRef ordinals) throws IOException {
+ for (int i = 0; i < ordinals.length; i++) {
+ int ord = ordinals.ints[i];
+ assert counterArray[ord] != 0 : "complement aggregation: count is about to become negative for ordinal " + ord;
+ --counterArray[ord];
+ }
}
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/CountingAggregator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/CountingAggregator.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/CountingAggregator.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/CountingAggregator.java Fri Jan 18 18:30:54 2013
@@ -1,5 +1,10 @@
package org.apache.lucene.facet.search.aggregator;
+import java.io.IOException;
+
+import org.apache.lucene.index.AtomicReaderContext;
+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
@@ -27,19 +32,17 @@ package org.apache.lucene.facet.search.a
public class CountingAggregator implements Aggregator {
protected int[] counterArray;
-
- public void aggregate(int ordinal) {
- ++counterArray[ordinal];
- }
-
- public void setNextDoc(int docid, float score) {
- // There's nothing for us to do here since we only increment the count by 1
- // in this aggregator.
- }
-
+
public CountingAggregator(int[] counterArray) {
this.counterArray = counterArray;
}
+
+ @Override
+ public void aggregate(int docID, float score, IntsRef ordinals) throws IOException {
+ for (int i = 0; i < ordinals.length; i++) {
+ counterArray[ordinals.ints[i]]++;
+ }
+ }
@Override
public boolean equals(Object obj) {
@@ -52,8 +55,12 @@ public class CountingAggregator implemen
@Override
public int hashCode() {
- int hashCode = counterArray == null ? 0 : counterArray.hashCode();
-
- return hashCode;
+ return counterArray == null ? 0 : counterArray.hashCode();
+ }
+
+ @Override
+ public boolean setNextReader(AtomicReaderContext context) throws IOException {
+ return true;
}
+
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/ScoringAggregator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/ScoringAggregator.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/ScoringAggregator.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/ScoringAggregator.java Fri Jan 18 18:30:54 2013
@@ -1,5 +1,10 @@
package org.apache.lucene.facet.search.aggregator;
+import java.io.IOException;
+
+import org.apache.lucene.index.AtomicReaderContext;
+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
@@ -26,7 +31,6 @@ package org.apache.lucene.facet.search.a
public class ScoringAggregator implements Aggregator {
private final float[] scoreArray;
- private float score;
private final int hashCode;
public ScoringAggregator(float[] counterArray) {
@@ -34,10 +38,13 @@ public class ScoringAggregator implement
this.hashCode = scoreArray == null ? 0 : scoreArray.hashCode();
}
- public void aggregate(int ordinal) {
- scoreArray[ordinal] += score;
+ @Override
+ public void aggregate(int docID, float score, IntsRef ordinals) throws IOException {
+ for (int i = 0; i < ordinals.length; i++) {
+ scoreArray[ordinals.ints[i]] += score;
+ }
}
-
+
@Override
public boolean equals(Object obj) {
if (obj == null || obj.getClass() != this.getClass()) {
@@ -52,7 +59,9 @@ public class ScoringAggregator implement
return hashCode;
}
- public void setNextDoc(int docid, float score) {
- this.score = score;
+ @Override
+ public boolean setNextReader(AtomicReaderContext context) throws IOException {
+ return true;
}
+
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/CountFacetRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/CountFacetRequest.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/CountFacetRequest.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/CountFacetRequest.java Fri Jan 18 18:30:54 2013
@@ -1,7 +1,5 @@
package org.apache.lucene.facet.search.params;
-import org.apache.lucene.index.IndexReader;
-
import org.apache.lucene.facet.search.FacetArrays;
import org.apache.lucene.facet.search.aggregator.Aggregator;
import org.apache.lucene.facet.search.aggregator.ComplementCountingAggregator;
@@ -47,9 +45,7 @@ public class CountFacetRequest extends F
}
@Override
- public Aggregator createAggregator(boolean useComplements,
- FacetArrays arrays, IndexReader reader,
- TaxonomyReader taxonomy) {
+ public Aggregator createAggregator(boolean useComplements, FacetArrays arrays, TaxonomyReader taxonomy) {
// we rely on that, if needed, result is cleared by arrays!
int[] a = arrays.getIntArray();
if (useComplements) {
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java Fri Jan 18 18:30:54 2013
@@ -2,17 +2,11 @@ package org.apache.lucene.facet.search.p
import java.io.IOException;
-import org.apache.lucene.index.IndexReader;
-
-import org.apache.lucene.facet.index.params.CategoryListParams;
-import org.apache.lucene.facet.search.CategoryListIterator;
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.search.cache.CategoryListData;
-import org.apache.lucene.facet.search.cache.CategoryListCache;
import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
@@ -64,9 +58,9 @@ public abstract class FacetRequest imple
* Default result mode
* @see #getResultMode()
*/
- public static final ResultMode DEFAULT_RESULT_MODE = ResultMode.GLOBAL_FLAT;
+ public static final ResultMode DEFAULT_RESULT_MODE = ResultMode.PER_NODE_IN_TREE;
- private final CategoryPath categoryPath;
+ public final CategoryPath categoryPath;
private final int numResults;
private int numLabel;
private int depth;
@@ -136,17 +130,6 @@ public abstract class FacetRequest imple
}
/**
- * The root category of this facet request. The categories that are returned
- * as a result of this request will all be descendants of this root.
- * <p>
- * <b>NOTE:</b> you should not modify the returned {@link CategoryPath}, or
- * otherwise some methonds may not work properly, e.g. {@link #hashCode()}.
- */
- public final CategoryPath getCategoryPath() {
- return categoryPath;
- }
-
- /**
* How deeply to look under the given category. If the depth is 0,
* 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,
@@ -162,24 +145,22 @@ public abstract class FacetRequest imple
* will have their category paths calculated, and the rest will only be
* available as ordinals (category numbers) and will have null paths.
* <P>
- * If Integer.MAX_VALUE is specified, all
- * results are labled.
+ * If Integer.MAX_VALUE is specified, all results are labled.
* <P>
- * The purpose of this parameter is to avoid having to run the whole
- * faceted search again when the user asks for more values for the facet;
- * The application can ask (getNumResults()) for more values than it needs
- * to show, but keep getNumLabel() only the number it wants to immediately
- * show. The slow-down caused by finding more values is negligible, because
- * the slowest part - finding the categories' paths, is avoided.
+ * The purpose of this parameter is to avoid having to run the whole faceted
+ * search again when the user asks for more values for the facet; The
+ * application can ask (getNumResults()) for more values than it needs to
+ * show, but keep getNumLabel() only the number it wants to immediately show.
+ * The slow-down caused by finding more values is negligible, because the
+ * slowest part - finding the categories' paths, is avoided.
* <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 labeled.
- * In the per-node mode, if this limit is 3,
- * 3 top children of {@link #getCategoryPath() the target category} would be labeled,
- * as well as 3 top children of each of them, and so forth, until the depth defined
- * by {@link #getDepth()}.
+ * 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 labeled. In the per-node mode, if this limit is 3, 3
+ * top children of {@link #categoryPath the target category} would be labeled,
+ * 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 getNumLabel() {
@@ -187,20 +168,18 @@ public abstract class FacetRequest imple
}
/**
- * The number of sub-categories to return (at most).
- * If the sub-categories are returned.
+ * 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.
+ * 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 #getCategoryPath() 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()}.
+ * 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() {
@@ -314,34 +293,12 @@ public abstract class FacetRequest imple
* computation.
* @param arrays
* provider for facet arrays in use for current computation.
- * @param indexReader
- * index reader in effect.
* @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, IndexReader indexReader,
- TaxonomyReader taxonomy) throws IOException;
-
- /**
- * Create the category list iterator for the specified partition.
- * If a non null cache is provided which contains the required data,
- * use it for the iteration.
- */
- public CategoryListIterator createCategoryListIterator(IndexReader reader,
- TaxonomyReader taxo, FacetSearchParams sParams, int partition)
- throws IOException {
- CategoryListCache clCache = sParams.getClCache();
- CategoryListParams clParams = sParams.getFacetIndexingParams().getCategoryListParams(categoryPath);
- if (clCache!=null) {
- CategoryListData clData = clCache.get(clParams);
- if (clData!=null) {
- return clData.iterator(partition);
- }
- }
- return clParams.createCategoryListIterator(reader, partition);
- }
+ public abstract Aggregator createAggregator(boolean useComplements, FacetArrays arrays, TaxonomyReader taxonomy)
+ throws IOException;
/**
* Return the value of a category used for facets computations for this
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java Fri Jan 18 18:30:54 2013
@@ -1,12 +1,9 @@
package org.apache.lucene.facet.search.params;
-import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
-import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams;
import org.apache.lucene.facet.index.params.FacetIndexingParams;
-import org.apache.lucene.facet.search.cache.CategoryListCache;
-import org.apache.lucene.facet.search.results.FacetResult;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -26,12 +23,13 @@ import org.apache.lucene.facet.search.re
*/
/**
- * Faceted search parameters indicate for which facets should info be gathered.
+ * Defines parameters that are needed for faceted search. The list of
+ * {@link FacetRequest facet requests} denotes the facets for which aggregated
+ * should be done.
* <p>
- * The contained facet requests define for which facets should info be gathered.
- * <p>
- * Contained faceted indexing parameters provide required info on how
- * to read and interpret the underlying faceted information in the search index.
+ * One can pass {@link FacetIndexingParams} in order to tell the search code how
+ * to read the facets information. Note that you must use the same
+ * {@link FacetIndexingParams} that were used for indexing.
*
* @lucene.experimental
*/
@@ -39,64 +37,55 @@ public class FacetSearchParams {
protected final FacetIndexingParams indexingParams;
protected final List<FacetRequest> facetRequests;
- private CategoryListCache clCache = null;
-
+
/**
- * Construct with specific faceted indexing parameters.
- * It is important to know the indexing parameters so as to e.g.
- * read facets data correctly from the index.
- * {@link #addFacetRequest(FacetRequest)} must be called at least once
- * for this faceted search to find any faceted result.
- * @param indexingParams Indexing faceted parameters which were used at indexing time.
- * @see #addFacetRequest(FacetRequest)
+ * 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)}.
*/
- public FacetSearchParams(FacetIndexingParams indexingParams) {
- this.indexingParams = indexingParams;
- facetRequests = new ArrayList<FacetRequest>();
+ public FacetSearchParams(FacetRequest... facetRequests) {
+ this(Arrays.asList(facetRequests), FacetIndexingParams.ALL_PARENTS);
}
-
+
/**
- * Construct with default faceted indexing parameters.
- * Usage of this constructor is valid only if also during indexing the
- * default faceted indexing parameters were used.
- * {@link #addFacetRequest(FacetRequest)} must be called at least once
- * for this faceted search to find any faceted result.
- * @see #addFacetRequest(FacetRequest)
+ * 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)}.
*/
- public FacetSearchParams() {
- this(new DefaultFacetIndexingParams());
+ public FacetSearchParams(List<FacetRequest> facetRequests) {
+ this(facetRequests, FacetIndexingParams.ALL_PARENTS);
}
/**
- * A list of {@link FacetRequest} objects, determining what to count.
- * If the returned collection is empty, the faceted search will return no facet results!
+ * Initilizes with the given {@link FacetRequest requests} and
+ * {@link FacetIndexingParams}.
*/
- public final FacetIndexingParams getFacetIndexingParams() {
- return indexingParams;
+ public FacetSearchParams(List<FacetRequest> facetRequests, FacetIndexingParams indexingParams) {
+ if (facetRequests == null || facetRequests.size() == 0) {
+ throw new IllegalArgumentException("at least one FacetRequest must be defined");
+ }
+ this.indexingParams = indexingParams;
+ this.facetRequests = facetRequests;
}
/**
- * Parameters which controlled the indexing of facets, and which are also
- * needed during search.
+ * Returns the {@link FacetIndexingParams} that were passed to the
+ * constructor.
*/
- public final List<FacetRequest> getFacetRequests() {
- return facetRequests;
+ public FacetIndexingParams getFacetIndexingParams() {
+ return indexingParams;
}
-
+
/**
- * Add a facet request to apply for this faceted search.
- * This method must be called at least once for faceted search
- * to find any faceted result. <br>
- * NOTE: The order of addition implies the order of the {@link FacetResult}s
- * @param facetRequest facet request to be added.
+ * Returns the list of {@link FacetRequest facet requests} that were passed to
+ * the constructor.
*/
- public void addFacetRequest(FacetRequest facetRequest) {
- if (facetRequest == null) {
- throw new IllegalArgumentException("Provided facetRequest must not be null");
- }
- facetRequests.add(facetRequest);
+ public List<FacetRequest> getFacetRequests() {
+ return facetRequests;
}
-
+
@Override
public String toString() {
final char TAB = '\t';
@@ -112,19 +101,4 @@ public class FacetSearchParams {
return sb.toString();
}
-
- /**
- * @return the cldCache in effect
- */
- public CategoryListCache getClCache() {
- return clCache;
- }
-
- /**
- * Set Cached Category Lists data to be used in Faceted search.
- * @param clCache the cldCache to set
- */
- public void setClCache(CategoryListCache clCache) {
- this.clCache = clCache;
- }
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/ScoreFacetRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/ScoreFacetRequest.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/ScoreFacetRequest.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/params/ScoreFacetRequest.java Fri Jan 18 18:30:54 2013
@@ -1,7 +1,5 @@
package org.apache.lucene.facet.search.params;
-import org.apache.lucene.index.IndexReader;
-
import org.apache.lucene.facet.search.FacetArrays;
import org.apache.lucene.facet.search.aggregator.Aggregator;
import org.apache.lucene.facet.search.aggregator.ScoringAggregator;
@@ -38,9 +36,7 @@ public class ScoreFacetRequest extends F
}
@Override
- public Aggregator createAggregator(boolean useComplements,
- FacetArrays arrays, IndexReader reader,
- TaxonomyReader taxonomy) {
+ public Aggregator createAggregator(boolean useComplements, FacetArrays arrays, TaxonomyReader taxonomy) {
assert !useComplements : "complements are not supported by this FacetRequest";
return new ScoringAggregator(arrays.getFloatArray());
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/results/FacetResult.java Fri Jan 18 18:30:54 2013
@@ -39,7 +39,7 @@ public class FacetResult {
/**
* Facet result node matching the root of the {@link #getFacetRequest() facet request}.
* @see #getFacetRequest()
- * @see FacetRequest#getCategoryPath()
+ * @see FacetRequest#categoryPath
*/
public final FacetResultNode getFacetResultNode() {
return this.rootNode;
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/results/MutableFacetResultNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/results/MutableFacetResultNode.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/results/MutableFacetResultNode.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/results/MutableFacetResultNode.java Fri Jan 18 18:30:54 2013
@@ -145,6 +145,7 @@ public class MutableFacetResultNode impl
* org.apache.lucene.facet.search.results2.FacetResultNode#toString(java.lang.
* String)
*/
+ @Override
public String toString(String prefix) {
StringBuilder sb = new StringBuilder(prefix);
@@ -171,10 +172,12 @@ public class MutableFacetResultNode impl
return sb.toString();
}
+ @Override
public final int getOrdinal() {
return ordinal;
}
+ @Override
public final CategoryPath getLabel() {
return label;
}
@@ -188,6 +191,7 @@ public class MutableFacetResultNode impl
this.label = label;
}
+ @Override
public final double getValue() {
return value;
}
@@ -199,6 +203,7 @@ public class MutableFacetResultNode impl
* the value to set
* @see #getValue()
*/
+ @Override
public void setValue(double value) {
this.value = value;
}
@@ -212,6 +217,7 @@ public class MutableFacetResultNode impl
this.value += addedValue;
}
+ @Override
public final double getResidue() {
return residue;
}
@@ -234,6 +240,7 @@ public class MutableFacetResultNode impl
this.residue += addedResidue;
}
+ @Override
public final Iterable<? extends FacetResultNode> getSubResults() {
return subResults != null ? subResults : EMPTY_SUB_RESULTS;
}
@@ -308,6 +315,7 @@ public class MutableFacetResultNode impl
* org.apache.lucene.facet.search.results.FacetResultNode#getLabel(org.apache.lucene
* .facet.taxonomy.TaxonomyReader)
*/
+ @Override
public final CategoryPath getLabel(TaxonomyReader taxonomyReader)
throws IOException {
if (label == null) {
@@ -321,6 +329,7 @@ public class MutableFacetResultNode impl
*
* @see org.apache.lucene.facet.search.results.FacetResultNode#getNumSubResults()
*/
+ @Override
public final int getNumSubResults() {
return subResults == null ? 0 : subResults.size();
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java Fri Jan 18 18:30:54 2013
@@ -1,10 +1,9 @@
package org.apache.lucene.facet.search.sampling;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
-import org.apache.lucene.index.IndexReader;
-
-import org.apache.lucene.facet.search.CategoryListIterator;
import org.apache.lucene.facet.search.FacetArrays;
import org.apache.lucene.facet.search.ScoredDocIDs;
import org.apache.lucene.facet.search.aggregator.Aggregator;
@@ -14,6 +13,7 @@ import org.apache.lucene.facet.search.re
import org.apache.lucene.facet.search.results.FacetResultNode;
import org.apache.lucene.facet.search.results.MutableFacetResultNode;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
+import org.apache.lucene.index.IndexReader;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -58,6 +58,7 @@ public abstract class Sampler {
/**
* Construct with certain {@link SamplingParams}
+ *
* @param params sampling params in effect
* @throws IllegalArgumentException if the provided SamplingParams are not valid
*/
@@ -108,16 +109,15 @@ public abstract class Sampler {
* @param sampleSetSize required size of sample set
* @return sample of the input set in the required size
*/
- protected abstract SampleResult createSample(ScoredDocIDs docids, int actualSize,
- int sampleSetSize) throws IOException;
+ protected abstract SampleResult createSample(ScoredDocIDs docids, int actualSize, int sampleSetSize)
+ throws IOException;
/**
* Get a fixer of sample facet accumulation results. Default implementation
* returns a <code>TakmiSampleFixer</code> which is adequate only for
* counting. For any other accumulator, provide a different fixer.
*/
- public SampleFixer getSampleFixer(
- IndexReader indexReader, TaxonomyReader taxonomyReader,
+ public SampleFixer getSampleFixer(IndexReader indexReader, TaxonomyReader taxonomyReader,
FacetSearchParams searchParams) {
return new TakmiSampleFixer(indexReader, taxonomyReader, searchParams);
}
@@ -159,10 +159,10 @@ public abstract class Sampler {
OverSampledFacetRequest sampledFreq = null;
try {
- sampledFreq = (OverSampledFacetRequest)facetResult.getFacetRequest();
+ sampledFreq = (OverSampledFacetRequest) facetResult.getFacetRequest();
} catch (ClassCastException e) {
throw new IllegalArgumentException(
- "It is only valid to call this method with result obtained for a" +
+ "It is only valid to call this method with result obtained for a " +
"facet request created through sampler.overSamlpingSearchParams()",
e);
}
@@ -183,11 +183,12 @@ public abstract class Sampler {
// So now we can sample -> altering the searchParams to accommodate for the statistical error for the sampling
double overSampleFactor = getSamplingParams().getOversampleFactor();
if (overSampleFactor > 1) { // any factoring to do?
- res = new FacetSearchParams(original.getFacetIndexingParams());
- for (FacetRequest frq: original.getFacetRequests()) {
+ List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
+ for (FacetRequest frq : original.getFacetRequests()) {
int overSampledNumResults = (int) Math.ceil(frq.getNumResults() * overSampleFactor);
- res.addFacetRequest(new OverSampledFacetRequest(frq, overSampledNumResults));
+ facetRequests.add(new OverSampledFacetRequest(frq, overSampledNumResults));
}
+ res = new FacetSearchParams(facetRequests, original.getFacetIndexingParams());
}
return res;
}
@@ -202,7 +203,7 @@ public abstract class Sampler {
private static class OverSampledFacetRequest extends FacetRequest {
final FacetRequest orig;
public OverSampledFacetRequest(FacetRequest orig, int num) {
- super(orig.getCategoryPath(), num);
+ super(orig.categoryPath, num);
this.orig = orig;
setDepth(orig.getDepth());
setNumLabel(orig.getNumLabel());
@@ -212,19 +213,9 @@ public abstract class Sampler {
}
@Override
- public CategoryListIterator createCategoryListIterator(IndexReader reader,
- TaxonomyReader taxo, FacetSearchParams sParams, int partition)
+ public Aggregator createAggregator(boolean useComplements, FacetArrays arrays, TaxonomyReader taxonomy)
throws IOException {
- return orig.createCategoryListIterator(reader, taxo, sParams, partition);
- }
-
-
- @Override
- public Aggregator createAggregator(boolean useComplements,
- FacetArrays arrays, IndexReader indexReader,
- TaxonomyReader taxonomy) throws IOException {
- return orig.createAggregator(useComplements, arrays, indexReader,
- taxonomy);
+ return orig.createAggregator(useComplements, arrays, taxonomy);
}
@Override
@@ -242,4 +233,5 @@ public abstract class Sampler {
return orig.supportsComplements();
}
}
+
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingAccumulator.java Fri Jan 18 18:30:54 2013
@@ -4,12 +4,9 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import org.apache.lucene.index.IndexReader;
-
+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.FloatArrayAllocator;
-import org.apache.lucene.facet.search.IntArrayAllocator;
import org.apache.lucene.facet.search.SamplingWrapper;
import org.apache.lucene.facet.search.ScoredDocIDs;
import org.apache.lucene.facet.search.StandardFacetsAccumulator;
@@ -18,6 +15,7 @@ import org.apache.lucene.facet.search.re
import org.apache.lucene.facet.search.results.FacetResultNode;
import org.apache.lucene.facet.search.sampling.Sampler.SampleResult;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
+import org.apache.lucene.index.IndexReader;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -61,17 +59,10 @@ public class SamplingAccumulator extends
private double samplingRatio = -1d;
private final Sampler sampler;
- /**
- * Constructor...
- */
- public SamplingAccumulator(
- Sampler sampler,
- FacetSearchParams searchParams,
+ public SamplingAccumulator(Sampler sampler, FacetSearchParams searchParams,
IndexReader indexReader, TaxonomyReader taxonomyReader,
- IntArrayAllocator intArrayAllocator,
- FloatArrayAllocator floatArrayAllocator) {
- super(searchParams, indexReader, taxonomyReader, intArrayAllocator,
- floatArrayAllocator);
+ FacetArrays facetArrays) {
+ super(searchParams, indexReader, taxonomyReader, facetArrays);
this.sampler = sampler;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingParams.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingParams.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/SamplingParams.java Fri Jan 18 18:30:54 2013
@@ -125,8 +125,8 @@ public class SamplingParams {
* Set a sampling-threshold
* @see #getSamplingThreshold()
*/
- public void setSampingThreshold(int sampingThreshold) {
- this.samplingThreshold = sampingThreshold;
+ public void setSamplingThreshold(int samplingThreshold) {
+ this.samplingThreshold = samplingThreshold;
}
/**
Modified: lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/TakmiSampleFixer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/TakmiSampleFixer.java?rev=1435287&r1=1435286&r2=1435287&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/TakmiSampleFixer.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/facet/src/java/org/apache/lucene/facet/search/sampling/TakmiSampleFixer.java Fri Jan 18 18:30:54 2013
@@ -58,6 +58,7 @@ class TakmiSampleFixer implements Sample
this.searchParams = searchParams;
}
+ @Override
public void fixResult(ScoredDocIDs origDocIds, FacetResult fres)
throws IOException {
FacetResultNode topRes = fres.getFacetResultNode();
@@ -90,8 +91,7 @@ class TakmiSampleFixer implements Sample
* full set of matching documents.
* @throws IOException If there is a low-level I/O error.
*/
- private void recount(FacetResultNode fresNode, ScoredDocIDs docIds)
- throws IOException {
+ private void recount(FacetResultNode fresNode, ScoredDocIDs docIds) throws IOException {
// TODO (Facet): change from void to return the new, smaller docSet, and use
// that for the children, as this will make their intersection ops faster.
// can do this only when the new set is "sufficiently" smaller.
@@ -108,8 +108,7 @@ class TakmiSampleFixer implements Sample
Bits liveDocs = MultiFields.getLiveDocs(indexReader);
int updatedCount = countIntersection(MultiFields.getTermDocsEnum(indexReader, liveDocs,
drillDownTerm.field(), drillDownTerm.bytes(),
- 0),
- docIds.iterator());
+ 0), docIds.iterator());
fresNode.setValue(updatedCount);
}