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 Rob Outar <ro...@ideorlando.org> on 2002/11/22 17:56:51 UTC

Updating documents

I have something odd going on, I have code that updates documents in the
index so I have to delete it and then re add it.  When I re-add the document
I immediately do a search on the newly added field which fails.  However, if
I rerun the query a second time it works??  I have the Searcher class as an
attribute of my search class, does it not see the new changes?  Seems like
when it is reinitialized with the changed index it is then able to search on
the newly added field??

Let me know if anyone has encountered this.

Thanks,

Rob



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Updating documents

Posted by Doug Cutting <cu...@lucene.com>.
A deletion is only visible in other IndexReader instances created after 
the IndexReader where you made the deletion is closed.  So if you're 
searching using a different IndexReader, you need to re-open it after 
the deleting IndexReader is closed.  The lastModified method helps you 
to figure out when this is required.  The standard idiom is to cache the 
lastModified date returned when a reader is opened, then check it 
against the current value before each search.  When it is different, 
re-open.

Note: If you have many searching threads, it is most efficient for them 
to share an IndexReader.  But if one thread closes the reader while 
others are still searching it, then those searches may crash.  So, when 
re-opening the index, don't immediately close the old one.  Rather just 
let the garbage collector close its open files.  The only problem with 
this approach is that, if your index changes more frequently than the 
garbage collector collects old indexes then you can run out of file handles.

Hmm.  It would probably make things simpler if an IndexReader cached its 
lastModifiedDate when it was opened, so that applications don't have to 
do this themseleves to find out whether an IndexReader is out-of-date...

Doug

Rob Outar wrote:
> There is a reloading issue but I do not think lastModified is it:
> 
> static long lastModified(Directory directory)
>           Returns the time the index in this directory was last modified.
> static long lastModified(File directory)
>           Returns the time the index in the named directory was last
> modified.
> static long lastModified(String directory)
>           Returns the time the index in the named directory was last
> modified.
> 
> Do I need to create a new instance of IndexSearcher each time I search?
> 
> Thanks,
> 
> Rob
> 
> 
> -----Original Message-----
> From: Otis Gospodnetic [mailto:otis_gospodnetic@yahoo.com]
> Sent: Friday, November 22, 2002 12:20 PM
> To: Lucene Users List
> Subject: Re: Updating documents
> 
> 
> Don't you have to make use of lastModified method (I think in
> IndexSearcher), to 'reload' your instance of IndexSearcher?  I'm
> pulling this from some old, not very fresh memory....
> 
> Otis
> 
> --- Rob Outar <ro...@ideorlando.org> wrote:
> 
>>I have something odd going on, I have code that updates documents in
>>the
>>index so I have to delete it and then re add it.  When I re-add the
>>document
>>I immediately do a search on the newly added field which fails.
>>However, if
>>I rerun the query a second time it works??  I have the Searcher class
>>as an
>>attribute of my search class, does it not see the new changes?  Seems
>>like
>>when it is reinitialized with the changed index it is then able to
>>search on
>>the newly added field??
>>
>>Let me know if anyone has encountered this.
>>
>>Thanks,
>>
>>Rob
>>
>>
>>
>>--
>>To unsubscribe, e-mail:
>><ma...@jakarta.apache.org>
>>For additional commands, e-mail:
>><ma...@jakarta.apache.org>
>>
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus  Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Updating documents

Posted by Otis Gospodnetic <ot...@yahoo.com>.
Btw. I have posted the code for this before, so you can find it in the
list archives.

Otis

--- Scott Ganyo <sc...@etapestry.com> wrote:
> Not each time you search, but if you've modified the index since you 
> opened the searcher, you need to create a new searcher to get the
> changes.
> 
> Scott
> 
> Rob Outar wrote:
> 
> > There is a reloading issue but I do not think lastModified is it:
> >
> > static long lastModified(Directory directory)
> >           Returns the time the index in this directory was last
> modified.
> > static long lastModified(File directory)
> >           Returns the time the index in the named directory was
> last
> > modified.
> > static long lastModified(String directory)
> >           Returns the time the index in the named directory was
> last
> > modified.
> >
> > Do I need to create a new instance of IndexSearcher each time I
> search?
> >
> > Thanks,
> >
> > Rob
> >
> >
> > -----Original Message-----
> > From: Otis Gospodnetic [mailto:otis_gospodnetic@yahoo.com]
> > Sent: Friday, November 22, 2002 12:20 PM
> > To: Lucene Users List
> > Subject: Re: Updating documents
> >
> >
> > Don't you have to make use of lastModified method (I think in
> > IndexSearcher), to 'reload' your instance of IndexSearcher?  I'm
> > pulling this from some old, not very fresh memory....
> >
> > Otis
> >
> > --- Rob Outar  wrote:
> >
> > >I have something odd going on, I have code that updates documents
> in
> > >the
> > >index so I have to delete it and then re add it.  When I re-add
> the
> > >document
> > >I immediately do a search on the newly added field which fails.
> > >However, if
> > >I rerun the query a second time it works??  I have the Searcher
> class
> > >as an
> > >attribute of my search class, does it not see the new changes? 
> Seems
> > >like
> > >when it is reinitialized with the changed index it is then able to
> > >search on
> > >the newly added field??
> > >
> > >Let me know if anyone has encountered this.
> > >
> > >Thanks,
> > >
> > >Rob
> > >
> > >
> > >
> > >--
> > >To unsubscribe, e-mail:
> > >
> > >For additional commands, e-mail:
> > >
> > >
> >
> >
> > __________________________________________________
> > Do you Yahoo!?
> > Yahoo! Mail Plus  Powerful. Affordable. Sign up now.
> > http://mailplus.yahoo.com
> >
> > --
> > To unsubscribe, e-mail:
> >
> > For additional commands, e-mail:
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > For additional commands, e-mail: 
> 
> 
> -- 
> Brain: Pinky, are you pondering what I�m pondering?
> Pinky: I think so, Brain, but calling it a pu-pu platter? Huh, what
> were 
> they thinking?
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus � Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Updating documents

Posted by Scott Ganyo <sc...@etapestry.com>.
Not each time you search, but if you've modified the index since you 
opened the searcher, you need to create a new searcher to get the changes.

Scott

Rob Outar wrote:

> There is a reloading issue but I do not think lastModified is it:
>
> static long lastModified(Directory directory)
>           Returns the time the index in this directory was last modified.
> static long lastModified(File directory)
>           Returns the time the index in the named directory was last
> modified.
> static long lastModified(String directory)
>           Returns the time the index in the named directory was last
> modified.
>
> Do I need to create a new instance of IndexSearcher each time I search?
>
> Thanks,
>
> Rob
>
>
> -----Original Message-----
> From: Otis Gospodnetic [mailto:otis_gospodnetic@yahoo.com]
> Sent: Friday, November 22, 2002 12:20 PM
> To: Lucene Users List
> Subject: Re: Updating documents
>
>
> Don't you have to make use of lastModified method (I think in
> IndexSearcher), to 'reload' your instance of IndexSearcher?  I'm
> pulling this from some old, not very fresh memory....
>
> Otis
>
> --- Rob Outar  wrote:
>
> >I have something odd going on, I have code that updates documents in
> >the
> >index so I have to delete it and then re add it.  When I re-add the
> >document
> >I immediately do a search on the newly added field which fails.
> >However, if
> >I rerun the query a second time it works??  I have the Searcher class
> >as an
> >attribute of my search class, does it not see the new changes?  Seems
> >like
> >when it is reinitialized with the changed index it is then able to
> >search on
> >the newly added field??
> >
> >Let me know if anyone has encountered this.
> >
> >Thanks,
> >
> >Rob
> >
> >
> >
> >--
> >To unsubscribe, e-mail:
> >
> >For additional commands, e-mail:
> >
> >
>
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus  Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
>
> --
> To unsubscribe, e-mail:
>
> For additional commands, e-mail:
>
>
>
> --
> To unsubscribe, e-mail:
> For additional commands, e-mail: 


-- 
Brain: Pinky, are you pondering what I’m pondering?
Pinky: I think so, Brain, but calling it a pu-pu platter? Huh, what were 
they thinking?


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Updating documents

Posted by Otis Gospodnetic <ot...@yahoo.com>.
No, only each time the index is modified after the time you created
your last IndexSearcher instance, if I remember correctly.

Otis

--- Rob Outar <ro...@ideorlando.org> wrote:
> There is a reloading issue but I do not think lastModified is it:
> 
> static long lastModified(Directory directory)
>           Returns the time the index in this directory was last
> modified.
> static long lastModified(File directory)
>           Returns the time the index in the named directory was last
> modified.
> static long lastModified(String directory)
>           Returns the time the index in the named directory was last
> modified.
> 
> Do I need to create a new instance of IndexSearcher each time I
> search?
> 
> Thanks,
> 
> Rob
> 
> 
> -----Original Message-----
> From: Otis Gospodnetic [mailto:otis_gospodnetic@yahoo.com]
> Sent: Friday, November 22, 2002 12:20 PM
> To: Lucene Users List
> Subject: Re: Updating documents
> 
> 
> Don't you have to make use of lastModified method (I think in
> IndexSearcher), to 'reload' your instance of IndexSearcher?  I'm
> pulling this from some old, not very fresh memory....
> 
> Otis
> 
> --- Rob Outar <ro...@ideorlando.org> wrote:
> > I have something odd going on, I have code that updates documents
> in
> > the
> > index so I have to delete it and then re add it.  When I re-add the
> > document
> > I immediately do a search on the newly added field which fails.
> > However, if
> > I rerun the query a second time it works??  I have the Searcher
> class
> > as an
> > attribute of my search class, does it not see the new changes? 
> Seems
> > like
> > when it is reinitialized with the changed index it is then able to
> > search on
> > the newly added field??
> >
> > Let me know if anyone has encountered this.
> >
> > Thanks,
> >
> > Rob
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus  Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus � Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Updating documents

Posted by Rob Outar <ro...@ideorlando.org>.
There is a reloading issue but I do not think lastModified is it:

static long lastModified(Directory directory)
          Returns the time the index in this directory was last modified.
static long lastModified(File directory)
          Returns the time the index in the named directory was last
modified.
static long lastModified(String directory)
          Returns the time the index in the named directory was last
modified.

Do I need to create a new instance of IndexSearcher each time I search?

Thanks,

Rob


-----Original Message-----
From: Otis Gospodnetic [mailto:otis_gospodnetic@yahoo.com]
Sent: Friday, November 22, 2002 12:20 PM
To: Lucene Users List
Subject: Re: Updating documents


Don't you have to make use of lastModified method (I think in
IndexSearcher), to 'reload' your instance of IndexSearcher?  I'm
pulling this from some old, not very fresh memory....

Otis

--- Rob Outar <ro...@ideorlando.org> wrote:
> I have something odd going on, I have code that updates documents in
> the
> index so I have to delete it and then re add it.  When I re-add the
> document
> I immediately do a search on the newly added field which fails.
> However, if
> I rerun the query a second time it works??  I have the Searcher class
> as an
> attribute of my search class, does it not see the new changes?  Seems
> like
> when it is reinitialized with the changed index it is then able to
> search on
> the newly added field??
>
> Let me know if anyone has encountered this.
>
> Thanks,
>
> Rob
>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus  Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Updating documents

Posted by Otis Gospodnetic <ot...@yahoo.com>.
Don't you have to make use of lastModified method (I think in
IndexSearcher), to 'reload' your instance of IndexSearcher?  I'm
pulling this from some old, not very fresh memory....

Otis

--- Rob Outar <ro...@ideorlando.org> wrote:
> I have something odd going on, I have code that updates documents in
> the
> index so I have to delete it and then re add it.  When I re-add the
> document
> I immediately do a search on the newly added field which fails. 
> However, if
> I rerun the query a second time it works??  I have the Searcher class
> as an
> attribute of my search class, does it not see the new changes?  Seems
> like
> when it is reinitialized with the changed index it is then able to
> search on
> the newly added field??
> 
> Let me know if anyone has encountered this.
> 
> Thanks,
> 
> Rob
> 
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus � Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>