错误的 Nhibernate.Search 查询结果
我使用下面的代码通过 nhibernate.search 查询 lucene 索引:
var fts = NHibernate.Search.Search.CreateFullTextSession(this._session);
var luceneQuery = "Search:name~0.7 AND Moderated:true NOT PlaceType:WrongType";
var places = fts.CreateFullTextQuery<Place>(luceneQuery)
.List<Place>();
问题是查询返回所有类型的地点,包括 WrongType。当我尝试对 Luke 中的相同索引运行相同的查询时,一切正常,不会返回 WrongType 类型的位置。
搜索字段是 Place 对象中许多字段的串联。我正在使用 Modeated 和 PlaceType 字段来过滤掉一些记录,正如我发现的那样,这样可以保留 Lucene 查询中的原始排序顺序(按分数)。
如何使用 NHibernate.Search 从结果中排除 PlaceType(按 PlaceType)?
I am querying lucene index via nhibernate.search using code below:
var fts = NHibernate.Search.Search.CreateFullTextSession(this._session);
var luceneQuery = "Search:name~0.7 AND Moderated:true NOT PlaceType:WrongType";
var places = fts.CreateFullTextQuery<Place>(luceneQuery)
.List<Place>();
The problem is that query returns all types of Places, including WrongType. When I try to run the same query against the same index in Luke everything is ok, Places of type WrongType are not returned.
Search field is concatenation of many fields in Place object. I am using Moderated and PlaceType fields to filter out some records, as I have discovered, that in this way original sorting order (by score) from Lucene query is preserved.
How can I exclude Places by PlaceType from results using NHibernate.Search?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,所以我找到了解决方案。
我已使用 WhiteSpaceAnalyzer 对所有字段建立了索引。看来NHibernate.Search默认使用StandardAnalyzer,不管事实如何,我已将全局AnalyzerClass设置为WhiteSpaceAnalyzer。解析查询后,它看起来像这样:
这不起作用,因为 PlaceType 字段中的值不是小写的。
将问题中的代码更改为类似的内容:
解决了情况。
Ok, so I have found solution.
I have indexed all fields using WhiteSpaceAnalyzer. It seems that NHibernate.Search is using StandardAnalyzer by default, regardless from the fact, that I have set global AnalyzerClass to WhiteSpaceAnalyzer. After parsing the query it looked like that:
which didn't work, because values in PlaceType field were not lowercased.
Changing the code in the question to something like that:
solved the situation.