我正在尝试删除文档,但我无法以任何方式删除它。与我的示例相关的特定事情是我使用 RAMDirectory 作为目录并且我使用的是 Lucene.Net 3.0.3 版本。我的例子如下。
public void DeleteIndex(IndexWriter writer,IndexSearcher searcher)
{
var boolQuery = new BooleanQuery();
boolQuery.Add(new TermQuery(new Term("Id", "2")), Occur.MUST);
boolQuery.Add(new TermQuery(new Term("Type", "Product")), Occur.MUST);
writer.DeleteDocuments(boolQuery);
writer.Optimize(true);
//writer.Flush(true, true, true);//even this line doesn't help
writer.Commit();
var result = searcher.Search(boolQuery,1); // I can access deleted doc in search results
}