I am closing the directory and that's the line where the exception about the open files is being thrown:
public class MetaphoneReplacementAnaylyzerTest extends LuceneTestCase { @Test public void testKoolKat() throws Exception { Analyzer analyzer = new MetaphoneReplacementAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, analyzer); // Directory directory = new RAMDirectory(); Directory directory = newDirectory(); IndexWriter writer = new IndexWriter(directory, config); Document doc = new Document(); doc.add(new Field("contents", "cool cat", Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc, analyzer); writer.commit(); *** IndexSearcher searcher = new IndexSearcher(IndexReader.open(directory)); Query q = new QueryParser(Version.LUCENE_36, "contents", analyzer).parse("kool kat"); TopDocs hits = searcher.search(q, 1); assertEquals(1, hits.totalHits); int docID = hits.scoreDocs[0].doc; doc = searcher.doc(docID); assertEquals("cool cat", doc.get("contents")); writer.close(); searcher.close(); directory.close(); // <=== if I comment this out, I get an assertion failure about the directory not being closed. If I leave this in I get an error about the files being open } } Interestingly, if I change the *** line above to use the deprecated constructor taking just the directory it works fine: IndexSearcher searcher = new IndexSearcher(directory); Brendan Grainger brendan.grain...@gmail.com www.kuripai.com On Jun 28, 2012, at 7:36 PM, Robert Muir wrote: > Hello, > > this part of the stacktrace: > > >> Caused by: java.lang.RuntimeException: unclosed IndexInput: _0.prx >> at >> org.apache.lucene.store.MockDirectoryWrapper.addFileHandle(MockDirectoryWrapper.java:472) >> at >> org.apache.lucene.store.MockDirectoryWrapper.openInput(MockDirectoryWrapper.java:497) >> at org.apache.lucene.store.Directory.openInput(Directory.java:145) >> at >> org.apache.lucene.index.SegmentCoreReaders.<init>(SegmentCoreReaders.java:96) >> at org.apache.lucene.index.SegmentReader.get(SegmentReader.java:116) >> at org.apache.lucene.index.SegmentReader.get(SegmentReader.java:94) >> at >> org.apache.lucene.index.DirectoryReader.<init>(DirectoryReader.java:105) >> at >> org.apache.lucene.index.ReadOnlyDirectoryReader.<init>(ReadOnlyDirectoryReader.java:27) >> at >> org.apache.lucene.index.DirectoryReader$1.doBody(DirectoryReader.java:78) >> at >> org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:709) >> at >> org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:72) >> at org.apache.lucene.index.IndexReader.open(IndexReader.java:256) >> at >> com.kuripai.lucene.analysis.MetaphoneReplacementAnaylyzerTest.testKoolKat(MetaphoneReplacementAnaylyzerTest.java:36) >> ... 39 more >> > > is telling you where in your code you opened the un-closed object that > you need to close. > > looks to me like the problem is how you open your reader: > new IndexSearcher(IndexReader.open(directory)); > > in this case (where IndexSearcher takes a reader that you passed in), > closing the searcher won't actually close the underlying reader. > you passed it in, so you should be sure to close this reader yourself. > > -- > lucidimagination.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org >