我无法使用 Lucene.NET 2.0.0.4 搜索确切的短语
例如,我正在搜索“范围属性设置变量”(包括引号)但没有收到匹配项,我已经确认 100% 的短语存在。
谁能建议我哪里出错了?Lucene.NET 甚至支持吗?像往常一样,API 文档并没有太大帮助,我读过的一些 CodeProject 文章也没有特别提到这一点。
使用以下代码创建索引:
Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory("Index", true);
Analyzer analyzer = new Lucene.Net.Analysis.SimpleAnalyzer();
IndexWriter indexWriter = new Lucene.Net.Index.IndexWriter(dir, analyzer,true);
//create a document, add in a single field
Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
Lucene.Net.Documents.Field fldContent = new Lucene.Net.Documents.Field(
"content", File.ReadAllText(@"Documents\100.txt"),
Lucene.Net.Documents.Field.Store.YES,
Lucene.Net.Documents.Field.Index.TOKENIZED);
doc.Add(fldContent);
//write the document to the index
indexWriter.AddDocument(doc);
然后我使用以下方法搜索一个短语:
//state the file location of the index
Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory("Index", false);
//create an index searcher that will perform the search
IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(dir);
QueryParser qp = new QueryParser("content", new SimpleAnalyzer());
// txtSearch.Text Contains a phrase such as "this is a phrase"
Query q=qp.Parse(txtSearch.Text);
//execute the query
Lucene.Net.Search.Hits hits = searcher.Search(q);
目标文档约为 7 MB 纯文本。
我已经看到了这个先前的问题,但是我不想要一个邻近搜索,只是一个精确的短语搜索。