Class OrdinalMappingLeafReader

All Implemented Interfaces:
Closeable, AutoCloseable

public class OrdinalMappingLeafReader extends FilterLeafReader
A FilterLeafReader for updating facets ordinal references, based on an ordinal map. You should use this code in conjunction with merging taxonomies - after you merge taxonomies, you receive an DirectoryTaxonomyWriter.OrdinalMap which maps the 'old' ordinals to the 'new' ones. You can use that map to re-map the doc values which contain the facets information (ordinals) either before or while merging the indexes.

For re-mapping the ordinals during index merge, do the following:

 // merge the old taxonomy with the new one.
 OrdinalMap map = new MemoryOrdinalMap();
 DirectoryTaxonomyWriter.addTaxonomy(srcTaxoDir, map);
 int[] ordmap = map.getMap();

 // Add the index and re-map ordinals on the go
 DirectoryReader reader = DirectoryReader.open(oldDir);
 IndexWriterConfig conf = new IndexWriterConfig(VER, ANALYZER);
 IndexWriter writer = new IndexWriter(newDir, conf);
 List<LeafReaderContext> leaves = reader.leaves();
 LeafReader wrappedLeaves[] = new LeafReader[leaves.size()];
 for (int i = 0; i < leaves.size(); i++) {
   wrappedLeaves[i] = new OrdinalMappingLeafReader(leaves.get(i).reader(), ordmap);
 }
 writer.addIndexes(new MultiReader(wrappedLeaves));
 writer.commit();
 
  • Field Details

  • Constructor Details

    • OrdinalMappingLeafReader

      public OrdinalMappingLeafReader(LeafReader in, int[] ordinalMap, FacetsConfig srcConfig)
      Wraps an LeafReader, mapping ordinals according to the ordinalMap, using the provided FacetsConfig which was used to build the wrapped reader.
  • Method Details

    • encode

      @Deprecated protected BytesRef encode(IntsRef ordinals)
      Deprecated.
      Custom binary formats are no longer directly supported for taxonomy faceting starting in Lucene 9
      Expert: encodes category ordinals into a BytesRef. Override in case you use custom encoding, other than the default done by FacetsConfig.
    • getOrdinalsReader

      @Deprecated protected OrdinalsReader getOrdinalsReader(String field)
      Deprecated.
      Custom binary formats are no longer directly supported for taxonomy faceting starting in Lucene 9
      Expert: override in case you used custom encoding for the categories under this field.
    • getBinaryDocValues

      public BinaryDocValues getBinaryDocValues(String field) throws IOException
      Description copied from class: LeafReader
      Returns BinaryDocValues for this field, or null if no binary doc values were indexed for this field. The returned instance should only be used by a single thread.
      Overrides:
      getBinaryDocValues in class FilterLeafReader
      Throws:
      IOException
    • getSortedNumericDocValues

      public SortedNumericDocValues getSortedNumericDocValues(String field) throws IOException
      Description copied from class: LeafReader
      Returns SortedNumericDocValues for this field, or null if no SortedNumericDocValues were indexed for this field. The returned instance should only be used by a single thread.
      Overrides:
      getSortedNumericDocValues in class FilterLeafReader
      Throws:
      IOException
    • getCoreCacheHelper

      public IndexReader.CacheHelper getCoreCacheHelper()
      Description copied from class: LeafReader
      Optional method: Return a IndexReader.CacheHelper that can be used to cache based on the content of this leaf regardless of deletions. Two readers that have the same data but different sets of deleted documents or doc values updates may be considered equal. Consider using IndexReader.getReaderCacheHelper() if you need deletions or dv updates to be taken into account.

      A return value of null indicates that this reader is not suited for caching, which is typically the case for short-lived wrappers that alter the content of the wrapped leaf reader.

      Specified by:
      getCoreCacheHelper in class LeafReader
    • getReaderCacheHelper

      public IndexReader.CacheHelper getReaderCacheHelper()
      Description copied from class: IndexReader
      Optional method: Return a IndexReader.CacheHelper that can be used to cache based on the content of this reader. Two readers that have different data or different sets of deleted documents will be considered different.

      A return value of null indicates that this reader is not suited for caching, which is typically the case for short-lived wrappers that alter the content of the wrapped reader.

      Specified by:
      getReaderCacheHelper in class IndexReader