问题描述
如何在Lucene中对两个多字词短语进行邻近搜索.例如,我想找到所有黑色实验室*(黑色拉布拉多犬,黑色拉布拉多犬等),外加5个单词"pet shop".我应该使用哪个分析仪?建议使用哪个查询解析器?我正在使用Lucene.NET.我已经将ComplexPhraseQueryParser从Java移植到了C#,但是该解析器似乎并没有解决这个问题(或者也许我只是在错误地使用它).我刚刚开始使用Lucene,因此非常感谢您的帮助.
How can I do a proximity search for two multi-word phrases in Lucene. For example, I want to find allblack lab* (black labrador, black labradoodle, etc) withing 5 words of the phrase "pet shop". Which analyzer should I be using? Which query parser would be recommended? I'm working with Lucene.NET. I've ported the ComplexPhraseQueryParser from Java to C#, but that parser doesn't seem to be doing the trick (or perhaps I'm just using it wrong). I'm just getting started with Lucene, so your help is much appreciated.
推荐答案
您可以使用 SpanQuery :
new SpanNearQuery(
new SpanQuery[] {
new SpanNearQuery(
new SpanQuery[] {
new SpanTermQuery(new Term(FIELD, "black")),
new SpanMultiTermQueryWrapper<WildcardQuery>(new WildcardQuery(new Term(FIELD, "lab*"))),
},
0,
true),
new SpanNearQuery(
new SpanQuery[] {
new SpanTermQuery(new Term(FIELD, "pet")),
new SpanTermQuery(new Term(FIELD, "shop")),
},
0,
true),
},
5,
true);
默认的Lucene QueryParser
不支持跨度查询,但是您可以尝试环绕查询解析器.我在文档方面找不到其他东西.
The default Lucene QueryParser
doesn't support span queries, but you could try the Surround query parser. I couldn't find much else in the way of documentation.
You may also find this answer and this blog post useful.
这篇关于““黑色实验室"" Lucene中的“宠物店""〜5(带有多词短语的邻近搜索)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!