> From: Ype Kingma [mailto:[EMAIL PROTECTED]]
>
> Suppose I would like to retrieve all docs that are resulting
> from a query.
> I should then use the search() call with the HitCollector argument
> which is called back with collect(docNr, score)
>
> Would it be wise to sort by docNr when using IndexReader.doc(docNr) to
> get to the stored fields?
Yes, that would be the most efficient way. Note that HitCollector.collect()
is called with increasing document ids, so you don't actually have to
sort--they arrive in order.
> And another question. I looked at the source for searcher.close() and
> found that it closes its reader. Does that close the index reader used
> to perform the search? That would interfere with a strategy to keep
> an index reader open as long as possible and share it between threads.
You shouldn't close the Searcher. Reuse it too.
I may have confused things in an earlier message. One should keep a single
Searcher which uses a single IndexReader. Thus the code I posted earlier
for caching an IndexReader should really be caching a Searcher. The
IndexReader will be cached implicitly by the IndexSearcher. Thus the
correct code for caching the IndexReader in "latest" should be:
private Searcher searcher;
private long lastModified;
public synchronized Searcher getSearcher() throws IOException {
if (lastModified != IndexReader.lastModified("latest")) {
// there's a new index: open it
lastModified = IndexReader.lastModified("latest");
searcher = new IndexSearcher("latest");
}
return searcher;
}
Doug
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>