You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Ganesh - yahoo <em...@yahoo.co.in> on 2008/08/28 12:35:50 UTC

when to refresh IndexSearcher and IndexWriter

Hello all,

My index will get update very frequently.

1) When shall i need to optimize IndexWriter? I have planned to optimize 
every day. Is that fine.

2) When shall i need to re-open IndexReader and IndexSearcher? I have 
planned to do it every 10 minutes.

3) IndexSearcher could be used across threads. If i have to re-open the 
IndexReader and IndexSearcher, then it should be synchronized. If i try to 
do this then i am ending up in doing complete search functionality in 
synchronization. Is there any better way to do that.

synchronized void search() {

if 10 mins is elapsed reopen the reader else use the original..

IndexSearcher.search().....

collect the hits
}
Is there any better way to do it.

Regards
Ganesh
 

Send instant messages to your online friends http://in.messenger.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: when to refresh IndexSearcher and IndexWriter

Posted by Michael McCandless <lu...@mikemccandless.com>.
Ganesh - yahoo wrote:

> Hello all,
>
> My index will get update very frequently.
>
> 1) When shall i need to optimize IndexWriter? I have planned to  
> optimize every day. Is that fine.

Probably you should test in your app, to see if optimization is even  
necessary and if so, at what frequency.  Optimize() is quite costly in  
IO and if done on the same machine doing searches will likely slow  
down the searches.

> 2) When shall i need to re-open IndexReader and IndexSearcher? I  
> have planned to do it every 10 minutes.

This is your design choice: how costly is it when your users receive  
stale results?  How frequently do you add/update docs to the index?

> 3) IndexSearcher could be used across threads. If i have to re-open  
> the IndexReader and IndexSearcher, then it should be synchronized.  
> If i try to do this then i am ending up in doing complete search  
> functionality in synchronization. Is there any better way to do that.
>
> synchronized void search() {

You can continue to use the old searcher even while a new IndexReader  
is being reopened, so, searches need not be synchronized.

However, once the reopen finishes (and, any warming that you need to  
do completes) the "swap out" of the old searcher for the new one must  
be done carefully such that new searches immediately start using the  
new searcher, and you do not close the old searcher until all running  
searches are done with it.

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org