Class UpgradeIndexMergePolicy

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Cloneable

    public class UpgradeIndexMergePolicy
    extends MergePolicy
    This MergePolicy is used for upgrading all existing segments of an index when calling IndexWriter.forceMerge(int). All other methods delegate to the base MergePolicy given to the constructor. This allows for an as-cheap-as possible upgrade of an older index by only upgrading segments that are created by previous Lucene versions. forceMerge does no longer really merge; it is just used to "forceMerge" older segment versions away.

    In general one would use IndexUpgrader, but for a fully customizeable upgrade, you can use this like any other MergePolicy and call IndexWriter.forceMerge(int):

      IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_XX, new KeywordAnalyzer());
      iwc.setMergePolicy(new UpgradeIndexMergePolicy(iwc.getMergePolicy()));
      IndexWriter w = new IndexWriter(dir, iwc);
      w.forceMerge(1);
      w.close();
     

    Warning: This merge policy may reorder documents if the index was partially upgraded before calling forceMerge (e.g., documents were added). If your application relies on "monotonicity" of doc IDs (which means that the order in which the documents were added to the index is preserved), do a forceMerge(1) instead. Please note, the delegate MergePolicy may also reorder documents.

    See Also:
    IndexUpgrader