How to read Lucene 3.2 index by Lucene 4.10?

497 views Asked by At

Getting Lucene 4.10 read 3.2 version indexes Upgraded to 4.10 still need to read 3.2 indexes. Deployed jre 7 as required. Made all changes within a existing code base which became erroneous. Still need to read 3.2 indexes before going to take on re-indexing. How to read existing 3.2 indexes by Lucene 4.10 ( what changes to make if any in a code )

2

There are 2 answers

4
femtoRgon On

You can use IndexUpgrader, something like:

IndexUpgrader upgrader = new IndexUpgrader(myIndexDirectory, Version.LUCENE_4_10_0);
upgrader.upgrade();

or run it from the command line:

java -cp lucene-core.jar org.apache.lucene.index.IndexUpgrader myIndexDirectory
0
femtoRgon On

You can set the codec used to decode the indexes in the IndexWriterConfig. Lucene3xCodec would be the codec to use here:

IndexWriterConfig config = new IndexWriterConfig(Version.LATEST, analyzer);
config.setCodec(new Lucene3xCodec());
IndexWriter writer = new IndexWriter(directory, config);
IndexSearcher searcher = new IndexSearcher(new DirectoryReader.open(writer));

Bear in mind, this codec is strictly read-only. Any attempt to add, delete, or update a document will result in an UnsupportedOperationException being thrown. If you wish to support writing to the index, you must upgrade your index (see my original answer).