2017-05-31 89 views
2

我试图返回一个使用iQuery查询的课程列表,但我有一些日期比较的问题。Sitecore日期比较不返回预期结果

IM目前使用的与将来的日期返回课程代码

query = query.Where(r => r.EndDate >= DateTime.UtcNow); 

,但是它不会返回在同一天,结束与比DateTime.UtcNow返回的时间后结束的时间课程。

任何想法我做错了什么?

我刚用卢克检查指标,如果我使用

end_date:[20170531t092205609z TO *] 

我回来,我需要确切的结果但在日志中的实际查询使用

+end_date:[20170531t092205609z TO *] +_template:a84b75fccac64eafa746f4b71e628adc - Filter : 

然后我得到更多的结果包括我失踪的课程。

为什么

a) i get more results back using the second query? 
b) Why is i that in my c# code the results returned do not match the search results? 
+0

你能在搜索日志文件检查什么是查询被发送到索引? –

+0

@MarekMusielak这是发送28688 10:22:05信息ExecuteQueryAgainstLucene(website_web_event_search_index):+ end_date:[20170531t092205609z TO *] + _template:a84b75fccac64ea7474f4b71e628adc - Filter: –

回答

0

也有类似的问题,在这里描述了我们的解决方案:https://ggullentops.blogspot.be/2015/12/sitecore-lucene-index-and-datetime.html

我们的问题有2个原因:

  • 第一个原因是,Sitecore的存储其在UTC DateTime是否(这与我们当地的一个小时的时间差)
  • 第二个原因是,Sitecore的使用“T”在日期中以小写形式在查询中。但在我的索引中,它们都是大写字母。如果我使用Luke尝试查询,它的确会给我错误的结果..当我在Luke中更改查询以使用大写字母T时,它的工作正确..

我们找到的最简单的解决方案是指标配置:

<field fieldName="datefrom" storageType="YES" indexType="UNTOKENIZED" vectorType="NO" boost="1f" 
format="yyyyMMdd" type="System.DateTime" 
settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider"/> 

(注意格式=“...”)

+0

事情是我得到的结果,即使与小写字母t –