> > P.S. At one point I tried doing an in-memory index using the > > RAMDirectory > > and then merging it with an on-disk index and it didn't work. The > > RAMDirectory never flushed to disk... leaving me with an > > empty index. I > > think this is because of a bug in the mechanism that is > > supposed to copy the > > segments during the merge, but I didn't follow up on this. > > That should work, it should be faster and would use a lot > less memory than > the approach you describe above. Can you please submit a > simple test case > illustrating the failure? Something self-contained would be best.
Ok. This will fail: import java.io.*; import org.apache.lucene.index.*; import org.apache.lucene.analysis.*; import org.apache.lucene.document.*; import org.apache.lucene.store.*; public class LuceneRAMDirectoryTest { public static void main(String args[]) { try { // create index in RAM RAMDirectory ramDirectory = new RAMDirectory(); Analyzer analyzer = new SimpleAnalyzer(); IndexWriter ramWriter = new IndexWriter(ramDirectory, analyzer, true); try { for (int i = 0; i < 100; i++) { Document doc = new Document(); doc.add(Field.Keyword("field1", "" + i)); ramWriter.addDocument(doc); } } finally { ramWriter.close(); } // then merge into file File file = new File("index"); boolean missing = !file.exists(); if (missing) file.mkdir(); IndexWriter fileWriter = new IndexWriter(file, analyzer, true); try { fileWriter.addIndexes(new Directory[] { ramDirectory }); } finally { fileWriter.close(); } } catch (Exception e) { e.printStackTrace(); } } }