在Sitecore 7 Update-1中按日期时间搜索
我正在尝试使用Sitecore 7搜索API执行查询。该查询包含许多DateTime where子句。在下面的示例中,EffectiveFrom和EffectiveTo是日期时间属性在Sitecore 7 Update-1中按日期时间搜索,sitecore,lucene.net,sitecore7,Sitecore,Lucene.net,Sitecore7,我正在尝试使用Sitecore 7搜索API执行查询。该查询包含许多DateTime where子句。在下面的示例中,EffectiveFrom和EffectiveTo是日期时间属性 var index = ContentSearchManager.GetIndex("sitecore_web_index"); using (var context = index.CreateSearchContext()) { var schedules = context.GetQueryable&
var index = ContentSearchManager.GetIndex("sitecore_web_index");
using (var context = index.CreateSearchContext())
{
var schedules = context.GetQueryable<ScheduleSearchResultItem>()
.Where(item => item.EffectiveFrom <= DateTime.Now)
.Where(item => item.EffectiveTo >= DateTime.Now);
foreach (var schedule in schedules)
{
//...
}
}
这是Sitecore 7的初始版本,但是,它现在抛出一个“字符串未被识别为有效的日期时间。”Sitecore 7 Update-1中的错误
我已经尝试了几十种索引配置,并在我的ScheduleSearchResultItem
上添加和删除了IndexFieldDateTimeValueConverter
属性。我已通过Luke确认,这些项目确实包含yyyyMMdd格式的日期。也就是说,并非所有项目都具有effectivefrom和effectiveto字段
还有其他人经历过同样的行为吗?这是一个局部问题。升级过程中,
Sitecore.ContentSearch.Solr.Indexes.config文件不知何故进入了我的Includes文件夹。我没有使用Solr,删除此文件修复了此问题。这也发生在我身上。问题在于Sitecore升级说明中没有很好地定义它。如果您没有全神贯注,那么将添加Sitecore.ContentSearch.Solr.Indexes.config文件以及其他更新的配置文件。谢谢
/// <summary>
/// Search result item for event schedules
/// </summary>
public class ScheduleSearchResultItem : SearchResultItem
{
/// <summary>
/// EffectiveFrom field
/// </summary>
[TypeConverter(typeof(IndexFieldDateTimeValueConverter))]
[IndexField("effectivefrom")]
public DateTime EffectiveFrom { get; set; }
/// <summary>
/// EffectiveTo field
/// </summary>
[TypeConverter(typeof(IndexFieldDateTimeValueConverter))]
[IndexField("effectiveto")]
public DateTime EffectiveTo { get; set; }
// ...
}