public class DirectoryTaxonomyReader extends TaxonomyReader
TaxonomyReader which retrieves stored taxonomy information from a
Directory.
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.
TaxonomyReader.ChildrenIteratorINVALID_ORDINAL, ROOT_ORDINAL| Constructor and Description |
|---|
DirectoryTaxonomyReader(Directory directory)
Open for reading a taxonomy stored in a given
Directory. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doClose()
performs the actual task of closing the resources that are used by the
taxonomy reader.
|
protected DirectoryTaxonomyReader |
doOpenIfChanged()
Implements the opening of a new
DirectoryTaxonomyReader instance if
the taxonomy has changed. |
java.util.Collection<Accountable> |
getChildResources() |
java.util.Map<java.lang.String,java.lang.String> |
getCommitUserData()
Retrieve user committed data.
|
int |
getOrdinal(FacetLabel cp)
Returns the ordinal of the category given as a path.
|
ParallelTaxonomyArrays |
getParallelTaxonomyArrays()
Returns a
ParallelTaxonomyArrays object which can be used to
efficiently traverse the taxonomy tree. |
FacetLabel |
getPath(int ordinal)
Returns the path name of the category with the given ordinal.
|
int |
getSize()
Returns the number of categories in the taxonomy.
|
protected DirectoryReader |
openIndexReader(Directory directory)
Open the
DirectoryReader from this Directory. |
protected DirectoryReader |
openIndexReader(IndexWriter writer)
Open the
DirectoryReader from this IndexWriter. |
long |
ramBytesUsed() |
void |
setCacheSize(int size)
setCacheSize controls the maximum allowed size of each of the caches
used by
getPath(int) and getOrdinal(FacetLabel). |
java.lang.String |
toString(int max)
Returns ordinal -> label mapping, up to the provided
max ordinal or number of ordinals, whichever is
smaller.
|
close, decRef, ensureOpen, getChildren, getOrdinal, getRefCount, incRef, openIfChanged, tryIncRefpublic DirectoryTaxonomyReader(Directory directory)
throws java.io.IOException
Directory.directory - The Directory in which the taxonomy resides.CorruptIndexException - if the Taxonomy is corrupt.java.io.IOException - if another error occurred.protected void doClose()
throws java.io.IOException
TaxonomyReaderdoClose in class TaxonomyReaderjava.io.IOExceptionprotected DirectoryTaxonomyReader doOpenIfChanged() throws java.io.IOException
DirectoryTaxonomyReader instance if
the taxonomy has changed.
NOTE: the returned DirectoryTaxonomyReader shares the
ordinal and category caches with this reader. This is not expected to cause
any issues, unless the two instances continue to live. The reader
guarantees that the two instances cannot affect each other in terms of
correctness of the caches, however if the size of the cache is changed
through setCacheSize(int), it will affect both reader instances.
doOpenIfChanged in class TaxonomyReaderjava.io.IOExceptionTaxonomyReader.openIfChanged(TaxonomyReader)protected DirectoryReader openIndexReader(Directory directory)
throws java.io.IOException
DirectoryReader from this Directory.java.io.IOExceptionprotected DirectoryReader openIndexReader(IndexWriter writer)
throws java.io.IOException
DirectoryReader from this IndexWriter.java.io.IOExceptionpublic ParallelTaxonomyArrays getParallelTaxonomyArrays() throws java.io.IOException
TaxonomyReaderParallelTaxonomyArrays object which can be used to
efficiently traverse the taxonomy tree.getParallelTaxonomyArrays in class TaxonomyReaderjava.io.IOExceptionpublic java.util.Map<java.lang.String,java.lang.String> getCommitUserData()
throws java.io.IOException
TaxonomyReadergetCommitUserData in class TaxonomyReaderjava.io.IOExceptionTaxonomyWriter.setLiveCommitData(Iterable)public int getOrdinal(FacetLabel cp) throws java.io.IOException
TaxonomyReadergetOrdinal in class TaxonomyReaderTaxonomyReader.INVALID_ORDINAL if the category
wasn't foun.java.io.IOExceptionpublic FacetLabel getPath(int ordinal) throws java.io.IOException
TaxonomyReadergetPath in class TaxonomyReaderjava.io.IOExceptionpublic int getSize()
TaxonomyReadergetSize in class TaxonomyReaderpublic long ramBytesUsed()
public java.util.Collection<Accountable> getChildResources()
public void setCacheSize(int size)
getPath(int) and getOrdinal(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.
size - the new maximum cache size, in number of entries.public java.lang.String toString(int max)
Data In Motion GmbH all rights reserved