We've solr configured for our 8.2 solution. Recently, a new computed field has been added to the schema. This field is a datetimecollection field which has list of datetimes.
Here is the code for it. We rebuilt the index after adding the new custom field. But then querying on the datetime field using search API isn't working as expected. The data is getting stored in solr indexes as multivalued array of dates. But then when querying the field in Sitecore,the value of this field is always the MinTime (1/1/0001 12 AM). Any clue as to why it's failing.
<contentSearch>
<indexConfigurations>
<defaultSolrIndexConfiguration>
<fields hint="raw:AddComputedIndexField">
<field fieldName="scheduledpublish" returnType="datetimeCollection">classname, assembly</field>
</fields>
</defaultSolrIndexConfiguration>
</indexConfigurations>
</contentSearch>
[IndexField("scheduledpublish")]
[IgnoreIndexFieldAttribute]
public DateTime ScheduledPublishDateTime { get; set; }
public override object ComputeFieldValue(IIndexable indexable)
{
Sitecore.Data.Items.Item item = indexable as SitecoreIndexableItem;
if (item == null)
return null;
var dateList = new List<DateTime>();
if (item.Publishing.PublishDate != DateTimeOffset.MinValue.UtcDateTime)
dateList.Add(item.Publishing.PublishDate);
if (item.Publishing.UnpublishDate != DateTimeOffset.MaxValue.UtcDateTime)
dateList.Add(item.Publishing.UnpublishDate);
if (item.Publishing.ValidFrom != DateTimeOffset.MinValue.UtcDateTime)
dateList.Add(item.Publishing.ValidFrom);
if (item.Publishing.ValidTo != DateTimeOffset.MaxValue.UtcDateTime)
dateList.Add(item.Publishing.ValidTo);
return dateList.Count == 0 ? null : dateList;
}
var queryResult = searchContxt.GetQueryable<PublishItem>()
.Filter(f => f.LatestVersion &&
f.ScheduledPublishDateTime.Between(publishSpanFrom, publishSpanUntil, Inclusion.Upper))
.OrderBy(f => f.FullPath)
.Skip(skip)
.Take(500)
.GetResults();