FAQ
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

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedJan 18, '09 at 9:43a
activeJan 18, '09 at 9:43a
posts1
users1
websitelucene.apache.org

1 user in discussion

Amin Mohammed-Coleman: 1 post

People

Translate

site design / logo © 2022 Grokbase