Open directory through IndexReader or IndexSearcher? in lucene

what is the difference between these two codes? based on performance oriented and documentation oriented

using the directory directly in IndexSearcher

Analyzer anal = new StandardAnalyzer(Version.LUCENE_30);
QueryParser parser = new QueryParser(Version.LUCENE_30, "", anal);
Query query = parser.parse(queryStr);
Searcher searcher = new IndexSearcher(NIOFSDirectory.open(new File(indexDir)));

using the directory in IndexReader, then open the search engine with this reader

Analyzer anal = new StandardAnalyzer(Version.LUCENE_30);
QueryParser parser = new QueryParser(Version.LUCENE_30, "", anal);
Query query = parser.parse(queryStr);
IndexReader ir = IndexReader.open(NIOFSDirectory.open(new File(indexDir)), false);
IndexSearcher searcherNew = new IndexSearcher(ir);
+3
source share
1 answer

IndexSearcher is a lightweight wrapper around IndexReader. Even if you use the IndexSearcher constructor, IndexReader will be open under the hoods , so you can expect the same result from your two fragments.

, , , IndexSearcher . , Lucene 3.5.

+6

All Articles