C# Sitecore 8和Solr中可枚举项的范围搜索
我需要在Sitecore 8中的个人资料卡上进行复杂的范围搜索。 我迄今为止取得的成就: 所有配置文件卡在Solr中都作为字符串列表进行索引,其中列表中的字符串是一个平面路径,如 “配置文件卡名称/配置文件名称/值” 这是我想到的最好的选择。当然,我希望将值存储为整数,但不知道如何使用配置文件卡这样的结构 例如,我可以在Solr中执行直接查询,返回我期望的结果C# Sitecore 8和Solr中可枚举项的范围搜索,c#,linq,solr,sitecore,C#,Linq,Solr,Sitecore,我需要在Sitecore 8中的个人资料卡上进行复杂的范围搜索。 我迄今为止取得的成就: 所有配置文件卡在Solr中都作为字符串列表进行索引,其中列表中的字符串是一个平面路径,如 “配置文件卡名称/配置文件名称/值” 这是我想到的最好的选择。当然,我希望将值存储为整数,但不知道如何使用配置文件卡这样的结构 例如,我可以在Solr中执行直接查询,返回我期望的结果 q=profilecard_sm:["Card1/Influence/2" TO "Card1/Influence/5"]&ro
q=profilecard_sm:["Card1/Influence/2" TO "Card1/Influence/5"]&rows=10
但我不知道如何通过Sitecore中的LINQ实现这一点
Upd:
已尝试此代码:
var results = context.GetQueryable<SearchResultItemWithProfileCard>()
.Where(i => i["profilecard_sm"].CompareTo("Card1/Influence/5") <= 0)
&& i["profilecard_sm"].CompareTo("Card1/Influence/1") >= 0))
;
这绝对不是我想要的
但它正在被序列化为
(profilecard_sm:[* TO "Card1/Influence/5"] AND profilecard_sm:["Card1/Influence/1" TO *])
(档案卡短信:[*至“Card1/Influence/5”]和档案卡短信:[“Card1/Influence/1”至*)
我也遇到过同样的问题(尽管与Lucene和int
field有关),您可以阅读
我认为您只需要使用扩展方法Sitecore.ContentSearch.Linq.MethodExtensions.Between(这个T值,T from,T to,Inclusion Inclusion)
fromSitecore.ContentSearch.Linq.dll
大概是这样的:
使用Sitecore.ContentSearch.Linq;
var results=context.GetQueryable()
其中(i=>i[“profilecard_sm”]。介于(“Card1/Influence/1”、“Card1/Influence/5”、Inclusion.two”)之间;
不过,字符串比较可能很棘手。考虑以下排序:
Card1/Influence/1
Card1/impact/10
Card1/impact/11
卡片1/影响/2
卡片1/影响/3
您的结果最终可能会像上面那样排序,但我不能100%确定Solr如何处理这个问题
但它正在被序列化为
(profilecard_sm:[* TO "Card1/Influence/5"] AND profilecard_sm:["Card1/Influence/1" TO *])
(档案卡短信:[*至“Card1/Influence/5”]和档案卡短信:[“Card1/Influence/1”至*)
我也遇到过同样的问题(尽管与Lucene和int
field有关),您可以阅读
我认为您只需要使用扩展方法Sitecore.ContentSearch.Linq.MethodExtensions.Between(这个T值,T from,T to,Inclusion Inclusion)
fromSitecore.ContentSearch.Linq.dll
大概是这样的:
使用Sitecore.ContentSearch.Linq;
var results=context.GetQueryable()
其中(i=>i[“profilecard_sm”]。介于(“Card1/Influence/1”、“Card1/Influence/5”、Inclusion.two”)之间;
不过,字符串比较可能很棘手。考虑以下排序:
Card1/Influence/1
Card1/impact/10
Card1/impact/11
卡片1/影响/2
卡片1/影响/3
您的结果可能会像上面那样进行排序,但我不能100%确定Solr如何处理此问题。谢谢!我仍在考虑如何使用严格的整数比较来进行字符串比较谢谢!我仍然在考虑如何在没有字符串比较的情况下使用严格的int比较