Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class DirectoryTaxonomyReader

    A TaxonomyReader which retrieves stored taxonomy information from a Lucene.Net.Store.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.

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Inheritance
    object
    TaxonomyReader
    DirectoryTaxonomyReader
    Implements
    IDisposable
    Inherited Members
    TaxonomyReader.ROOT_ORDINAL
    TaxonomyReader.INVALID_ORDINAL
    TaxonomyReader.OpenIfChanged<T>(T)
    TaxonomyReader.EnsureOpen()
    TaxonomyReader.Dispose()
    TaxonomyReader.DecRef()
    TaxonomyReader.GetChildren(int)
    TaxonomyReader.GetOrdinal(string, string[])
    TaxonomyReader.RefCount
    TaxonomyReader.IncRef()
    TaxonomyReader.TryIncRef()
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Facet.Taxonomy.Directory
    Assembly: Lucene.Net.Facet.dll
    Syntax
    public class DirectoryTaxonomyReader : TaxonomyReader, IDisposable

    Constructors

    DirectoryTaxonomyReader(DirectoryTaxonomyIndexReaderFactory, DirectoryTaxonomyWriter)

    Opens a DirectoryTaxonomyReader over the given DirectoryTaxonomyWriter (for NRT).

    Declaration
    public DirectoryTaxonomyReader(DirectoryTaxonomyIndexReaderFactory indexReaderFactory, DirectoryTaxonomyWriter taxoWriter)
    Parameters
    Type Name Description
    DirectoryTaxonomyIndexReaderFactory indexReaderFactory

    The DirectoryTaxonomyIndexReaderFactory to use to open the index reader.

    DirectoryTaxonomyWriter taxoWriter

    The DirectoryTaxonomyWriter from which to obtain newly added categories, in real-time.

    Exceptions
    Type Condition
    ArgumentNullException

    if indexReaderFactory or taxoWriter is null.

    DirectoryTaxonomyReader(DirectoryTaxonomyIndexReaderFactory, Directory)

    Open for reading a taxonomy stored in a given Lucene.Net.Store.Directory.

    Declaration
    public DirectoryTaxonomyReader(DirectoryTaxonomyIndexReaderFactory indexReaderFactory, Directory directory)
    Parameters
    Type Name Description
    DirectoryTaxonomyIndexReaderFactory indexReaderFactory

    The DirectoryTaxonomyIndexReaderFactory to use to open the index reader.

    Directory directory

    The Lucene.Net.Store.Directory in which the taxonomy resides.

    Exceptions
    Type Condition
    CorruptIndexException

    if the Taxonomy is corrupt.

    IOException

    if another error occurred.

    DirectoryTaxonomyReader(DirectoryTaxonomyWriter)

    Opens a DirectoryTaxonomyReader over the given DirectoryTaxonomyWriter (for NRT). Uses Default for DirectoryTaxonomyIndexReaderFactory.

    Declaration
    public DirectoryTaxonomyReader(DirectoryTaxonomyWriter taxoWriter)
    Parameters
    Type Name Description
    DirectoryTaxonomyWriter taxoWriter

    The DirectoryTaxonomyWriter from which to obtain newly added categories, in real-time.

    DirectoryTaxonomyReader(Directory)

    Open for reading a taxonomy stored in a given Lucene.Net.Store.Directory. Uses Default as for DirectoryTaxonomyIndexReaderFactory.

    Declaration
    public DirectoryTaxonomyReader(Directory directory)
    Parameters
    Type Name Description
    Directory directory

    The Lucene.Net.Store.Directory in which the taxonomy resides.

    Exceptions
    Type Condition
    CorruptIndexException

    if the Taxonomy is corrupt.

    IOException

    if another error occurred.

    Properties

    CommitUserData

    Retrieve user committed data.

    Declaration
    public override IDictionary<string, string> CommitUserData { get; }
    Property Value
    Type Description
    IDictionary<string, string>
    Overrides
    TaxonomyReader.CommitUserData
    See Also
    CommitData

    Count

    Returns 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).

    Declaration
    public override int Count { get; }
    Property Value
    Type Description
    int
    Overrides
    TaxonomyReader.Count

    ParallelTaxonomyArrays

    Returns a ParallelTaxonomyArrays object which can be used to efficiently traverse the taxonomy tree.

    Declaration
    public override ParallelTaxonomyArrays ParallelTaxonomyArrays { get; }
    Property Value
    Type Description
    ParallelTaxonomyArrays
    Overrides
    TaxonomyReader.ParallelTaxonomyArrays

    Methods

    Dispose(bool)

    Performs the actual task of closing the resources that are used by the taxonomy reader.

    Declaration
    protected override void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing
    Overrides
    TaxonomyReader.Dispose(bool)

    DoOpenIfChanged()

    Implements the opening of a new 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.

    Declaration
    protected override TaxonomyReader DoOpenIfChanged()
    Returns
    Type Description
    TaxonomyReader
    Overrides
    TaxonomyReader.DoOpenIfChanged()

    GetOrdinal(FacetLabel)

    Returns 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).

    Declaration
    public override int GetOrdinal(FacetLabel cp)
    Parameters
    Type Name Description
    FacetLabel cp
    Returns
    Type Description
    int

    the category's ordinal or INVALID_ORDINAL if the category wasn't found.

    Overrides
    TaxonomyReader.GetOrdinal(FacetLabel)

    GetPath(int)

    Returns the path name of the category with the given ordinal.

    Declaration
    public override FacetLabel GetPath(int ordinal)
    Parameters
    Type Name Description
    int ordinal
    Returns
    Type Description
    FacetLabel
    Overrides
    TaxonomyReader.GetPath(int)

    SetCacheSize(int)

    SetCacheSize(int) controls the maximum allowed size of each of the caches used by 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.
    Declaration
    public virtual void SetCacheSize(int size)
    Parameters
    Type Name Description
    int size

    The new maximum cache size, in number of entries.

    ToString(int)

    Returns ordinal -> label mapping, up to the provided max ordinal or number of ordinals, whichever is smaller.

    Declaration
    public virtual string ToString(int max)
    Parameters
    Type Name Description
    int max
    Returns
    Type Description
    string

    Implements

    IDisposable
    Back to top Copyright © 2025 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.