Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Committed changes visibility in Lucene. Best practices

I'm using Lucene 3.0.3. I've made a Spring bean aiming to encapsulate all operations on the same index.

public class IndexOperations {

    private IndexWriter writer;
    private IndexReader reader;
    private IndexSearcher searcher;

    public void init() {...}
    public void destroy() {...}

    public void save(Document d) {...}
    public void delete(Document d) {...}
    public List<Document> list() {...}

}

In order to permit fast changes and searches, I thought leaving writer, reader and searcher open could be a good idea. But the problem is that commited changes on writer can't be seen by readers until reopen. And this operation can be costly, so maybe is not a good idea for fast searches.

What would be the best approach for this typical scenario?

like image 310
sinuhepop Avatar asked Jan 14 '11 12:01

sinuhepop


1 Answers

You should keep the writer always open, but don't persist the reader/searcher. When you need a searcher just do IndexSearcher srch = new IndexSearcher(writer.getReader()); This way the searcher will get the most recent changes, even if they aren't flushed to disk yet (giving you the best of both worlds).

like image 112
Xodarap Avatar answered Sep 30 '22 09:09

Xodarap