Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ewuski 99 posts 286 karma points
    Jan 10, 2023 @ 22:15
    ewuski
    0

    Examine search's RangeQuery<DateTime> not returning any results

    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?

  • Thomas 319 posts 606 karma points c-trib
    Jul 19, 2023 @ 11:18
    Thomas
    0

    Do you find a solution ?

  • ewuski 99 posts 286 karma points
    Aug 11, 2023 @ 15:44
    ewuski
    0

    I have created custom index where I index dates are need and it is working. I didn't make it working with default index

Please Sign in or register to post replies

Write your reply to:

Draft