The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

dpawson (54) [Avatar] Offline
#1
the text uses
Directory dir = FSDirectory.open(new File(“/path/to/index”));
IndexReader reader = IndexReader.open(dir);
IndexSearcher searcher = new IndexSearcher(reader);

In the code (Searcher.java)
you use

Directory dir = FSDirectory.open(new File(indexDir)); //3
IndexSearcher is = new IndexSearcher(dir); //3

Is IndexReader necessary? It appears not (and it is abstract)
mike.mccandless (221) [Avatar] Offline
#2
Re: pdf p102, 103 Use of indexReader rather than indexSearcher
They do exactly the same thing -- under the hood IndexSearcher will call IndexReader.open on the Directory you pass in. But if you need access to the IndexReader (say, you'll use .reopen later) then you should create the reader yourself.
dpawson (54) [Avatar] Offline
#3
Re: pdf p102, 103 Use of indexReader rather than indexSearcher
The please provide a rationale for the use of the intermediate class? E.g. when I would want to use it, or under what circumstances?
mike.mccandless (221) [Avatar] Offline
#4
Re: pdf p102, 103 Use of indexReader rather than indexSearcher
The examples throughout the book that use IndexReader are cases where you want an IndexReader. Eg deleting by docID (chapter 2), opening near-real-time reader, doing reopen.

Section 3.2.1 already talks through opening IndexReader vs IndexSearcher directly from Directory.