org.apache.lucene.facet.taxonomy

## Class OrdinalMappingLeafReader

- java.lang.Object
- - org.apache.lucene.index.IndexReader
  - - org.apache.lucene.index.LeafReader
    - - org.apache.lucene.index.FilterLeafReader
      - - org.apache.lucene.facet.taxonomy.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();

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

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.lucene.index.FilterLeafReader

      `FilterLeafReader.FilterFields, FilterLeafReader.FilterPostingsEnum, FilterLeafReader.FilterTerms, FilterLeafReader.FilterTermsEnum`

    - ### Nested classes/interfaces inherited from class org.apache.lucene.index.LeafReader

      `LeafReader.CoreClosedListener`

    - ### Nested classes/interfaces inherited from class org.apache.lucene.index.IndexReader

      `IndexReader.ReaderClosedListener`

  - ### Field Summary

    - ### Fields inherited from class org.apache.lucene.index.FilterLeafReader

      `in`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `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 Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected BytesRef` | `encode(IntsRef ordinals)` Expert: encodes category ordinals into a BytesRef.
    `BinaryDocValues` | `getBinaryDocValues(String field)`
    `protected OrdinalsReader` | `getOrdinalsReader(String field)` Expert: override in case you used custom encoding for the categories under this field.

    - ### Methods inherited from class org.apache.lucene.index.FilterLeafReader

      `addCoreClosedListener, checkIntegrity, doClose, document, fields, getDelegate, getDocsWithField, getFieldInfos, getIndexSort, getLiveDocs, getNormValues, getNumericDocValues, getPointValues, getSortedDocValues, getSortedNumericDocValues, getSortedSetDocValues, getTermVectors, maxDoc, numDocs, removeCoreClosedListener, toString, unwrap`

    - ### Methods inherited from class org.apache.lucene.index.LeafReader

      `addCoreClosedListenerAsReaderClosedListener, docFreq, getContext, getDocCount, getSumDocFreq, getSumTotalTermFreq, postings, postings, removeCoreClosedListenerAsReaderClosedListener, terms, totalTermFreq`

    - ### Methods inherited from class org.apache.lucene.index.IndexReader

      `addReaderClosedListener, close, decRef, document, document, ensureOpen, equals, getCombinedCoreAndDeletesKey, getCoreCacheKey, getRefCount, getTermVector, hasDeletions, hashCode, incRef, leaves, numDeletedDocs, registerParentReader, removeReaderClosedListener, tryIncRef`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### 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 Detail

    - #### encode

          protected BytesRef encode(IntsRef ordinals)

      Expert: encodes category ordinals into a BytesRef. Override in case you use custom encoding, other than the default done by FacetsConfig.

    - #### getOrdinalsReader

          protected OrdinalsReader getOrdinalsReader(String field)

      Expert: override in case you used custom encoding for the categories under this field.

    - #### getBinaryDocValues

          public BinaryDocValues getBinaryDocValues(String field)
                                             throws IOException

      Overrides:
        `getBinaryDocValues` in class `FilterLeafReader`
      Throws:
        `IOException`

Copyright © 2000-2018 Apache Software Foundation. All Rights Reserved.