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 "m.harig" <m....@gmail.com> on 2009/08/07 13:10:50 UTC
reading index
hello all,
thanks to lucene. Am using lucene 2.4.0 for my application. My
doubt is , can i read the index for many number of times? i mean , i've a
search application which reads the index , which is 300MB in size, am
reading my index at every time the user hits the page . Is it good to read
index at every time? or else is there any caching technique to handle this?
--
View this message in context: http://www.nabble.com/reading-index-tp24862928p24862928.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
RE: reading index
Posted by "m.harig" <m....@gmail.com>.
Hello
Will my reader.reopen() method work on windows machine when the index get
updated? i mean my tomcat server will allow the reader to update my index?
please help me.
--
View this message in context: http://www.nabble.com/reading-index-tp24862928p24875673.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
RE: reading index
Posted by Uwe Schindler <uw...@thetaphi.de>.
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
Re: reading index
Posted by "m.harig" <m....@gmail.com>.
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
Re: reading index
Posted by Ian Lea <ia...@gmail.com>.
It's not clear to me what you mean by reading the index every time.
If you mean that you open a new searcher for every search, then no,
it's not good.
If you mean that every search or paging request gets passed to lucene
then that is standard practice and is fine.
See http://wiki.apache.org/lucene-java/ImproveSearchingSpeed for loads
of good advice.
--
Ian.
On Fri, Aug 7, 2009 at 12:10 PM, m.harig<m....@gmail.com> wrote:
>
> hello all,
>
> thanks to lucene. Am using lucene 2.4.0 for my application. My
> doubt is , can i read the index for many number of times? i mean , i've a
> search application which reads the index , which is 300MB in size, am
> reading my index at every time the user hits the page . Is it good to read
> index at every time? or else is there any caching technique to handle this?
> --
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org