Class DirectoryTaxonomyWriter

    • Field Detail

      • INDEX_EPOCH

        public static final String INDEX_EPOCH
        Property name of user commit data that contains the index epoch. The epoch changes whenever the taxonomy is recreated (i.e. opened with IndexWriterConfig.OpenMode.CREATE.

        Applications should not use this property in their commit data because it will be overridden by this taxonomy writer.

        See Also:
        Constant Field Values
    • Method Detail

      • closeResources

        protected void closeResources()
                               throws IOException
        A hook for extending classes to close additional resources that were used. The default implementation closes the IndexReader as well as the TaxonomyWriterCache instances that were used.
        NOTE: if you override this method, you should include a super.closeResources() call in your implementation.
        Throws:
        IOException
      • findCategory

        protected int findCategory​(FacetLabel categoryPath)
                            throws IOException
        Look up the given category in the cache and/or the on-disk storage, returning the category's ordinal, or a negative number in case the category does not yet exist in the taxonomy.
        Throws:
        IOException
      • addCategory

        public int addCategory​(FacetLabel categoryPath)
                        throws IOException
        Description copied from interface: TaxonomyWriter
        addCategory() adds a category with a given path name to the taxonomy, and returns its ordinal. If the category was already present in the taxonomy, its existing ordinal is returned.

        Before adding a category, addCategory() makes sure that all its ancestor categories exist in the taxonomy as well. As result, the ordinal of a category is guaranteed to be smaller then the ordinal of any of its descendants.

        Specified by:
        addCategory in interface TaxonomyWriter
        Throws:
        IOException
      • ensureOpen

        protected final void ensureOpen()
        Verifies that this instance wasn't closed, or throws AlreadyClosedException if it is.
      • getSize

        public int getSize()
        Description copied from interface: TaxonomyWriter
        getSize() returns the number of categories in the taxonomy.

        Because categories are numbered consecutively starting with 0, it means the taxonomy contains ordinals 0 through getSize()-1.

        Note that the number returned by getSize() 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:
        getSize in interface TaxonomyWriter
      • setCacheMissesUntilFill

        public void setCacheMissesUntilFill​(int i)
        Set the number of cache misses before an attempt is made to read the entire taxonomy into the in-memory cache.

        This taxonomy writer holds an in-memory cache of recently seen categories to speed up operation. On each cache-miss, the on-disk index needs to be consulted. When an existing taxonomy is opened, a lot of slow disk reads like that are needed until the cache is filled, so it is more efficient to read the entire taxonomy into memory at once. We do this complete read after a certain number (defined by this method) of cache misses.

        If the number is set to 0, the entire taxonomy is read into the cache on first use, without fetching individual categories first.

        NOTE: it is assumed that this method is called immediately after the taxonomy writer has been created.

      • getParent

        public int getParent​(int ordinal)
                      throws IOException
        Description copied from interface: TaxonomyWriter
        getParent() returns the ordinal of the parent category of the category with the given ordinal.

        When a category is specified as a path name, finding the path of its parent is as trivial as dropping the last component of the path. getParent() is functionally equivalent to calling getPath() on the given ordinal, dropping the last component of the path, and then calling getOrdinal() to get an ordinal back.

        If the given ordinal is the ROOT_ORDINAL, an INVALID_ORDINAL is returned. If the given ordinal is a top-level category, the ROOT_ORDINAL is returned. If an invalid ordinal is given (negative or beyond the last available ordinal), an IndexOutOfBoundsException is thrown. However, it is expected that getParent will only be called for ordinals which are already known to be in the taxonomy. TODO (Facet): instead of a getParent(ordinal) method, consider having a

        getCategory(categorypath, prefixlen) which is similar to addCategory except it doesn't add new categories; This method can be used to get the ordinals of all prefixes of the given category, and it can use exactly the same code and cache used by addCategory() so it means less code.

        Specified by:
        getParent in interface TaxonomyWriter
        Throws:
        IOException
      • getDirectory

        public Directory getDirectory()
        Returns the Directory of this taxonomy writer.
      • getTaxonomyEpoch

        public final long getTaxonomyEpoch()
        Expert: returns current index epoch, if this is a near-real-time reader. Used by DirectoryTaxonomyReader to support NRT.
        NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
      • useNumericDocValuesForOrdinals

        public boolean useNumericDocValuesForOrdinals()
        Description copied from interface: TaxonomyWriter
        Determine whether-or-not to store taxonomy ordinals for each document using the older binary format or the newer SortedNumericDocValues format (based on the version used to create the index).
        Specified by:
        useNumericDocValuesForOrdinals in interface TaxonomyWriter