lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "dyzc2010" <>
Subject Re: Is it necessary to create a new searcher?
Date Fri, 13 Jan 2012 16:06:23 GMT
Thanks for pointing that out for me. I will change the code.

My challenge is that I use a same reader for multiple threads. So if I have to close a reader
within a thread, the others may be affected. With that, what can I do within a thread to reopen
a new reader?
------------------ Original ------------------
From:  "Ian Lea"<>;
Date:  Fri, Jan 13, 2012 05:47 PM
To:  "java-user"<>; 

Subject:  Re: Is it necessary to create a new searcher?

The javadocs for openIfChanged say that it returns null if not
changed, so I don't think your code will work as is.  You need to
check the return value and you'll need to close the old reader if you
have been given a new one.

If you are going to be reopening if changed, there seems little point
in calling isCurrent() rather than openIfChanged().  Searchers are
based on readers and readers are tied to a segment and if only one or
two segments have changed, only those readers will be reopened.
So in general, a reopen after a small number of updates may well be
quicker than a reopen after a large number of updates.  How important
is it that your searches get up to date data? If vital, you'll have to
reopen.  If not so vital you could instead reopen every now and again.

You should take a look at NRTManager and NRTManagerReopenThread.
There's good info in the javadocs.


On Wed, Jan 11, 2012 at 10:51 PM, Cheng <> wrote:
> I am currently using the following statement at the end of each index
> writing, although I don't know if the writing modifies the indexes or not:
> is = new IndexSearcher(IndexReader.openIfChanged(ir));
> # is -> IndexSearcher, ir-> IndexReader
> My question is how expensive to create a searcher instance (I have
> potentially hundreds of thousands of docs added or modified so the cost to
> create a new searcher instance may be unbearable.)
> Should I use the IndexReader.isCurrent() instead to check if is current?
> Thanks

To unsubscribe, e-mail:
For additional commands, e-mail:
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message