lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pulkit Singhal <pulkitsing...@gmail.com>
Subject Re: Does a IndexSearcher call incRef on the underlying reader?
Date Wed, 27 Oct 2010 17:01:07 GMT
Hello Mike,

1st of all, great book.

@Question3: It sounds like an IndexReader always starts with a count of zero
but that should not be a cause of worry because the value only gets acted
upon in a call to decRef() ... am I right?

@Question4: It seems to me that based on you explanation so far, the
IndexReader will end up closing after the very 1st search. That doesn't
sound too efficient given that keeping it alive and kicking is something
that is highly desirable ... no? Am I missing something or does that
responsibility fall elsewhere?

I hope I haven't hijacked my own thread?

- Pulkit

On Wed, Oct 27, 2010 at 12:52 PM, Michael McCandless <
lucene@mikemccandless.com> wrote:

> When you run a search, you call SearcherManager.get to obtain the
> current searcher.
>
> That does an incRef.
>
> So if while this query is running a new searcher is swapped in, the
> query is still save because it's holding a reference.  Ie the reader
> will have a refCount of 1 at that point.
>
> Then when the search finishes and calls SearcherManager.release, that
> drops the readers refCount to 0, which closes it.
>
> Note, though, that you must still lose your reference to the reader to
> allow GC to clean it up!
>
> Mike
>
> On Wed, Oct 27, 2010 at 12:48 PM, Pulkit Singhal
> <pulkitsinghal@gmail.com> wrote:
> > @Question2: Also I was wondering what happens to the code that may have
> been
> > using the searcher which got swapped out in SearcherManager? Does that
> > IndexSearcher continue to run and when it finishes the GC is free to
> collect
> > it? OR will the fact that the reader for that searcher has had its last
> > decRef() call take the reader's internal count to 0 ... cause someone who
> is
> > paging through results to see the server choking with exceptions?
> >
> > On Wed, Oct 27, 2010 at 12:35 PM, Pulkit Singhal <
> pulkitsinghal@gmail.com>wrote:
> >
> >> Hello,
> >>
> >> I have been looking at the SearcherManager example provided in the
> "Lucene
> >> In Action 2nd Edition" book. It seems like a great way to manage
> >> IndexReaders but I had a few questions about the Lucene API that
> poppedup
> >> after reading it:
> >>
> >> @Question: Does a IndexSearcher call upon an IndexReader's incRef()
> method
> >> internally when the reader is passed in as an argument to the searcher's
> >> constructor?
> >> @Motivation: I ask because, if that is the case then I will need to make
> an
> >> additional call to decRef(). Also the book claims that
> >> "IndexSearcher.close() is a no-op if you provide an already opened
> >> IndexReader when creating the IndexSearcher" so I guess I can't count on
> >> that close() method to call the decRef() method for me and I must call
> it
> >> myself?  Once again, I'm thinking of doing all this only if incRef() was
> >> called on the reader in the searcher's constructor, which I'm hoping
> someone
> >> will confirm for me.
> >>
> >> Thanks,
> >> - Pulkit
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message