3

I have a Sitecore 9 instance using Solr. I'm trying to query a collection of datetimes such that if any of the datetimes in that collection are within a range that item will be returned.

The issue that I'm having is that the Solr query appears to only compare the year and ignore the rest of the date, for example, a query for 2018-01-01 will return everything with a date in 2019 but nothing in 2018. (Example query at the bottom)

My Field Configuration :

<field fieldName="sessionstartdate" storageType="yes" 
returnType="datetimeCollection" indexType="untokenized">RSAC.Project.Rsac.Search.Fields.SessionStartDateField, RSAC.Project.Rsac</field>

My Queryable Item Definition :

[IndexField(RsacSearchConstants.SessionStartDateField)]
[IgnoreIndexField]
public DateTime SearchableStartDates { get; set; }

The Linq Query :

if (facetParameters.AfterDate.HasValue)
{
    var dateQuery = PredicateBuilder.True<ISessionItem>();
    dateQuery = dateQuery.And(x => x.SearchableStartDates.Between(facetParameters.AfterDate.Value, DateTime.Now.AddYears(3), Inclusion.Both));

    facetQuery = facetQuery.And(dateQuery);
}
...
query = query.Where(facetQuery);

The relevant part of the Solr Query Looks like this :

sessionstartdate_dtm:[2018-01-13T18:06:42.596Z TO 2021-07-13T18:06:42.624Z]

This is the field of one of the items I would expect to see returned by the above query:

"sessionstartdate_dtm":["2018-04-15T13:00:00Z","2018-04-16T13:00:00Z"]

I've tried running variations of the query with and without the timestamp, with and without the '-' and ':' characters and it seems as if solr is seeing the year then searching just on that

  • 1
    Please try after updating your field return type to "datetime"! – NSP Jul 16 '18 at 10:36
  • @NSP changing the return type to datetime also changes how it's stored in solr to only handle one date and not multiple. – Aaron F. Jul 25 '18 at 19:17
0

Do you have the *_dtm dynamic field type correctly configured in your Solr managed scema? This field type is missing in the configuration for a clean Sitecore 9/Solr setup. The Sitecore SchemaPopulateHelper class creates those mappings, but there are some erros in it, where one of them is the missing *_dtm mapping.

More details about this here: https://mikael.com/2018/01/working-with-content-search-and-solr-in-sitecore-9/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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