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 Lee Goddard <le...@gmail.com> on 2011/03/04 14:20:24 UTC
IndexReader.reopen() question
Hello list,
Does this look correct? I am told it is not functioning, in that new
entries to the index are not being picked-up?
Thanks
Lee
try {
if (! reader.isCurrent()){
IndexReader newReader = reader.reopen();
if (newReader != reader) {
// reader was reopened
searcher.close();
reader.close();
}
reader = newReader;
searcher = new IndexSearcher(reader);
if (searcher == null) throw new ServletException(
"searcher is null (init a)" );
}
} catch (CorruptIndexException e){
throw new ServletException( "Could not refresh reader?
"+e.getMessage() );
} catch (IOException e){
throw new ServletException( "Could not refresh reader?
"+e.getMessage() );
} catch (Exception e){
throw new ServletException( "Could not re-open reader?
"+e.getMessage() );
}
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: IndexReader.reopen() question
Posted by Lee <le...@gmail.com>.
Thanks Ian, and Mike -- the code below was the result of badly copying
the Javadocs in exasperation and panic: all points taken with gratitude.
Cheers
Lee
On 04/03/2011 16:40, Ian Lea wrote:
> Looks basically OK to me. I wonder if you need the isCurrent() check
> as well as if (newReader != reader) but shouldn't do any harm.
> Likewise there doesn't seem much point in reassigning reader and
> creating a new searcher if newReader is the same as reader. But I
> don't think that either of those would cause new entries not to be
> picked up.
>
> I'd ask for some evidence and/or check that the new entries really
> have been added.
>
>
> --
> Ian.
>
>
> On Fri, Mar 4, 2011 at 1:20 PM, Lee Goddard<le...@gmail.com> wrote:
>> Hello list,
>>
>> Does this look correct? I am told it is not functioning, in that new
>> entries to the index are not being picked-up?
>>
>> Thanks
>> Lee
>>
>>
>> try {
>> if (! reader.isCurrent()){
>> IndexReader newReader = reader.reopen();
>> if (newReader != reader) {
>> // reader was reopened
>> searcher.close();
>> reader.close();
>> }
>> reader = newReader;
>> searcher = new IndexSearcher(reader);
>> if (searcher == null) throw new ServletException( "searcher
>> is null (init a)" );
>> }
>> } catch (CorruptIndexException e){
>> throw new ServletException( "Could not refresh reader?
>> "+e.getMessage() );
>> } catch (IOException e){
>> throw new ServletException( "Could not refresh reader?
>> "+e.getMessage() );
>> } catch (Exception e){
>> throw new ServletException( "Could not re-open reader?
>> "+e.getMessage() );
>> }
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: IndexReader.reopen() question
Posted by Ian Lea <ia...@gmail.com>.
Looks basically OK to me. I wonder if you need the isCurrent() check
as well as if (newReader != reader) but shouldn't do any harm.
Likewise there doesn't seem much point in reassigning reader and
creating a new searcher if newReader is the same as reader. But I
don't think that either of those would cause new entries not to be
picked up.
I'd ask for some evidence and/or check that the new entries really
have been added.
--
Ian.
On Fri, Mar 4, 2011 at 1:20 PM, Lee Goddard <le...@gmail.com> wrote:
> Hello list,
>
> Does this look correct? I am told it is not functioning, in that new
> entries to the index are not being picked-up?
>
> Thanks
> Lee
>
>
> try {
> if (! reader.isCurrent()){
> IndexReader newReader = reader.reopen();
> if (newReader != reader) {
> // reader was reopened
> searcher.close();
> reader.close();
> }
> reader = newReader;
> searcher = new IndexSearcher(reader);
> if (searcher == null) throw new ServletException( "searcher
> is null (init a)" );
> }
> } catch (CorruptIndexException e){
> throw new ServletException( "Could not refresh reader?
> "+e.getMessage() );
> } catch (IOException e){
> throw new ServletException( "Could not refresh reader?
> "+e.getMessage() );
> } catch (Exception e){
> throw new ServletException( "Could not re-open reader?
> "+e.getMessage() );
> }
>
>
> ---------------------------------------------------------------------
> 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: IndexReader.reopen() question
Posted by Michael McCandless <lu...@mikemccandless.com>.
On Fri, Mar 4, 2011 at 8:20 AM, Lee Goddard <le...@gmail.com> wrote:
> Does this look correct? I am told it is not functioning, in that new
> entries to the index are not being picked-up?
Also be careful w/ threads -- if queries are "in flight", closing the
reader out from other them will cause problems.
--
Mike
http://blog.mikemccandless.com
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org