views:

143

answers:

2

I'm using Lucene search API in a web based application. Which method of Lucene's IndexSearcher class is recommended to use?Is any method faster than other?

1.IndexSearcher(Directory directory) 2.IndexSearcher(IndexReader r) 3.IndexSearcher(String path)

Thanks for reading.

+3  A: 

The constructor which accepts Directory and path to index internally use the constructor that accpets IndexReader. So, there is no performance advantage of one over others. Keep in mind that if you create searcher with IndexReader, you have to close the reader explicitly after you close the searcher.

Shashikant Kore
A: 

It's all about convenience.

If you just want to create an IndexSearcher, use the one that accepts a path.

If you already have a Directory object, use the one that accepts a Directory.

And if you have an IndexReader... you get the point. Just remember that if you provided an IndexReader, you're expected to close it yourself after you've closed the IndexSearcher.

I highly recommend grabbing a copy of the Lucene source code. It is very readable, and can answer a lot of these questions.

itsadok
Can you please answer this one?http://stackoverflow.com/questions/899542/problem-using-same-instance-of-indexsearcher-for-multiple-requests
Steve Chapman