English 中文(简体)
Lucene 2.9.2:在指数Searcher的即时值下,已经关闭。
原标题:Lucene 2.9.2: AlreadyClosedException at instantiation of IndexSearcher

Context:
A helper facade class is providing search methods for my application. As performance is not an issue, a new IndexSearcher is created for each query.

对于每个询问,都设立了一个新的搜索器:

File indexFile = new File(String absolutePathToIndex);
IndexSearcher searcher = new IndexSearcher(indexFile.getAbsolutePath(), true);

有时,我拿到<条码>已关闭的Exception,我不理解,因为没有分享搜索器物体。

Any ideas? Any best practice of how to open the index? Known issues? Thanks.

Stacktrace:

org.apache.lucene.store.AlreadyClosedException: this Directory is closed
        at org.apache.lucene.store.Directory.ensureOpen(Directory.java:251)
        at org.apache.lucene.store.FSDirectory.listAll(FSDirectory.java:530)
        at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:585)
        at org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:69)
        at org.apache.lucene.index.IndexReader.open(IndexReader.java:476)
        at org.apache.lucene.index.IndexReader.open(IndexReader.java:243)
        at org.apache.lucene.search.IndexSearcher.<init>(IndexSearcher.java:78)

Proposed Solution #1: the way to go?

Directory directory = FSDirectory.open(File indexFile);
IndexSearcher searcher = new IndexSearcher(directory, true);
...do the query...
searcher.close();

Question: the above code from solution #1 is created for EACH query. Is it necessary to close the directory too? Having checked the source code of Lucene 2.9.2, searcher.close() does not close the directory associated with the internal reader object.

问题回答

The method which you call in this example is anyways deprecated. So maybe the use of the IndexSearcher(Directory path, boolean readOnly) shows up a different behavior.

You need to make sure that you dont close the Directory before every subsequent search finishes. So for example if you use this Directory multiple times and you reinstantiate the Searcher the other Searcher will be destroyed and probably close the Directory in the destructor.

因此,如果你已经使用未经解释的校长版本,则试图利用每名搜索者的新目录。

If an error only happens under high concurrent load, it suggests that perhaps you have multiple threads attempting to close the directory Or trying to read from already closed directory. You haven t clarified whether absolutePath is a local variable inside a method, or an instance variable in an object which is getting reused by multiple threads -- so it s hard to guess.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签