1

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?

4

1 回答 1

3

事实证明这是一个本地化问题。在升级过程中,该Sitecore.ContentSearch.Solr.Indexes.config文件以某种方式进入了我的 Includes 文件夹。我没有使用 Solr,删除这个文件解决了这个问题。

于 2013-08-20T00:50:54.503 回答