lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <...@thetaphi.de>
Subject RE: reading index
Date Fri, 07 Aug 2009 16:07:37 GMT
You should *not* create a new Searcher for every request. Open the Searcher
one time (e.g. in your servlets init() method) and keep it open. Close it on
we application shutdown.

If your index changes inbetween, you should reopen it (e.g. by testing for
IndexReader.isCurrent() and if not, reopening it). Searcher is threadsafe,
so no worries.

IndexSearcher has no reopen method, so you must reopen the underlying
reader. A strategy to do that is to open the IndexReader one time (not the
IndexSearcher), and reopen it as needed. Then create an IndexSearcher from
it (which is no cost at all, as IndexSearcher is just a wrapper around
IndexReader). So use the ctor of IndexSearcher that takes an IndexReader.
You can create a new IndexSearcher on top of an IndexReader for each
request, there is not problem with it (because it is a thin wrapper). The
important thing is only, that a reopened Reader needs a new IndexSearcher.
This is done by using a fresh instance for each request. Another possibility
is to also reuse the IndexSearcher, but replace it with a new one after each
reopen of the IndexReader.

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de

> -----Original Message-----
> From: m.harig [mailto:m.harig@gmail.com]
> Sent: Friday, August 07, 2009 5:37 PM
> To: java-user@lucene.apache.org
> Subject: Re: reading index
> 
> 
> Thanks,
>                this is my code snippet
> 
>               public void doSearch(){
>                 ..............................
> 
>                 Query query =
> .................................................
> 
>                 IndexSearcher searcher = new IndexSearcher(directory);
>                 Hits hits = searcher.search(query);
> 
>                for(int i=start;i<end;i++){
> 
>                        // getting doc to display fields
> 
>                }
> 
>                searcher.close();
>                 }
> 
>           am calling this method everytime when a user tries to search a
> keyword. is it correct or wrong? If wrong please anyone tell me how to do
> it?
> --
> View this message in context: http://www.nabble.com/reading-index-
> tp24862928p24866995.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org



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


Mime
View raw message