lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mindaugas Žakšauskas" <>
Subject Reusing same IndexSearcher
Date Wed, 05 Mar 2008 17:18:54 GMT

Another newbie here...using Lucene 2.3.1 on Linux. Hopefully anyone
could advice me on /subj/.

Both IndexSearcher Javadoc and Lucene FAQ says the IndexSearcher
should be reused as it's thread safe. That's OK.
Now if I have index changed, I need to reopen the IndexReader that is
associated with it. How do I do this as IndexSearcher has no setter
method for IndexReader?

Let's speak in Java. Say, we've got a static singletone accessor method:

private static Searcher instance;
public static Searcher getLuceneSearcher () {
   if( instance == null ) {
      IndexReader reader = "/tmp/index_folder" );
      instance = new IndexSearcher( reader );    // simple yet boring
   } else {                                    // here goes the fun part
      IndexReader r_old = instance.getIndexReader();
      IndexReader r_new = r_old.reopen();
      if( r_old != r_new ) {
         r_old.close();                  // thanks for nice Javadoc, guys!
         // what to do now? there's no instance.setIndexReader( r_new )!
   return instance;

Of course, I could create a new IndexSearcher on the else branch and
return it. However, this approach resulted the infamous "too many open
files" exception. Lifting the `ulimit -n` to hundreds of thousands of
files didn't really help as the same exception was still being thrown
(actual resource usage fluctuating around 2000 of open files). Then
from `lsof` output I noticed that the same segment file was being open
more than once, apparently from different instances of
IndexSearchers/IndexReaders and went the path shown above. Maybe I'm
just plain wrong.

Really appreciate your advice.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message