X-Git-Url: https://git.mdrn.pl/pylucene.git/blobdiff_plain/a2e61f0c04805cfcb8706176758d1283c7e3a55c..aaeed5504b982cf3545252ab528713250aa33eed:/lucene-java-3.5.0/lucene/contrib/facet/src/java/org/apache/lucene/facet/search/cache/CategoryListData.java diff --git a/lucene-java-3.5.0/lucene/contrib/facet/src/java/org/apache/lucene/facet/search/cache/CategoryListData.java b/lucene-java-3.5.0/lucene/contrib/facet/src/java/org/apache/lucene/facet/search/cache/CategoryListData.java new file mode 100644 index 0000000..a661077 --- /dev/null +++ b/lucene-java-3.5.0/lucene/contrib/facet/src/java/org/apache/lucene/facet/search/cache/CategoryListData.java @@ -0,0 +1,135 @@ +package org.apache.lucene.facet.search.cache; + +import java.io.IOException; + +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.CategoryListIterator; +import org.apache.lucene.facet.taxonomy.TaxonomyReader; +import org.apache.lucene.util.collections.IntArray; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Category list data maintained in RAM. + *
+ * Speeds up facets accumulation when more RAM is available. + *
+ * Note that this will consume more memory: one int (4 bytes) for each category + * of each document. + *
+ * Note: at the moment this class is insensitive to updates of the index, and, + * in particular, does not make use of Lucene's ability to refresh a single + * segment. + *
+ * See {@link CategoryListCache#register(CategoryListParams, CategoryListData)}
+ * and
+ * {@link CategoryListCache#loadAndRegister(CategoryListParams, IndexReader, TaxonomyReader, FacetIndexingParams)}.
+ *
+ * @lucene.experimental
+ */
+public class CategoryListData {
+
+ // TODO (Facet): experiment with different orders - p-d-c vs. current d-p-c.
+ private transient volatile int[][][] docPartitionCategories;
+
+ /**
+ * Empty constructor for extensions with modified computation of the data.
+ */
+ protected CategoryListData() {
+ }
+
+ /**
+ * Compute category list data for caching for faster iteration.
+ */
+ CategoryListData(IndexReader reader, TaxonomyReader taxo,
+ FacetIndexingParams iparams, CategoryListParams clp) throws IOException {
+
+ final int maxDoc = reader.maxDoc();
+ int[][][]dpf = new int[maxDoc][][];
+ int numPartitions = (int)Math.ceil(taxo.getSize()/(double)iparams.getPartitionSize());
+ IntArray docCategories = new IntArray();
+ for (int part=0; part