Package org.apache.lucene.facet.search
Class TotalFacetCountsCache
- java.lang.Object
-
- org.apache.lucene.facet.search.TotalFacetCountsCache
-
public final class TotalFacetCountsCache extends Object
Manage an LRU cache forTotalFacetCounts
per index, taxonomy, and facet indexing params.- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_CACHE_SIZE
Default size of in memory cache for computed total facet counts.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear the cache.int
getCacheSize()
static TotalFacetCountsCache
getSingleton()
Get the single instance of this cacheTotalFacetCounts
getTotalCounts(org.apache.lucene.index.IndexReader indexReader, TaxonomyReader taxonomy, FacetIndexingParams facetIndexingParams, CategoryListCache clCache)
Get the total facet counts for a reader/taxonomy pair and facet indexing parameters.void
load(File inputFile, org.apache.lucene.index.IndexReader indexReader, TaxonomyReader taxonomy, FacetIndexingParams facetIndexingParams)
LoadTotalFacetCounts
matching input parameters from the provided outputFile and add them into the cache for the provided indexReader, taxonomy, and facetIndexingParams.void
setCacheSize(int size)
Set the number of TotalFacetCounts arrays that will remain in memory cache.void
store(File outputFile, org.apache.lucene.index.IndexReader indexReader, TaxonomyReader taxonomy, FacetIndexingParams facetIndexingParams, CategoryListCache clCache)
Store theTotalFacetCounts
matching input parameters into the provided outputFile, making them available for a later call toload(File, IndexReader, TaxonomyReader, FacetIndexingParams)
.
-
-
-
Field Detail
-
DEFAULT_CACHE_SIZE
public static final int DEFAULT_CACHE_SIZE
Default size of in memory cache for computed total facet counts. Set to 2 for the case when an application reopened a reader and the original one is still in use (Otherwise there will be switching again and again between the two.)- See Also:
- Constant Field Values
-
-
Method Detail
-
getSingleton
public static TotalFacetCountsCache getSingleton()
Get the single instance of this cache
-
getTotalCounts
public TotalFacetCounts getTotalCounts(org.apache.lucene.index.IndexReader indexReader, TaxonomyReader taxonomy, FacetIndexingParams facetIndexingParams, CategoryListCache clCache) throws IOException
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.- Parameters:
indexReader
- the documents indextaxonomy
- the taxonomy indexfacetIndexingParams
- facet indexing parametersclCache
- category list cache for faster computation, can be null- Returns:
- the total facet counts.
- Throws:
IOException
-
load
public void load(File inputFile, org.apache.lucene.index.IndexReader indexReader, TaxonomyReader taxonomy, FacetIndexingParams facetIndexingParams) throws IOException
LoadTotalFacetCounts
matching input parameters from the provided outputFile and add them into the cache for the provided indexReader, taxonomy, and facetIndexingParams. If aTotalFacetCounts
for these parameters already exists in the cache, it will be replaced by the loaded one.- Parameters:
inputFile
- file from which to read the dataindexReader
- the documents indextaxonomy
- the taxonomy indexfacetIndexingParams
- the facet indexing parameters- Throws:
IOException
- on error- See Also:
store(File, IndexReader, TaxonomyReader, FacetIndexingParams, CategoryListCache)
-
store
public void store(File outputFile, org.apache.lucene.index.IndexReader indexReader, TaxonomyReader taxonomy, FacetIndexingParams facetIndexingParams, CategoryListCache clCache) throws IOException
Store theTotalFacetCounts
matching input parameters into the provided outputFile, making them available for a later call toload(File, IndexReader, TaxonomyReader, FacetIndexingParams)
. If theseTotalFacetCounts
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).- Parameters:
outputFile
- file to store in.indexReader
- the documents indextaxonomy
- the taxonomy indexfacetIndexingParams
- the facet indexing parametersclCache
- category list cache for faster computation, can be null- Throws:
IOException
- on error- See Also:
load(File, IndexReader, TaxonomyReader, FacetIndexingParams)
,getTotalCounts(IndexReader, TaxonomyReader, FacetIndexingParams, CategoryListCache)
-
clear
public void clear()
Clear the cache.
-
getCacheSize
public int getCacheSize()
- Returns:
- the maximal cache size
-
setCacheSize
public void setCacheSize(int size)
Set the number of TotalFacetCounts arrays that will remain in memory cache.If new size is smaller than current size, the cache is appropriately trimmed.
Minimal size is 1, so passing zero or negative size would result in size of 1.
- Parameters:
size
- new size to set
-
-