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 Amin Mohammed-Coleman <am...@gmail.com> on 2009/01/18 10:43:01 UTC
MultiSearcher: close()
Hi
I have a class that uses the MultiSearcher inorder to perform search
using different other searches. Here is a snippet of the class:
MultiSearcher multiSearcher = null;
try {
multiSearcher = new MultiSearcher(searchers.toArray(new
IndexSearcher[] {}));
QueryParser queryParser = new
MultiFieldQueryParser(FieldNameEnum.fieldNameDescriptions(), analyzer);
Query query = queryParser.parse(searchRequest.getSearchTerm());
//TODO: Sort and Filters
TopDocs topDocs = multiSearcher.search(query, 100);
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
LOGGER.debug("total number of hits for [" + query.toString() + " ]
= " +topDocs.totalHits);
for (ScoreDoc scoreDoc : scoreDocs) {
final Document doc = multiSearcher.doc(scoreDoc.doc);
float score = scoreDoc.score;
final BaseDocument baseDocument = new BaseDocument(doc, score);
Summary documentSummary = new DocumentSummaryImpl(baseDocument);
summaryList.add(documentSummary);
}
} catch (Exception e) {
throw new IllegalStateException(e);
} finally {
if (multiSearcher != null) {
try {
multiSearcher.close();
} catch (IOException e) {
LOGGER.error("Could not close multisearcher. Need to investigate
why.", e);
}
}
}
This class is injected with dependencies using spring. Do I need to
explicitly close the multisearcher? If I call the method first time it
is ok, then any subsequent calls generate the following:
org.apache.lucene.store.AlreadyClosedException: this IndexReader is
closed
What is the best practice for this? I had a look at Lucene In Action
book and example doesn't close the multisearcher.
Any help would be highly appreciated.
Cheers