出于某种原因,我无法让 SpanNearQuery 工作。我已经尝试调试过去 3 个小时,但徒劳无功。有人可以告诉我我是否在做一些愚蠢的事情吗?到目前为止,这是我的尝试:
public static void Test2()
{
Directory directory = FSDirectory.Open(new DirectoryInfo(Environment.CurrentDirectory + "\\LuceneIndex"));
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);
var writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
var article = new Document();
article.Add(new Field("Id", "TEST-111111", Field.Store.YES, Field.Index.ANALYZED));
article.Add(new Field("ArticleText", "How should I gather Active User statistics from the log file? There is somewhat more information available on Google.", Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(article);
writer.Optimize();
writer.Close();
IndexReader indexReader = IndexReader.Open(directory, true);
Searcher indexSearch = new IndexSearcher(indexReader);
SpanNearQuery qq = new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(new Term("ArticleText", "Active")), new SpanTermQuery(new Term("ArticleText", "User")) }, 3, true);
Console.WriteLine(qq.ToString());
TopDocs resultDocs = indexSearch.Search(qq, indexReader.MaxDoc());
Console.WriteLine("Results Found: " + resultDocs.totalHits); // Gives me zero
indexSearch.Close();
directory.Close();
Console.Read();
}