org.apache.lucene.facet.index
Class FacetsPayloadProcessorProvider

java.lang.Object
  extended by org.apache.lucene.index.PayloadProcessorProvider
      extended by org.apache.lucene.facet.index.FacetsPayloadProcessorProvider

public class FacetsPayloadProcessorProvider
extends org.apache.lucene.index.PayloadProcessorProvider

A PayloadProcessorProvider 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' payloads to the 'new' ones. You can use that map to re-map the payloads which contain the facets information (ordinals) either before or while merging the indexes.

For re-mapping the ordinals before you merge the indexes, do the following:

 // merge the old taxonomy with the new one.
 OrdinalMap map = LuceneTaxonomyWriter.addTaxonomies();
 int[] ordmap = map.getMap();
 
 // re-map the ordinals on the old directory.
 Directory oldDir;
 FacetsPayloadProcessorProvider fppp = new FacetsPayloadProcessorProvider(
     oldDir, ordmap);
 IndexWriterConfig conf = new IndexWriterConfig(VER, ANALYZER);
 conf.setMergePolicy(new ForceOptimizeMergePolicy());
 IndexWriter writer = new IndexWriter(oldDir, conf);
 writer.setPayloadProcessorProvider(fppp);
 writer.forceMerge(1);
 writer.close();
 
 // merge that directory with the new index.
 IndexWriter newWriter; // opened on the 'new' Directory
 newWriter.addIndexes(oldDir);
 newWriter.commit();
 
For re-mapping the ordinals during index merge, do the following:
 // merge the old taxonomy with the new one.
 OrdinalMap map = LuceneTaxonomyWriter.addTaxonomies();
 int[] ordmap = map.getMap();
 
 // Add the index and re-map ordinals on the go
 IndexReader r = IndexReader.open(oldDir);
 IndexWriterConfig conf = new IndexWriterConfig(VER, ANALYZER);
 IndexWriter writer = new IndexWriter(newDir, conf);
 writer.setPayloadProcessorProvider(fppp);
 writer.addIndexes(r);
 writer.commit();
 

NOTE: while the second example looks simpler, IndexWriter may trigger a long merge due to addIndexes. The first example avoids this perhaps unneeded merge, as well as can be done separately (e.g. on another node) before the index is merged.

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

Nested Class Summary
static class FacetsPayloadProcessorProvider.FacetsDirPayloadProcessor
           
static class FacetsPayloadProcessorProvider.FacetsPayloadProcessor
          A PayloadProcessor for updating facets ordinal references, based on an ordinal map
 
Nested classes/interfaces inherited from class org.apache.lucene.index.PayloadProcessorProvider
org.apache.lucene.index.PayloadProcessorProvider.DirPayloadProcessor, org.apache.lucene.index.PayloadProcessorProvider.PayloadProcessor
 
Constructor Summary
FacetsPayloadProcessorProvider(org.apache.lucene.store.Directory dir, int[] ordinalMap, FacetIndexingParams indexingParams)
          Construct FacetsPayloadProcessorProvider with FacetIndexingParams
 
Method Summary
 org.apache.lucene.index.PayloadProcessorProvider.DirPayloadProcessor getDirProcessor(org.apache.lucene.store.Directory dir)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FacetsPayloadProcessorProvider

public FacetsPayloadProcessorProvider(org.apache.lucene.store.Directory dir,
                                      int[] ordinalMap,
                                      FacetIndexingParams indexingParams)
Construct FacetsPayloadProcessorProvider with FacetIndexingParams

Parameters:
dir - the Directory containing the segments to update
ordinalMap - an array mapping previous facets ordinals to new ones
indexingParams - the facets indexing parameters
Method Detail

getDirProcessor

public org.apache.lucene.index.PayloadProcessorProvider.DirPayloadProcessor getDirProcessor(org.apache.lucene.store.Directory dir)
                                                                                     throws IOException
Specified by:
getDirProcessor in class org.apache.lucene.index.PayloadProcessorProvider
Throws:
IOException


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