org.apache.lucene.facet.taxonomy.CachedOrdinalsReader Maven / Gradle / Ivy
Show all versions of lucene-facet Show documentation
/*
* 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.
*/
package org.apache.lucene.facet.taxonomy;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.WeakHashMap;
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.Accountables;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.IntsRef;
import org.apache.lucene.util.RamUsageEstimator;
/**
* A per-segment cache of documents' facet ordinals. Every {@link CachedOrds} holds the ordinals in
* a raw {@code int[]}, and therefore consumes as much RAM as the total number of ordinals found in
* the segment, but saves the CPU cost of decoding ordinals during facet counting.
*
* NOTE: every {@link CachedOrds} is limited to 2.1B total ordinals. If that is a
* limitation for you then consider limiting the segment size to fewer documents, or use an
* alternative cache which pages through the category ordinals.
*
*
NOTE: when using this cache, it is advised to use a {@link DocValuesFormat} that does
* not cache the data in memory, at least for the category lists fields, or otherwise you'll be
* doing double-caching.
*
*
NOTE: create one instance of this and re-use it for all facet implementations (the
* cache is per-instance, not static).
*
* @deprecated Custom binary encodings for taxonomy ordinals are no longer supported starting with
* Lucene 9
*/
@Deprecated
public class CachedOrdinalsReader extends OrdinalsReader implements Accountable {
private final OrdinalsReader source;
private final Map