我有以下代码,使用Lucene.NET V4检查文件是否存在于我的索引中。Lucene.NET - 检查索引中是否存在文档
bool exists = false;
IndexReader reader = IndexReader.Open(Lucene.Net.Store.FSDirectory.Open(lucenePath), false);
Term term = new Term("filepath", "\\myFile.PDF");
TermDocs docs = reader.TermDocs(term);
if (docs.Next())
{
exists = true;
}
文件myFile.PDF
肯定存在,但它总是回来为false
。当我看到在调试docs
,其Doc
和Freq
性声明,他们“扔类型的异常‘System.NullReferenceException’。