Index: lucene/facet/src/java/org/apache/lucene/facet/associations/AssociationsPayloadIterator.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/associations/AssociationsPayloadIterator.java (revision 1432826) +++ lucene/facet/src/java/org/apache/lucene/facet/associations/AssociationsPayloadIterator.java (working copy) @@ -3,7 +3,7 @@ import java.io.IOException; import org.apache.lucene.facet.search.PayloadIterator; -import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.Term; import org.apache.lucene.store.ByteArrayDataInput; import org.apache.lucene.util.BytesRef; @@ -46,13 +46,22 @@ * It is assumed that all association values can be deserialized with the * given {@link CategoryAssociation}. */ - public AssociationsPayloadIterator(IndexReader reader, String field, T association) throws IOException { - pi = new PayloadIterator(reader, new Term(field, association.getCategoryListID())); - hasAssociations = pi.init(); + public AssociationsPayloadIterator(String field, T association) throws IOException { + pi = new PayloadIterator(new Term(field, association.getCategoryListID())); this.association = association; } /** + * Sets the {@link AtomicReaderContext} for which {@link #setNextDoc(int)} + * calls will be made. Returns true iff this reader has associations for any + * of the documents belonging to the association given to the constructor. + */ + public final boolean setNextReader(AtomicReaderContext context) throws IOException { + hasAssociations = pi.setNextReader(context); + return hasAssociations; + } + + /** * Skip to the requested document. Returns true iff the document has category * association values and they were read successfully. Associations are * handled through {@link #handleAssociation(int, CategoryAssociation)} by Index: lucene/facet/src/java/org/apache/lucene/facet/associations/FloatAssociationsPayloadIterator.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/associations/FloatAssociationsPayloadIterator.java (revision 1432826) +++ lucene/facet/src/java/org/apache/lucene/facet/associations/FloatAssociationsPayloadIterator.java (working copy) @@ -2,7 +2,6 @@ import java.io.IOException; -import org.apache.lucene.index.IndexReader; import org.apache.lucene.util.collections.IntToFloatMap; /* @@ -31,9 +30,8 @@ private final IntToFloatMap ordinalAssociations = new IntToFloatMap(); - public FloatAssociationsPayloadIterator(IndexReader reader, String field, CategoryFloatAssociation association) - throws IOException { - super(reader, field, association); + public FloatAssociationsPayloadIterator(String field, CategoryFloatAssociation association) throws IOException { + super(field, association); } @Override Index: lucene/facet/src/java/org/apache/lucene/facet/associations/IntAssociationsPayloadIterator.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/associations/IntAssociationsPayloadIterator.java (revision 1432826) +++ lucene/facet/src/java/org/apache/lucene/facet/associations/IntAssociationsPayloadIterator.java (working copy) @@ -2,7 +2,6 @@ import java.io.IOException; -import org.apache.lucene.index.IndexReader; import org.apache.lucene.util.collections.IntToIntMap; /* @@ -31,9 +30,8 @@ private final IntToIntMap ordinalAssociations = new IntToIntMap(); - public IntAssociationsPayloadIterator(IndexReader reader, String field, CategoryIntAssociation association) - throws IOException { - super(reader, field, association); + public IntAssociationsPayloadIterator(String field, CategoryIntAssociation association) throws IOException { + super(field, association); } @Override Index: lucene/facet/src/java/org/apache/lucene/facet/index/params/CategoryListParams.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/index/params/CategoryListParams.java (revision 1432826) +++ lucene/facet/src/java/org/apache/lucene/facet/index/params/CategoryListParams.java (working copy) @@ -3,13 +3,10 @@ import java.io.IOException; import java.io.Serializable; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.Term; - import org.apache.lucene.facet.search.CategoryListIterator; import org.apache.lucene.facet.search.PayloadCategoryListIteraor; -import org.apache.lucene.facet.search.TotalFacetCounts; import org.apache.lucene.facet.util.PartitionsUtils; +import org.apache.lucene.index.Term; import org.apache.lucene.util.encoding.DGapIntEncoder; import org.apache.lucene.util.encoding.IntDecoder; import org.apache.lucene.util.encoding.IntEncoder; @@ -98,11 +95,6 @@ return new SortingIntEncoder(new UniqueValuesIntEncoder(new DGapIntEncoder(new VInt8IntEncoder()))); } - /** - * Equality is defined by the 'term' that defines this category list. - * Sub-classes should override this method if a more complex calculation - * is needed to ensure equality. - */ @Override public boolean equals(Object o) { if (o == this) { @@ -121,29 +113,16 @@ return this.term.equals(other.term); } - /** - * Hashcode is similar to {@link #equals(Object)}, in that it uses - * the term that defines this category list to derive the hashcode. - * Subclasses need to ensure that equality/hashcode is correctly defined, - * or there could be side-effects in the {@link TotalFacetCounts} caching - * mechanism (as the filename for a Total Facet Counts array cache - * is dependent on the hashCode, so it should consistently return the same - * hash for identity). - */ @Override public int hashCode() { return this.hashCode; } - /** - * Create the category list iterator for the specified partition. - */ - public CategoryListIterator createCategoryListIterator(IndexReader reader, - int partition) throws IOException { + /** Create the {@link CategoryListIterator} for the specified partition. */ + public CategoryListIterator createCategoryListIterator(int partition) throws IOException { String categoryListTermStr = PartitionsUtils.partitionName(this, partition); Term payloadTerm = new Term(term.field(), categoryListTermStr); - return new PayloadCategoryListIteraor(reader, payloadTerm, - createEncoder().createMatchingDecoder()); + return new PayloadCategoryListIteraor(payloadTerm, createEncoder().createMatchingDecoder()); } } \ No newline at end of file Index: lucene/facet/src/java/org/apache/lucene/facet/search/AdaptiveFacetsAccumulator.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/search/AdaptiveFacetsAccumulator.java (revision 1432826) +++ lucene/facet/src/java/org/apache/lucene/facet/search/AdaptiveFacetsAccumulator.java (working copy) @@ -50,7 +50,7 @@ * Create an {@link AdaptiveFacetsAccumulator} * @see StandardFacetsAccumulator#StandardFacetsAccumulator(FacetSearchParams, IndexReader, TaxonomyReader) */ - public AdaptiveFacetsAccumulator(FacetSearchParams searchParams, IndexReader indexReader, + public AdaptiveFacetsAccumulator(FacetSearchParams searchParams, IndexReader indexReader, TaxonomyReader taxonomyReader) { super(searchParams, indexReader, taxonomyReader); } Index: lucene/facet/src/java/org/apache/lucene/facet/search/CategoryListIterator.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/search/CategoryListIterator.java (revision 1432826) +++ lucene/facet/src/java/org/apache/lucene/facet/search/CategoryListIterator.java (working copy) @@ -2,6 +2,7 @@ import java.io.IOException; +import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.util.IntsRef; /* @@ -23,6 +24,8 @@ /** * An interface for obtaining the category ordinals of documents. + * {@link #getOrdinals(int, IntsRef)} calls are done with document IDs that are + * local to the reader given to {@link #setNextReader(AtomicReaderContext)}. *
* NOTE: this class operates as a key to a map, and therefore you should * implement {@code equals()} and {@code hashCode()} for proper behavior. @@ -32,19 +35,20 @@ public interface CategoryListIterator { /** - * Initializes the iterator. This method must be called before any calls to - * {@link #getOrdinals(int, IntsRef)}, and its return value indicates whether there are - * any relevant documents for this iterator. + * Sets the {@link AtomicReaderContext} for which + * {@link #getOrdinals(int, IntsRef)} calls will be made. Returns true iff any + * of the documents in this reader have category ordinals. This method must be + * called before any calls to {@link #getOrdinals(int, IntsRef)}. */ - public boolean init() throws IOException; - + public boolean setNextReader(AtomicReaderContext context) throws IOException; + /** * Stores the category ordinals of the given document ID in the given * {@link IntsRef}, starting at position 0 upto {@link IntsRef#length}. Grows * the {@link IntsRef} if it is not large enough. * *
- * NOTE: if the requested document does not category ordinals
+ * NOTE: if the requested document does not have category ordinals
* associated with it, {@link IntsRef#length} is set to zero.
*/
public void getOrdinals(int docID, IntsRef ints) throws IOException;
Index: lucene/facet/src/java/org/apache/lucene/facet/search/PayloadCategoryListIteraor.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/PayloadCategoryListIteraor.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/PayloadCategoryListIteraor.java (working copy)
@@ -2,7 +2,7 @@
import java.io.IOException;
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IntsRef;
@@ -34,17 +34,15 @@
public class PayloadCategoryListIteraor implements CategoryListIterator {
private final IntDecoder decoder;
- private final IndexReader indexReader;
private final Term term;
private final PayloadIterator pi;
private final int hashCode;
- public PayloadCategoryListIteraor(IndexReader indexReader, Term term, IntDecoder decoder) throws IOException {
- pi = new PayloadIterator(indexReader, term);
+ public PayloadCategoryListIteraor(Term term, IntDecoder decoder) throws IOException {
+ pi = new PayloadIterator(term);
this.decoder = decoder;
- hashCode = indexReader.hashCode() ^ term.hashCode();
+ hashCode = term.hashCode();
this.term = term;
- this.indexReader = indexReader;
}
@Override
@@ -58,7 +56,7 @@
}
// Hash codes are the same, check equals() to avoid cases of hash-collisions.
- return indexReader.equals(that.indexReader) && term.equals(that.term);
+ return term.equals(that.term);
}
@Override
@@ -67,8 +65,8 @@
}
@Override
- public boolean init() throws IOException {
- return pi.init();
+ public boolean setNextReader(AtomicReaderContext context) throws IOException {
+ return pi.setNextReader(context);
}
@Override
Index: lucene/facet/src/java/org/apache/lucene/facet/search/PayloadIterator.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/PayloadIterator.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/PayloadIterator.java (working copy)
@@ -1,12 +1,10 @@
package org.apache.lucene.facet.search;
import java.io.IOException;
-import java.util.Iterator;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.DocsAndPositionsEnum;
import org.apache.lucene.index.Fields;
-import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
@@ -42,99 +40,75 @@
*/
public class PayloadIterator {
- protected BytesRef data;
-
private TermsEnum reuseTE;
- private DocsAndPositionsEnum currentDPE;
+ private DocsAndPositionsEnum dpe;
private boolean hasMore;
- private int curDocID, curDocBase;
+ private int curDocID;
- private final Iterator
- * 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 {
/**
+ * 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.
+ */
+ public boolean setNextReader(AtomicReaderContext context) throws IOException;
+
+ /**
* Aggregate the ordinals of the given document ID (and its score). The given
* ordinals offset is always zero.
*/
Index: lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/CountingAggregator.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/CountingAggregator.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/CountingAggregator.java (working copy)
@@ -2,6 +2,7 @@
import java.io.IOException;
+import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.util.IntsRef;
/*
@@ -57,4 +58,9 @@
return counterArray == null ? 0 : counterArray.hashCode();
}
+ @Override
+ public boolean setNextReader(AtomicReaderContext context) throws IOException {
+ return true;
+ }
+
}
Index: lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/ScoringAggregator.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/ScoringAggregator.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/ScoringAggregator.java (working copy)
@@ -2,6 +2,7 @@
import java.io.IOException;
+import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.util.IntsRef;
/*
@@ -58,4 +59,9 @@
return hashCode;
}
+ @Override
+ public boolean setNextReader(AtomicReaderContext context) throws IOException {
+ return true;
+ }
+
}
Index: lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/associations/AssociationFloatSumAggregator.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/associations/AssociationFloatSumAggregator.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/associations/AssociationFloatSumAggregator.java (working copy)
@@ -6,7 +6,7 @@
import org.apache.lucene.facet.associations.FloatAssociationsPayloadIterator;
import org.apache.lucene.facet.index.params.CategoryListParams;
import org.apache.lucene.facet.search.aggregator.Aggregator;
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.util.IntsRef;
import org.apache.lucene.util.collections.IntToFloatMap;
@@ -39,13 +39,13 @@
protected final float[] sumArray;
protected final FloatAssociationsPayloadIterator associations;
- public AssociationFloatSumAggregator(IndexReader reader, float[] sumArray) throws IOException {
- this(CategoryListParams.DEFAULT_TERM.field(), reader, sumArray);
+ public AssociationFloatSumAggregator(float[] sumArray) throws IOException {
+ this(CategoryListParams.DEFAULT_TERM.field(), sumArray);
}
- public AssociationFloatSumAggregator(String field, IndexReader reader, float[] sumArray) throws IOException {
+ public AssociationFloatSumAggregator(String field, float[] sumArray) throws IOException {
this.field = field;
- associations = new FloatAssociationsPayloadIterator(reader, field, new CategoryFloatAssociation());
+ associations = new FloatAssociationsPayloadIterator(field, new CategoryFloatAssociation());
this.sumArray = sumArray;
}
@@ -76,4 +76,9 @@
return field.hashCode();
}
+ @Override
+ public boolean setNextReader(AtomicReaderContext context) throws IOException {
+ return associations.setNextReader(context);
+ }
+
}
Index: lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/associations/AssociationIntSumAggregator.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/associations/AssociationIntSumAggregator.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/aggregator/associations/AssociationIntSumAggregator.java (working copy)
@@ -6,7 +6,7 @@
import org.apache.lucene.facet.associations.IntAssociationsPayloadIterator;
import org.apache.lucene.facet.index.params.CategoryListParams;
import org.apache.lucene.facet.search.aggregator.Aggregator;
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.util.IntsRef;
import org.apache.lucene.util.collections.IntToIntMap;
@@ -39,13 +39,13 @@
protected final int[] sumArray;
protected final IntAssociationsPayloadIterator associations;
- public AssociationIntSumAggregator(IndexReader reader, int[] sumArray) throws IOException {
- this(CategoryListParams.DEFAULT_TERM.field(), reader, sumArray);
+ public AssociationIntSumAggregator(int[] sumArray) throws IOException {
+ this(CategoryListParams.DEFAULT_TERM.field(), sumArray);
}
- public AssociationIntSumAggregator(String field, IndexReader reader, int[] sumArray) throws IOException {
+ public AssociationIntSumAggregator(String field, int[] sumArray) throws IOException {
this.field = field;
- associations = new IntAssociationsPayloadIterator(reader, field, new CategoryIntAssociation());
+ associations = new IntAssociationsPayloadIterator(field, new CategoryIntAssociation());
this.sumArray = sumArray;
}
@@ -76,4 +76,9 @@
return field.hashCode();
}
+ @Override
+ public boolean setNextReader(AtomicReaderContext context) throws IOException {
+ return associations.setNextReader(context);
+ }
+
}
Index: lucene/facet/src/java/org/apache/lucene/facet/search/cache/CategoryListData.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/cache/CategoryListData.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/cache/CategoryListData.java (working copy)
@@ -6,6 +6,7 @@
import org.apache.lucene.facet.index.params.FacetIndexingParams;
import org.apache.lucene.facet.search.CategoryListIterator;
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
+import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.util.IntsRef;
@@ -56,26 +57,31 @@
}
/** Compute category list data for caching for faster iteration. */
- CategoryListData(IndexReader reader, TaxonomyReader taxo,
- FacetIndexingParams iparams, CategoryListParams clp) throws IOException {
+ CategoryListData(IndexReader reader, TaxonomyReader taxo, FacetIndexingParams iparams, CategoryListParams clp)
+ throws IOException {
- final int maxDoc = reader.maxDoc();
- int[][][]dpf = new int[maxDoc][][];
+ int[][][]dpf = new int[reader.maxDoc()][][];
int numPartitions = (int)Math.ceil(taxo.getSize()/(double)iparams.getPartitionSize());
IntsRef ordinals = new IntsRef(32);
for (int part = 0; part < numPartitions; part++) {
- CategoryListIterator cli = clp.createCategoryListIterator(reader, part);
- if (cli.init()) {
- for (int doc = 0; doc < maxDoc; doc++) {
- cli.getOrdinals(doc, ordinals);
- if (ordinals.length > 0) {
- if (dpf[doc] == null) {
- dpf[doc] = new int[numPartitions][];
+ for (AtomicReaderContext context : reader.leaves()) {
+ CategoryListIterator cli = clp.createCategoryListIterator(part);
+ if (cli.setNextReader(context)) {
+ final int maxDoc = context.reader().maxDoc();
+ for (int i = 0; i < maxDoc; i++) {
+ cli.getOrdinals(i, ordinals);
+ if (ordinals.length > 0) {
+ int doc = i + context.docBase;
+ if (dpf[doc] == null) {
+ dpf[doc] = new int[numPartitions][];
+ }
+ if (dpf[doc][part] == null) {
+ dpf[doc][part] = new int[ordinals.length];
+ }
+ for (int j = 0; j < ordinals.length; j++) {
+ dpf[doc][part][j] = ordinals.ints[j];
+ }
}
- dpf[doc][part] = new int[ordinals.length];
- for (int i = 0; i < ordinals.length; i++) {
- dpf[doc][part][i] = ordinals.ints[i];
- }
}
}
}
@@ -93,6 +99,7 @@
/** Internal: category list iterator over uncompressed category info in RAM */
private static class RAMCategoryListIterator implements CategoryListIterator {
+ private int docBase;
private final int part;
private final int[][][] dpc;
@@ -102,13 +109,15 @@
}
@Override
- public boolean init() throws IOException {
+ public boolean setNextReader(AtomicReaderContext context) throws IOException {
+ docBase = context.docBase;
return dpc != null && dpc.length > part;
}
-
+
@Override
public void getOrdinals(int docID, IntsRef ints) throws IOException {
ints.length = 0;
+ docID += docBase;
if (dpc.length > docID && dpc[docID] != null && dpc[docID][part] != null) {
if (ints.ints.length < dpc[docID][part].length) {
ints.grow(dpc[docID][part].length);
Index: lucene/facet/src/java/org/apache/lucene/facet/search/params/CountFacetRequest.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/params/CountFacetRequest.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/params/CountFacetRequest.java (working copy)
@@ -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,8 +45,7 @@
}
@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) {
Index: lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetRequest.java (working copy)
@@ -2,8 +2,6 @@
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;
@@ -11,8 +9,8 @@
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.CategoryListCache;
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;
@@ -314,33 +312,29 @@
* 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;
+ public abstract Aggregator createAggregator(boolean useComplements, FacetArrays arrays, 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.
+ * 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)
+ public CategoryListIterator createCategoryListIterator(TaxonomyReader taxo, FacetSearchParams sParams, int partition)
throws IOException {
CategoryListCache clCache = sParams.getCategoryListCache();
CategoryListParams clParams = sParams.getFacetIndexingParams().getCategoryListParams(categoryPath);
- if (clCache!=null) {
+ if (clCache != null) {
CategoryListData clData = clCache.get(clParams);
- if (clData!=null) {
+ if (clData != null) {
return clData.iterator(partition);
}
}
- return clParams.createCategoryListIterator(reader, partition);
+ return clParams.createCategoryListIterator(partition);
}
/**
Index: lucene/facet/src/java/org/apache/lucene/facet/search/params/ScoreFacetRequest.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/params/ScoreFacetRequest.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/params/ScoreFacetRequest.java (working copy)
@@ -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 @@
}
@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());
}
Index: lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationFloatSumFacetRequest.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationFloatSumFacetRequest.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationFloatSumFacetRequest.java (working copy)
@@ -2,8 +2,6 @@
import java.io.IOException;
-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.associations.AssociationFloatSumAggregator;
@@ -45,10 +43,10 @@
}
@Override
- public Aggregator createAggregator(boolean useComplements, FacetArrays arrays, IndexReader reader,
- TaxonomyReader taxonomy) throws IOException {
+ public Aggregator createAggregator(boolean useComplements, FacetArrays arrays, TaxonomyReader taxonomy)
+ throws IOException {
assert !useComplements : "complements are not supported by this FacetRequest";
- return new AssociationFloatSumAggregator(reader, arrays.getFloatArray());
+ return new AssociationFloatSumAggregator(arrays.getFloatArray());
}
@Override
Index: lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationIntSumFacetRequest.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationIntSumFacetRequest.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/params/associations/AssociationIntSumFacetRequest.java (working copy)
@@ -2,8 +2,6 @@
import java.io.IOException;
-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.associations.AssociationIntSumAggregator;
@@ -45,10 +43,10 @@
}
@Override
- public Aggregator createAggregator(boolean useComplements, FacetArrays arrays, IndexReader reader,
- TaxonomyReader taxonomy) throws IOException {
+ public Aggregator createAggregator(boolean useComplements, FacetArrays arrays, TaxonomyReader taxonomy)
+ throws IOException {
assert !useComplements : "complements are not supported by this FacetRequest";
- return new AssociationIntSumAggregator(reader, arrays.getIntArray());
+ return new AssociationIntSumAggregator(arrays.getIntArray());
}
@Override
Index: lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/sampling/Sampler.java (working copy)
@@ -60,6 +60,7 @@
/**
* Construct with certain {@link SamplingParams}
+ *
* @param params sampling params in effect
* @throws IllegalArgumentException if the provided SamplingParams are not valid
*/
@@ -110,16 +111,15 @@
* @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 TakmiSampleFixer 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);
}
@@ -161,10 +161,10 @@
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);
}
@@ -215,19 +215,15 @@
}
@Override
- public CategoryListIterator createCategoryListIterator(IndexReader reader,
- TaxonomyReader taxo, FacetSearchParams sParams, int partition)
- throws IOException {
- return orig.createCategoryListIterator(reader, taxo, sParams, partition);
+ public CategoryListIterator createCategoryListIterator(TaxonomyReader taxo, FacetSearchParams sParams,
+ int partition) throws IOException {
+ return orig.createCategoryListIterator(taxo, sParams, partition);
}
-
@Override
- public Aggregator createAggregator(boolean useComplements,
- FacetArrays arrays, IndexReader indexReader,
- TaxonomyReader taxonomy) throws IOException {
- return orig.createAggregator(useComplements, arrays, indexReader,
- taxonomy);
+ public Aggregator createAggregator(boolean useComplements, FacetArrays arrays, TaxonomyReader taxonomy)
+ throws IOException {
+ return orig.createAggregator(useComplements, arrays, taxonomy);
}
@Override
@@ -245,4 +241,5 @@
return orig.supportsComplements();
}
}
+
}
Index: lucene/facet/src/java/org/apache/lucene/facet/search/sampling/TakmiSampleFixer.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/search/sampling/TakmiSampleFixer.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/search/sampling/TakmiSampleFixer.java (working copy)
@@ -91,8 +91,7 @@
* 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.
@@ -109,8 +108,7 @@
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);
}
Index: lucene/facet/src/java/org/apache/lucene/facet/util/MultiCategoryListIterator.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/util/MultiCategoryListIterator.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/util/MultiCategoryListIterator.java (working copy)
@@ -5,6 +5,7 @@
import java.util.List;
import org.apache.lucene.facet.search.CategoryListIterator;
+import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.util.IntsRef;
/*
@@ -42,9 +43,10 @@
}
@Override
- public boolean init() throws IOException {
+ public boolean setNextReader(AtomicReaderContext context) throws IOException {
+ validIterators.clear();
for (CategoryListIterator cli : iterators) {
- if (cli.init()) {
+ if (cli.setNextReader(context)) {
validIterators.add(cli);
}
}
Index: lucene/facet/src/java/org/apache/lucene/facet/util/ScoredDocIdsUtils.java
===================================================================
--- lucene/facet/src/java/org/apache/lucene/facet/util/ScoredDocIdsUtils.java (revision 1432826)
+++ lucene/facet/src/java/org/apache/lucene/facet/util/ScoredDocIdsUtils.java (working copy)
@@ -3,17 +3,18 @@
import java.io.IOException;
import java.util.Arrays;
+import org.apache.lucene.facet.search.ScoredDocIDs;
+import org.apache.lucene.facet.search.ScoredDocIDsIterator;
+import org.apache.lucene.index.AtomicReader;
+import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiFields;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.OpenBitSet;
+import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.OpenBitSetDISI;
-import org.apache.lucene.facet.search.ScoredDocIDs;
-import org.apache.lucene.facet.search.ScoredDocIDsIterator;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -49,48 +50,57 @@
* @param reader holding the number of documents & information about deletions.
*/
public final static ScoredDocIDs getComplementSet(final ScoredDocIDs docids, final IndexReader reader)
- throws IOException {
+ throws IOException {
final int maxDoc = reader.maxDoc();
DocIdSet docIdSet = docids.getDocIDs();
- final OpenBitSet complement;
- if (docIdSet instanceof OpenBitSet) {
+ final FixedBitSet complement;
+ if (docIdSet instanceof FixedBitSet) {
// That is the most common case, if ScoredDocIdsCollector was used.
- complement = ((OpenBitSet) docIdSet).clone();
+ complement = ((FixedBitSet) docIdSet).clone();
} else {
- complement = new OpenBitSetDISI(docIdSet.iterator(), maxDoc);
+ complement = new FixedBitSet(maxDoc);
+ DocIdSetIterator iter = docIdSet.iterator();
+ int doc;
+ while ((doc = iter.nextDoc()) < maxDoc) {
+ complement.set(doc);
+ }
}
-
complement.flip(0, maxDoc);
-
- // Remove all Deletions from the complement set
clearDeleted(reader, complement);
return createScoredDocIds(complement, maxDoc);
}
-
- /**
- * Clear all deleted documents from a given open-bit-set according to a given reader
- */
- private static void clearDeleted(final IndexReader reader,
- final OpenBitSet set) throws IOException {
-
+
+ /** Clear all deleted documents from a given open-bit-set according to a given reader */
+ private static void clearDeleted(final IndexReader reader, final FixedBitSet set) throws IOException {
+
// If there are no deleted docs
if (!reader.hasDeletions()) {
return; // return immediately
}
- Bits bits = MultiFields.getLiveDocs(reader);
-
DocIdSetIterator it = set.iterator();
- int doc = DocIdSetIterator.NO_MORE_DOCS;
- while ((doc = it.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
- if (!bits.get(doc)) {
- set.fastClear(doc);
+ int doc = it.nextDoc();
+ for (AtomicReaderContext context : reader.leaves()) {
+ AtomicReader r = context.reader();
+ final int maxDoc = r.maxDoc() + context.docBase;
+ if (doc >= maxDoc) { // skip this segment
+ continue;
}
+ if (!r.hasDeletions()) { // skip all docs that belong to this reader as it has no deletions
+ while ((doc = it.nextDoc()) < maxDoc) {}
+ continue;
+ }
+ Bits liveDocs = r.getLiveDocs();
+ do {
+ if (!liveDocs.get(doc - context.docBase)) {
+ set.clear(doc);
+ }
+ } while ((doc = it.nextDoc()) < maxDoc);
}
}
-
+
/**
* Create a subset of an existing ScoredDocIDs object.
*
@@ -274,8 +284,7 @@
if (target <= next) {
target = next + 1;
}
- return next = target >= maxDoc ? NO_MORE_DOCS
- : target;
+ return next = target >= maxDoc ? NO_MORE_DOCS : target;
}
@Override
@@ -420,4 +429,5 @@
}
}
}
+
}
\ No newline at end of file
Index: lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java
===================================================================
--- lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java (revision 1432826)
+++ lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java (working copy)
@@ -317,8 +317,7 @@
}
/** Validate results equality */
- protected static void assertSameResults(List