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.ChildrenIterator
INVALID_ORDINAL, ROOT_ORDINAL
Constructor and Description |
---|
DirectoryTaxonomyReader(Directory directory)
Open for reading a taxonomy stored in a given
Directory . |
DirectoryTaxonomyReader(DirectoryTaxonomyWriter taxoWriter)
Opens a
DirectoryTaxonomyReader over the given
DirectoryTaxonomyWriter (for NRT). |
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. |
Map<String,String> |
getCommitUserData()
Retrieve user committed data.
|
int |
getOrdinal(CategoryPath 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. |
CategoryPath |
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) |
protected DirectoryReader |
openIndexReader(IndexWriter writer) |
void |
setCacheSize(int size)
setCacheSize controls the maximum allowed size of each of the caches
used by
getPath(int) and getOrdinal(CategoryPath) . |
void |
setDelimiter(char delimiter)
setDelimiter changes the character that the taxonomy uses in its
internal storage as a delimiter between category components.
|
String |
toString(int max) |
close, decRef, ensureOpen, getChildren, getRefCount, incRef, openIfChanged, tryIncRef
public DirectoryTaxonomyReader(Directory directory) throws IOException
Directory
.directory
- The Directory
in which the taxonomy resides.CorruptIndexException
- if the Taxonomy is corrupt.IOException
- if another error occurred.public DirectoryTaxonomyReader(DirectoryTaxonomyWriter taxoWriter) throws IOException
DirectoryTaxonomyReader
over the given
DirectoryTaxonomyWriter
(for NRT).taxoWriter
- The DirectoryTaxonomyWriter
from which to obtain newly
added categories, in real-time.IOException
protected void doClose() throws IOException
TaxonomyReader
doClose
in class TaxonomyReader
IOException
protected DirectoryTaxonomyReader doOpenIfChanged() throws 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 TaxonomyReader
IOException
TaxonomyReader.openIfChanged(TaxonomyReader)
protected DirectoryReader openIndexReader(Directory directory) throws IOException
IOException
protected DirectoryReader openIndexReader(IndexWriter writer) throws IOException
IOException
public ParallelTaxonomyArrays getParallelTaxonomyArrays() throws IOException
TaxonomyReader
ParallelTaxonomyArrays
object which can be used to
efficiently traverse the taxonomy tree.getParallelTaxonomyArrays
in class TaxonomyReader
IOException
public Map<String,String> getCommitUserData() throws IOException
TaxonomyReader
getCommitUserData
in class TaxonomyReader
IOException
TaxonomyWriter.setCommitData(Map)
public int getOrdinal(CategoryPath cp) throws IOException
TaxonomyReader
getOrdinal
in class TaxonomyReader
TaxonomyReader.INVALID_ORDINAL
if the category
wasn't foun.IOException
public CategoryPath getPath(int ordinal) throws IOException
TaxonomyReader
getPath
in class TaxonomyReader
IOException
public int getSize()
TaxonomyReader
getSize
in class TaxonomyReader
public void setCacheSize(int size)
getPath(int)
and getOrdinal(CategoryPath)
.
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 void setDelimiter(char delimiter)
If you do use this method, make sure you call it before any other methods that actually queries the taxonomy. Moreover, make sure you always pass the same delimiter for all LuceneTaxonomyWriter and LuceneTaxonomyReader objects you create.
public String toString(int max)
Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.