All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.lucene.facet.search.cache.CategoryListData Maven / Gradle / Ivy

There is a newer version: 9.11.1
Show newest version
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; partpart; } public long nextCategory() throws IOException { if (nextCategoryIndex >= dpc[currDoc][part].length) { return 1L+Integer.MAX_VALUE; } return dpc[currDoc][part][nextCategoryIndex++]; } public boolean skipTo(int docId) throws IOException { final boolean res = dpc.length>docId && dpc[docId]!=null && dpc[docId][part]!=null; if (res) { currDoc = docId; nextCategoryIndex = 0; } return res; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy