org.apache.lucene.facet.taxonomy.directory
Interface DirectoryTaxonomyWriter.OrdinalMap

All Known Implementing Classes:
DirectoryTaxonomyWriter.DiskOrdinalMap, DirectoryTaxonomyWriter.MemoryOrdinalMap
Enclosing class:
DirectoryTaxonomyWriter

public static interface DirectoryTaxonomyWriter.OrdinalMap

Mapping from old ordinal to new ordinals, used when merging indexes wit separate taxonomies.

addToTaxonomies() merges one or more taxonomies into the given taxonomy (this). An OrdinalMap is filled for each of the added taxonomies, containing the new ordinal (in the merged taxonomy) of each of the categories in the old taxonomy.

There exist two implementations of OrdinalMap: MemoryOrdinalMap and DiskOrdinalMap. As their names suggest, the former keeps the map in memory and the latter in a temporary disk file. Because these maps will later be needed one by one (to remap the counting lists), not all at the same time, it is recommended to put the first taxonomy's map in memory, and all the rest on disk (later to be automatically read into memory one by one, when needed).


Method Summary
 void addDone()
          Call addDone() to say that all addMapping() have been done.
 void addMapping(int origOrdinal, int newOrdinal)
           
 int[] getMap()
          Return the map from the taxonomy's original (consecutive) ordinals to the new taxonomy's ordinals.
 void setSize(int size)
          Set the size of the map.
 

Method Detail

setSize

void setSize(int size)
             throws IOException
Set the size of the map. This MUST be called before addMapping(). It is assumed (but not verified) that addMapping() will then be called exactly 'size' times, with different origOrdinals between 0 and size-1.

Throws:
IOException

addMapping

void addMapping(int origOrdinal,
                int newOrdinal)
                throws IOException
Throws:
IOException

addDone

void addDone()
             throws IOException
Call addDone() to say that all addMapping() have been done. In some implementations this might free some resources.

Throws:
IOException

getMap

int[] getMap()
             throws IOException
Return the map from the taxonomy's original (consecutive) ordinals to the new taxonomy's ordinals. If the map has to be read from disk and ordered appropriately, it is done when getMap() is called. getMap() should only be called once, and only when the map is actually needed. Calling it will also free all resources that the map might be holding (such as temporary disk space), other than the returned int[].

Throws:
IOException