I am attempting perform a query using the Sitecore 7 search API. The query contains a number of DateTime where clauses. In the example below, EffectiveFrom and EffectiveTo are DateTime properties.
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)
{
//...
}
}
ScheduleSearchResultItem
inherits from Sitecore.ContentSearch.SearchTypes.SearchResultItem
and looks like the following:
/// <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; }
// ...
}
This was working with the initial release of Sitecore 7, however, it now throws a "String was not recognized as a valid DateTime." error in Sitecore 7 Update-1.
I have tried dozens of index configurations, as well as adding and removing the IndexFieldDateTimeValueConverter
attribute on my ScheduleSearchResultItem
. I have confirmed via Luke that these items do contain dates in yyyyMMdd format. That said, not all of my items have effectivefrom and effectiveto fields.
Anyone else experiencing the same behavior?