Umbraco 10
I am trying to use a RangeQuery
with DateTime
range eg.
searchQuery = searcher
.CreateQuery(searcherSettings.IndexingType)
.NativeQuery($"+__IndexType:{IndexTypes.Content} +__NodeTypeAlias:{searcherSettings.ContentTypeToSearch.GetDescription()} ");
and then date range option:
if (searcherSettings.DateRangeProperties != null && searcherSettings.DateRangeProperties.Any())
{
foreach (var item in searcherSettings.DateRangeProperties)
{
searchQuery = searchQuery.And().RangeQuery<DateTime>(
new[] { item.PropertyName },
item.StartDate,
item.EndDate,
minInclusive: true,
maxInclusive: true);
}
}
The query ultimately resolves to:
Category: “content”, LuceneQuery: {+(+__IndexType:content
+__NodeTypeAlias:booking) +(startDate:[637397856000000000 TO 638092512000000000])}
Despite there are plenty of records between those dates (2 years) - it is not returning any results.
If I remove the date range condition - it returns all results as expected.
I am using a NativeQuery
above but without it also has the same effect:
searchQuery = searcher.CreateQuery(searcherSettings.IndexingType)
.Field("__NodeTypeAlias", searcherSettings.ContentTypeToSearch.GetDescription());
If I try to use a raw query like this:
searchQuery = searcher
.CreateQuery()
.NativeQuery($"+__IndexType:{IndexTypes.Content} +__NodeTypeAlias:{searcherSettings.ContentTypeToSearch.GetDescription()} {searcherSettings.RawQuery} -umbracoNaviHide:1 ");
where searcherSettings.RawQuery
is a string:
"+(startDate:[637397856000000000 TO 638092512000000000])"
the searchQuery
resolves to
Category: null, LuceneQuery: {+(+__IndexType:content +__NodeTypeAlias:booking +startDate:[* TO *] -umbracoNaviHide:1)}
What is going on here?
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/110864-examine-searchs-rangequerydatetime-not-returning-any-results