Lucene.net 匹配阶段查询不起作用
Lucene.net matchphase query doesn't work
我正在尝试使用匹配短语查询,但一直没有结果。我在这里做错了什么?我用的是Lucene.net 3.0.3
using (var dir = new RAMDirectory())
{
var queryText = "Bruce Wayne";
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);
var sampleDocs = new SortedSet<String>() { "Bruce Wayne", "Wayne Bruce", "Bruce Batman Wayne" };
using (var writer = new IndexWriter(dir, analyzer, create: true, mfl: IndexWriter.MaxFieldLength.LIMITED))
{
foreach (var sampleDoc in sampleDocs)
{
var doc = new Document();
doc.Add(new Field("id", Guid.NewGuid().ToString("N"), Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.Add(new Field("name", sampleDoc, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
writer.AddDocument(doc);
}
}
var searcher = new IndexSearcher(dir, true);
var query = new PhraseQuery()
{
Slop = 2
};
foreach (var item in queryText.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries))
{
query.Add(new Term("name", item));
}
TopDocs docs = searcher.Search(query, 1000);
}
问题已解决 - 我忘记将查询文本小写
我正在尝试使用匹配短语查询,但一直没有结果。我在这里做错了什么?我用的是Lucene.net 3.0.3
using (var dir = new RAMDirectory())
{
var queryText = "Bruce Wayne";
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);
var sampleDocs = new SortedSet<String>() { "Bruce Wayne", "Wayne Bruce", "Bruce Batman Wayne" };
using (var writer = new IndexWriter(dir, analyzer, create: true, mfl: IndexWriter.MaxFieldLength.LIMITED))
{
foreach (var sampleDoc in sampleDocs)
{
var doc = new Document();
doc.Add(new Field("id", Guid.NewGuid().ToString("N"), Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.Add(new Field("name", sampleDoc, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
writer.AddDocument(doc);
}
}
var searcher = new IndexSearcher(dir, true);
var query = new PhraseQuery()
{
Slop = 2
};
foreach (var item in queryText.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries))
{
query.Add(new Term("name", item));
}
TopDocs docs = searcher.Search(query, 1000);
}
问题已解决 - 我忘记将查询文本小写