Ah, I see your problem. From the Lucene Javadocs on IndexSearcher.close():

"Note that the underlying IndexReader is not closed, if IndexSearcher
was constructed with IndexSearcher(IndexReader r). If the IndexReader
was supplied implicitly by specifying a directory, then the
IndexReader gets closed."

Since you are explicitly passing in an IndexReader, the IndexSearcher
is not closing it. But since you created the IndexReader without
retaining a reference to it, you can not close it, thus you will
always have an open index.

You have a couple of options:

Either retain a reference to IndexReader by doing the following:

IndexReader ir = IndexReader.open(indexName);
IndexSearcher searcher = new IndexSearcher(ir);

or if indexName is just the path to the index, then just use:

IndexSearcher searcher = new IndexSearcher(indexName);

since that will manage the IndexReader for you.

Hope that helps.

Patrick

CCing list for archives.


On Tue, 7 Sep 2004 18:38:43 -0400, hui liu <[EMAIL PROTECTED]> wrote:
> First of all, thanks for your reply:-)
> 
> But actually, I've already tried this and here is my code:
> 
> searcher = new IndexSearcher(IndexReader.open(indexName));
> 
> and at some later place I wrote:
> 
> IndexReader.close();
> 
> Both of them are within try and catch, and then I got such an error in
> IE by tomcat:
> 
> non-static method close() cannot be referenced from a static context.
> 
> I read the source code of IndexReader and found that the method
> close() is final not static. so I tried to change it to static, but
> got even more errors.
> 
> I am wondering how do you use lucene? Has anyone met with the same thing?
> 
> Thanks a lot.
> 
> Ivy.
> 
> 
> 
> 
> On Tue, 7 Sep 2004 17:03:00 -0400, Patrick Burleson <[EMAIL PROTECTED]> wrote:
> > This isn't a Tomcat specific problem, but sounds like a problem with
> > how you the reader is being used.
> >
> > Somewhere in the JSP a IndexReader variable was probably assigned to.
> > A line something like:
> >
> > IndexReader ir = IndexReader.open("somepath");
> >
> > To close the reader, and thus solve the problem, somewhere later, you need:
> >
> > ir.close();
> >
> > with the needed try/catch in place.
> >
> > Again, please refrain from cross-posting...just because it happened on
> > Tomcat doesn't make it a Tomcat problem. This is clearly a lucene
> > usage problem.
> >
> > Patrick
> >
> >
> >
> > On Tue, 7 Sep 2004 16:37:42 -0400, hui liu <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > >
> > > I met with such a problem with lucene demo:
> > >
> > > Each time when I create lucene index, I have to first stop tomcat, and
> > > restart tomcat after the index is created. The reason is: the index is
> > > locked when using IndexReader.open(index) method in the jsp file.
> > >
> > > So, I tried to modify the jsp codes by adding close(), but it shows
> > > error which said "close() is not a static method". I checked the
> > > source codes of lucene IndexReader methods, and found that the close()
> > > method is final not static. I tried to change it to static, but
> > > resulted in many errors.
> > >
> > > So, does anybody meet the similar problem as me? Do you have any solutions?
> > >
> > > Thank you very very much.....!!
> > >
> > > Ivy.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to