lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amin Mohammed-Coleman <ami...@gmail.com>
Subject MultiSearcher: close()
Date Sun, 18 Jan 2009 09:43:01 GMT
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



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message