3

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();
2
  • Are the dates in Solr correct when storing? Also, can you share the code on how you are querying the index Jun 5, 2018 at 1:16
  • @HishaamNamooya dates in solr are correct (in UTC). Querying in solr directly through admin interface is also fine. Have updated query above Jun 5, 2018 at 22:39

1 Answer 1

1

This seems to be an issue with Timezone. After changing my system timezone to UTC, its working as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.