Reuse of IndexReader

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Reuse of IndexReader

Dominik Bruhn
Hy,
I got the following situation:
A Servlet runing in Tomcat5. When starting the servlet up it automatically
creates a IndexReader and stores it in a static variable. For searching this
variable is used. When adding a document to the index, I create a
IndexWriter, write the Document, and close the IndexWriter again.
This leads into a problem: The IndexReader only searches in documents which
were in the index when the Reader was created. Every Document added
afterwards is not searched in. When I restart the Servlet I can search in
those documents.

Is this a normal behaviour and how can I avoid this?

Thanks
--
Dominik Bruhn
mailto: [hidden email]
http://www.dbruhn.de

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Reuse of IndexReader

Erik Hatcher

On Jul 12, 2006, at 12:48 PM, Dominik Bruhn wrote:

> Hy,
> I got the following situation:
> A Servlet runing in Tomcat5. When starting the servlet up it  
> automatically
> creates a IndexReader and stores it in a static variable. For  
> searching this
> variable is used. When adding a document to the index, I create a
> IndexWriter, write the Document, and close the IndexWriter again.
> This leads into a problem: The IndexReader only searches in  
> documents which
> were in the index when the Reader was created. Every Document added
> afterwards is not searched in. When I restart the Servlet I can  
> search in
> those documents.
>
> Is this a normal behaviour and how can I avoid this?

This is normal behavior.  You'll need to develop some scheme for  
opening a new IndexReader when it is appropriate.  Lots of caveats  
apply.  See Solr for a solid implementation of how this can be done.

        Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Reuse of IndexReader

Erick Erickson
In reply to this post by Dominik Bruhn
This is normal behavior. When you open a reader, it takes a snapshot of the
index and uses that snapshot until it is closed, and any updates to the
index in the meantime are invisible to that reader.

You could periodically close and reopen the reader to get the latest data,
it's not necessary to stop the program. But as you describe things, you'd
have to take care that you don't close the reader if one of your (I presume)
threads was actually using it.

Best
Erick
Reply | Threaded
Open this post in threaded view
|

Re: Reuse of IndexReader

Dominik Bruhn
Hy,
thanks for your answers.
Uppon creation of the Reader, does Lucene copy the whole Index into RAM? Or is
this cache filled while searching? How can I find out how long it takes to
create the IndexReader? Just time to Create-Call?

Thanks
--
Dominik Bruhn
mailto: [hidden email]
http://www.dbruhn.de

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Reuse of IndexReader

Mark Miller-3
http://www.nabble.com/Fwd%3A-Contribution%3A-LuceneIndexAccessor-t17416.html#a47049

A good implementation for what you need.

- Mark

On 7/12/06, Dominik Bruhn <[hidden email]> wrote:

>
> Hy,
> thanks for your answers.
> Uppon creation of the Reader, does Lucene copy the whole Index into RAM?
> Or is
> this cache filled while searching? How can I find out how long it takes to
> create the IndexReader? Just time to Create-Call?
>
> Thanks
> --
> Dominik Bruhn
> mailto: [hidden email]
> http://www.dbruhn.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Reuse of IndexReader

Mark Miller-3
I have not seen an expert's comment on the previous code I linked to. It
seems (to my young inexperienced eyes) to do an optimal job of providing
realtime access to an index. Anyone else have some experience with this
code?

On 7/12/06, Mark Miller <[hidden email]> wrote:

>
>
> http://www.nabble.com/Fwd%3A-Contribution%3A-LuceneIndexAccessor-t17416.html#a47049
>
> A good implementation for what you need.
>
> - Mark
>
>
> On 7/12/06, Dominik Bruhn <[hidden email]> wrote:
> >
> > Hy,
> > thanks for your answers.
> > Uppon creation of the Reader, does Lucene copy the whole Index into RAM?
> > Or is
> > this cache filled while searching? How can I find out how long it takes
> > to
> > create the IndexReader? Just time to Create-Call?
> >
> > Thanks
> > --
> > Dominik Bruhn
> > mailto: [hidden email]
> > http://www.dbruhn.de
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>