Sitecore + Lucene使用和空字符串搜索FieldQuery [英] Sitecore + Lucene Search FieldQuery with and empty string

查看:200
本文介绍了Sitecore + Lucene使用和空字符串搜索FieldQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FieldQuery对象创建Sitecore.Ecommerce.Search.Query。然后我使用LuceneQueryBuilder类将Sitecore查询转换为Lucene.Net.Search.Query。除了我想要在空字符串上匹配的字段外,查询的所有内容都能正常工作。

I'm creating a Sitecore.Ecommerce.Search.Query using FieldQuery objects. I'm then converting the Sitecore query to a Lucene.Net.Search.Query using the LuceneQueryBuilder class. Everything with the query works fine except for fields where I am trying to match on a empty string.

所以...这样有效:

新的FieldQuery(FieldName,1,MatchVariant.NotEquals)

但是这个不会:

新的FieldQuery(FieldName,string.Empty,MatchVariant.NotEquals)

我已经反映了Sitecore.Ecommerce程序集和Lucene.Net程序集,但我没有发现任何明显的问题。但是,当我查看在Lucene查询中创建和使用的Term时,它看起来像这样:

I have reflected through both the Sitecore.Ecommerce assembly and the Lucene.Net assembly as well but I have not found any obvious issues. But, when I look at the Term that is created and used in the Lucene query, it looks like this:

-FieldName:

-FieldName:

我认为这是不正确的...但也许它是正确的我只是没有正确的字段索引设置...我不确定是诚实的。

which I believe is incorrect... but maybe it is correct and I just don't have the correct field indexes setup... I'm not sure to be honest.

非常感谢任何帮助。

谢谢!

推荐答案

Lucene并不真正支持搜索null / empty值。毕竟,没有任何索引可供查找。 Lucene使用倒排索引,它会进行某些类型的查询,包括纯粹的否定查询和搜索空值

Lucene does not really support searching for null/empty values. There is nothing indexed for it to find, after all. Lucene uses an inverted index, which makes certain kinds of queries, including pure negation queries and searching for nulls, difficult or even impossible.

如果你需要搜索某些字段为空的文档,你应该在字段中存储一个默认值(例如NULL) )你可以搜索。

If you need to search for documents in which certain fields are null, you should store a default value in the field (for instance "NULL") which you can search for.

那就是说,你可以创建

new RangeQuery(FieldName, null, null, true, true);

构造具有开放上限和下限的范围查询,因此它匹配任何具有值的查询。

Which constructs a range query with open upper and lower bounds, so it matches anything that has a value.

这不是一个很好的方法,但两者都没有只是否定的查询。

Not a good way to do it, but neither is querying with only a negation.

这篇关于Sitecore + Lucene使用和空字符串搜索FieldQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆