Class DirectoryTaxonomyReader
- java.lang.Object
-
- org.apache.lucene.facet.taxonomy.TaxonomyReader
-
- org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class DirectoryTaxonomyReader extends TaxonomyReader
ATaxonomyReaderwhich retrieves stored taxonomy information from aDirectory.Reading from the on-disk index on every method call is too slow, so this implementation employs caching: Some methods cache recent requests and their results, while other methods prefetch all the data into memory and then provide answers directly from in-memory tables. See the documentation of individual methods for comments on their performance.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.lucene.facet.taxonomy.TaxonomyReader
TaxonomyReader.ChildrenIterator
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.facet.taxonomy.TaxonomyReader
INVALID_ORDINAL, ROOT_ORDINAL
-
-
Constructor Summary
Constructors Constructor Description DirectoryTaxonomyReader(DirectoryTaxonomyWriter taxoWriter)Opens aDirectoryTaxonomyReaderover the givenDirectoryTaxonomyWriter(for NRT).DirectoryTaxonomyReader(Directory directory)Open for reading a taxonomy stored in a givenDirectory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.String>getCommitUserData()Retrieve user committed data.intgetOrdinal(FacetLabel cp)Returns the ordinal of the category given as a path.ParallelTaxonomyArraysgetParallelTaxonomyArrays()Returns aParallelTaxonomyArraysobject which can be used to efficiently traverse the taxonomy tree.FacetLabelgetPath(int ordinal)Returns the path name of the category with the given ordinal.intgetSize()Returns the number of categories in the taxonomy.voidsetCacheSize(int size)setCacheSize controls the maximum allowed size of each of the caches used bygetPath(int)andgetOrdinal(FacetLabel).java.lang.StringtoString(int max)Returns ordinal -> label mapping, up to the provided max ordinal or number of ordinals, whichever is smaller.-
Methods inherited from class org.apache.lucene.facet.taxonomy.TaxonomyReader
close, decRef, getChildren, getOrdinal, getRefCount, incRef, openIfChanged, tryIncRef
-
-
-
-
Constructor Detail
-
DirectoryTaxonomyReader
public DirectoryTaxonomyReader(Directory directory) throws java.io.IOException
Open for reading a taxonomy stored in a givenDirectory.- Parameters:
directory- TheDirectoryin which the taxonomy resides.- Throws:
CorruptIndexException- if the Taxonomy is corrupt.java.io.IOException- if another error occurred.
-
DirectoryTaxonomyReader
public DirectoryTaxonomyReader(DirectoryTaxonomyWriter taxoWriter) throws java.io.IOException
Opens aDirectoryTaxonomyReaderover the givenDirectoryTaxonomyWriter(for NRT).- Parameters:
taxoWriter- TheDirectoryTaxonomyWriterfrom which to obtain newly added categories, in real-time.- Throws:
java.io.IOException
-
-
Method Detail
-
getParallelTaxonomyArrays
public ParallelTaxonomyArrays getParallelTaxonomyArrays() throws java.io.IOException
Description copied from class:TaxonomyReaderReturns aParallelTaxonomyArraysobject which can be used to efficiently traverse the taxonomy tree.- Specified by:
getParallelTaxonomyArraysin classTaxonomyReader- Throws:
java.io.IOException
-
getCommitUserData
public java.util.Map<java.lang.String,java.lang.String> getCommitUserData() throws java.io.IOExceptionDescription copied from class:TaxonomyReaderRetrieve user committed data.- Specified by:
getCommitUserDatain classTaxonomyReader- Throws:
java.io.IOException- See Also:
TaxonomyWriter.setCommitData(Map)
-
getOrdinal
public int getOrdinal(FacetLabel cp) throws java.io.IOException
Description copied from class:TaxonomyReaderReturns the ordinal of the category given as a path. The ordinal is the category's serial number, an integer which starts with 0 and grows as more categories are added (note that once a category is added, it can never be deleted).- Specified by:
getOrdinalin classTaxonomyReader- Returns:
- the category's ordinal or
TaxonomyReader.INVALID_ORDINALif the category wasn't foun. - Throws:
java.io.IOException
-
getPath
public FacetLabel getPath(int ordinal) throws java.io.IOException
Description copied from class:TaxonomyReaderReturns the path name of the category with the given ordinal.- Specified by:
getPathin classTaxonomyReader- Throws:
java.io.IOException
-
getSize
public int getSize()
Description copied from class:TaxonomyReaderReturns the number of categories in the taxonomy. Note that the number of categories returned is often slightly higher than the number of categories inserted into the taxonomy; This is because when a category is added to the taxonomy, its ancestors are also added automatically (including the root, which always get ordinal 0).- Specified by:
getSizein classTaxonomyReader
-
setCacheSize
public void setCacheSize(int size)
setCacheSize controls the maximum allowed size of each of the caches used bygetPath(int)andgetOrdinal(FacetLabel).Currently, if the given size is smaller than the current size of a cache, it will not shrink, and rather we be limited to its current size.
- Parameters:
size- the new maximum cache size, in number of entries.
-
toString
public java.lang.String toString(int max)
Returns ordinal -> label mapping, up to the provided max ordinal or number of ordinals, whichever is smaller.
-
-