Steve Chapman
Steve Chapman

Reputation: 1317

Is there any recommended IndexSearcher method?

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.

Upvotes: 1

Views: 322

Answers (2)

itsadok
itsadok

Reputation: 29352

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.

Upvotes: 0

Shashikant Kore
Shashikant Kore

Reputation: 5052

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.

Upvotes: 3

Related Questions