Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user

Querying Sitecore Solr datetimeCollectiondatetime Collection

I have a Sitecore 9 instance using solrSolr. 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 solrSolr 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

Querying Sitecore Solr datetimeCollection

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

Querying Solr datetime Collection

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

Source Link

Querying Sitecore Solr datetimeCollection

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