错误的 Nhibernate.Search 查询结果

发布于 2024-11-04 05:47:03 字数 587 浏览 0 评论 0原文

我使用下面的代码通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水中月 2024-11-11 05:47:03

好的,所以我找到了解决方案。

我已使用 WhiteSpaceAnalyzer 对所有字段建立了索引。看来NHibernate.Search默认使用StandardAnalyzer,不管事实如何,我已将全局AnalyzerClass设置为WhiteSpaceAnalyzer。解析查询后,它看起来像这样:

"+Search:name~0.7 +Moderated:true -PlaceType:wrongtype"

这不起作用,因为 PlaceType 字段中的值不是小写的。

将问题中的代码更改为类似的内容:

var fts = NHibernate.Search.Search.CreateFullTextSession(this._session);

var queryParser = new QueryParser("text", new WhitespaceAnalyzer());
var luceneQuery = "Search:name~0.7 AND Moderated:true NOT PlaceType:WrongType";
var query = queryParser.Parse(luceneQuery);

var places = fts.CreateFullTextQuery(query, typeof(Place))
            .List<Place>();

解决了情况。

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:

"+Search:name~0.7 +Moderated:true -PlaceType:wrongtype"

which didn't work, because values in PlaceType field were not lowercased.

Changing the code in the question to something like that:

var fts = NHibernate.Search.Search.CreateFullTextSession(this._session);

var queryParser = new QueryParser("text", new WhitespaceAnalyzer());
var luceneQuery = "Search:name~0.7 AND Moderated:true NOT PlaceType:WrongType";
var query = queryParser.Parse(luceneQuery);

var places = fts.CreateFullTextQuery(query, typeof(Place))
            .List<Place>();

solved the situation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文