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"<ian....@gmail.com>; Date: Fri, Jan 13, 2012 05:47 PM To: "java-user"<java-user@lucene.apache.org>; 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. -- Ian. On Wed, Jan 11, 2012 at 10:51 PM, Cheng <zhoucheng2...@gmail.com> 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: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org