简体   繁体   English

错误的Nhibernate。搜索查询结果

[英]Wrong Nhibernate.Search query results

I am querying lucene index via nhibernate.search using code below:我正在使用以下代码通过 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>();

The problem is that query returns all types of Places, including WrongType.问题是查询返回所有类型的 Places,包括 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.当我尝试对 Luke 中的同一索引运行相同的查询时,一切正常,不会返回 WrongType 类型的位置。

Search field is concatenation of many fields in Place object.搜索字段是地方 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.正如我所发现的,我正在使用 Moderated 和 PlaceType 字段来过滤掉一些记录,这样就可以保留来自 Lucene 查询的原始排序顺序(按分数)。

How can I exclude Places by PlaceType from results using NHibernate.Search?如何使用 NHibernate.Search 从结果中按 PlaceType 排除 Places?

Ok, so I have found solution.好的,所以我找到了解决方案。

I have indexed all fields using WhiteSpaceAnalyzer.我已经使用 WhiteSpaceAnalyzer 索引了所有字段。 It seems that NHibernate.Search is using StandardAnalyzer by default, regardless from the fact, that I have set global AnalyzerClass to WhiteSpaceAnalyzer.似乎 NHibernate.Search 默认使用 StandardAnalyzer,不管我是否已将全局 AnalyzerClass 设置为 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.这不起作用,因为 PlaceType 字段中的值没有小写。

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.解决了这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM