org.apache.lucene.facet.util

## Class FacetsPayloadMigrationReader

- java.lang.Object
- - org.apache.lucene.index.IndexReader
  - - org.apache.lucene.index.AtomicReader
    - - org.apache.lucene.index.FilterAtomicReader
      - - org.apache.lucene.facet.util.FacetsPayloadMigrationReader

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class FacetsPayloadMigrationReader
      extends FilterAtomicReader

  A `FilterAtomicReader` for migrating a facets index which encodes category ordinals in a payload to `BinaryDocValues`. To migrate the index, you should build a mapping from a field (String) to term (`Term`), which denotes under which BinaryDocValues field to put the data encoded in the matching term's payload. You can follow the code example below to migrate an existing index:

       // Add the index and migrate payload to DocValues on the go
       DirectoryReader reader = DirectoryReader.open(oldDir);
       IndexWriterConfig conf = new IndexWriterConfig(VER, ANALYZER);
       IndexWriter writer = new IndexWriter(newDir, conf);
       List<AtomicReaderContext> leaves = reader.leaves();
       AtomicReader wrappedLeaves[] = new AtomicReader[leaves.size()];
       for (int i = 0; i < leaves.size(); i++) {
         wrappedLeaves[i] = new FacetPayloadMigrationReader(leaves.get(i).reader(),
             fieldTerms);
       }
       writer.addIndexes(new MultiReader(wrappedLeaves));
       writer.commit();

  NOTE: to build the field-to-term map you can use `buildFieldTermsMap(Directory, FacetIndexingParams)`, as long as the index to migrate contains the ordinals payload under `PAYLOAD_TERM_TEXT`.

  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.FilterAtomicReader

      `FilterAtomicReader.FilterDocsAndPositionsEnum, FilterAtomicReader.FilterDocsEnum, FilterAtomicReader.FilterFields, FilterAtomicReader.FilterTerms, FilterAtomicReader.FilterTermsEnum`

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

      `IndexReader.ReaderClosedListener`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `PAYLOAD_TERM_TEXT` The `Term` text of the ordinals payload.

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

      `in`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FacetsPayloadMigrationReader(AtomicReader in, Map<String,Term> fieldTerms)` Wraps an `AtomicReader` and migrates the payload to `BinaryDocValues` fields by using the given mapping.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Map<String,Term>` | `buildFieldTermsMap(Directory dir, FacetIndexingParams fip)` A utility method for building the field-to-Term map, given the `FacetIndexingParams` and the directory of the index to migrate.
    `BinaryDocValues` | `getBinaryDocValues(String field)`
    `FieldInfos` | `getFieldInfos()`

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

      `doClose, document, fields, getCombinedCoreAndDeletesKey, getCoreCacheKey, getLiveDocs, getNormValues, getNumericDocValues, getSortedDocValues, getSortedSetDocValues, getTermVectors, hasDeletions, maxDoc, numDocs, toString`

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

      `docFreq, getContext, hasNorms, termDocsEnum, termPositionsEnum, terms, totalTermFreq`

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

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

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

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

- - ### Field Detail

    - #### PAYLOAD_TERM_TEXT

          public static final String PAYLOAD_TERM_TEXT

      The `Term` text of the ordinals payload.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### FacetsPayloadMigrationReader

          public FacetsPayloadMigrationReader(AtomicReader in,
                                      Map<String,Term> fieldTerms)

      Wraps an `AtomicReader` and migrates the payload to `BinaryDocValues` fields by using the given mapping.

  - ### Method Detail

    - #### buildFieldTermsMap

          public static Map<String,Term> buildFieldTermsMap(Directory dir,
                                            FacetIndexingParams fip)
                                                     throws IOException

      A utility method for building the field-to-Term map, given the `FacetIndexingParams` and the directory of the index to migrate. The map that will be built will correspond to partitions as well as multiple `CategoryListParams`.

      NOTE: since `CategoryListParams` no longer define a `Term`, this method assumes that the term used by the different `CategoryListParams` is `PAYLOAD_TERM_TEXT`. If this is not the case, then you should build the map yourself, using the terms in your index.

      Throws:
        `IOException`

    - #### getBinaryDocValues

          public BinaryDocValues getBinaryDocValues(String field)
                                             throws IOException

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

    - #### getFieldInfos

          public FieldInfos getFieldInfos()

      Overrides:
        `getFieldInfos` in class `FilterAtomicReader`

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