javasoze/zoie — Issue #8: BaseSearchIndex loadFromIndex must inovke   writer.maybeMerge()  after  writer.addIndexesNoOptimize(new Directory[] { dir }) use with lucene 3.4
Author: wangscu
Created: 2011-10-15 07:46:31+00:00
State: open

in Lucene 3.4 writer.addIndexes(new Directory[] { dir }) does not merge any more, so we must inoke maybeMerge after add dir to index. :)

public void loadFromIndex(BaseSearchIndex index) throws IOException
{
// hao: open readOnly ram index reader
ZoieIndexReader reader = index.openIndexReader();
if (reader == null)
return;

Directory dir = reader.directory();

// hao: delete docs in disk index
LongSet delDocs = _delDocs;
clearDeletes();
deleteDocs(delDocs);

// hao: merge the readOnly ram index with the disk index
IndexWriter writer = null;
try
{
writer = openIndexWriter(null, null);
writer.addIndexes(new Directory[] { dir });
writer.maybeMerge();
} finally
{
closeIndexWriter();
}
}