You haven't set reader
to be anything. You need to initialise it before using it. You can do this is you have the path of the index using:
IndexReader reader = IndexReader.Open(indexDirectoryPath);
or:
Directory directory = FSDirectory.Open(indexDirectoryPath);
IndexReader reader = IndexReader.Open(directory);
or:
DirectoryInfo directoryInfo = new DirectoryInfo(indexDirectoryPath);
Directory directory = FSDirectory.Open(directoryInfo);
IndexReader reader = IndexReader.Open(directory);
where indexDirectoryPath
in all cases is the full path of the index location as a string
. Which way you use depends on which version of Lucene.Net you are using.
Additionally, make sure that you close the reader when you have finished with it (by calling reader.Close()
), otherwise you will likely get file locking issues.