Is there a recommended IndexSearcher method?

I am using Lucene search API in a web application. Which method of the Lucene IndexSearcher class should you use? Is any method faster than others?

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

Thanks for reading.

+1


a source to share


2 answers


A constructor that accepts a directory and an index path internally uses a constructor that uses an IndexReader. Thus, there is no performance advantage of one over the other. Be aware that if you create a finder using IndexReader, you must close it explicitly after closing the finder.



+3


a source


It's all about convenience.

If you just want to create IndexSearcher

, use the one that accepts a path.

If you already have an object Directory

, use the one that accepts Directory

.



And if you have IndexReader

... you get the point. Just remember that if you have provided IndexReader

, you must close it yourself after you closed IndexSearcher

.

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

0


a source







All Articles