Lucene best practice

Posted by Dragos on Programmers See other posts from Programmers or by Dragos
Published on 2012-03-18T21:31:47Z Indexed on 2012/03/19 2:15 UTC
Read the original article Hit count: 266

Filed under:

I am trying to understand how Lucene should be used.

From what I have read, creating an IndexReader is costly, so using a Search Manager shoulg be the right choice. However, a SearchManager should be produced by a NRTManager(which, by the way, should replace the IndexWriter for every add or delete operation performed). But in order to have a NRTManager, I should first have an IndexWriter, and here comes my problem.

The documentation says:

  • an IndexWriter is thread-safe
  • the constructor of this class takes a Directory object, so it seems creating an instace should be costly(as in the case of an IndexReader)
  • all changes are buffered and flushed periodically(so they seem to encourage using a single instance)

    but:

  • the changes, although flushed will only be visible after commit or close

  • after finished making updates(add/delete), the instance should be closed
  • I also found this: http://stackoverflow.com/questions/5374419/forgot-to-close-the-lucene-indexwriter-after-adding-documents-to-the-index where it is said that not closing a writer might ruin everything

So what am I really supposed to do? Is having a single IndexWriter instance a good idea(make only commit and never close it)?

EDIT: What is more, if I use NRTManager, how can I make acommit`? Is it even possible?

© Programmers or respective owner

Related posts about java