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
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.
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.IndexReader |
addReaderClosedListener, close, decRef, document, document, ensureOpen, equals, getRefCount, getTermVector, hashCode, incRef, leaves, numDeletedDocs, open, open, open, open, open, registerParentReader, removeReaderClosedListener, tryIncRef |
PAYLOAD_TERM_TEXT
public static final String PAYLOAD_TERM_TEXT
- The
Term
text of the ordinals payload.
- See Also:
- Constant Field Values
FacetsPayloadMigrationReader
public FacetsPayloadMigrationReader(AtomicReader in,
Map<String,Term> fieldTerms)
- Wraps an
AtomicReader
and migrates the payload to BinaryDocValues
fields by using the given mapping.
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.