邻近搜索示例 Lucene.Net
我想使用 Lucene.Net 进行邻近搜索。我看到这个问题,看起来这就是他的答案,但没有提供代码。 Java 文档说使用 ~ 字符和中间的单词数,但我不知道这个字符在代码中的位置。任何人都可以给我一个使用 Lucene.Net 进行邻近搜索的示例吗?
编辑:
到目前为止我所拥有的:
IndexSearcher searcher = new IndexSearcher(this.Directory, true);
string[] fieldList = new string[] { "Name", "Description" };
List<BooleanClause.Occur> occurs = new List<BooleanClause.Occur>();
foreach (string field in fieldList)
{
occurs.Add(BooleanClause.Occur.SHOULD);
}
Query searchQuery = MultiFieldQueryParser.Parse(this.LuceneVersion, query, fieldList, occurs.ToArray(), this.Analyzer);
如果我尝试在 MultiFieldQueryParser 上添加带有任何数字的“~”,则会出错,表示对于 FuzzySearch,值应该在 0.0 和 1.0 之间,但我想要a 邻近搜索 3 个分隔词“我的搜索”~3
I want to make a Proximity Search with Lucene.Net. I saw this question where it looks like that was the answer for him, but no code was suplied. The Java documentation says to use the ~ character with the number of words in between, but I don't see where this character would go in the code. Anyone can give me an example of a Proximity Search using Lucene.Net?
Edit:
What I have so far:
IndexSearcher searcher = new IndexSearcher(this.Directory, true);
string[] fieldList = new string[] { "Name", "Description" };
List<BooleanClause.Occur> occurs = new List<BooleanClause.Occur>();
foreach (string field in fieldList)
{
occurs.Add(BooleanClause.Occur.SHOULD);
}
Query searchQuery = MultiFieldQueryParser.Parse(this.LuceneVersion, query, fieldList, occurs.ToArray(), this.Analyzer);
If I try to add the "~" with any number on the MultiFieldQueryParser it errors out saying that for a FuzzySearch the values should be between 0.0 and 1.0, but I want a Proximity Search 3 words of separation Ex. "my search"~3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
波形符表示模糊搜索(如果您将其应用于单个术语),或者表示邻近搜索(如果您将其应用于 短语。您收到的错误听起来像是您将其应用于单个术语(term~10)而不是使用短语(“term term”~10)。
The tilde means either a fuzzy search if you apply it on a single term, or a proximity search if you apply it on a phrase. The error you're receiving sounds like you're applying it on a single term (term~10) instead of using a phrase ("term term"~10).
Lucene.NET 和同一版本的经典 java lucene 之间的唯一区别应该是内部的,而不是外部的——操作目标是拥有一个非常兼容的项目,特别是在输入(查询)和输出(索引文件)方面。所以它应该可以工作,但是它适用于 java lucene。如果没有,那就是一个错误。
The only differences between Lucene.NET and classic java lucene of the same version should be internal, not external -- operational goal is to have a very compatible project, especially on the input (queries) and output (index files) side. So it should work however it works for java lucene. If it don't, it is a bug.