Copied to clipboard

Flag this post as spam?

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


  • Simon Jansson 2 posts 22 karma points
    Apr 26, 2024 @ 14:18
    Simon Jansson
    0

    RangeQuery on DateField fails with exception saying it's a FullText field

    I have a Umbraco 13 project where we built a custom index for activities that we fetch from a remote API. I'm trying to do a RangeQuery on one of the fields that contains a date to see if the activity falls within the bounds of 2 different dates.

    This is how we set the FieldDefinitions.

    var definitions = new FieldDefinitionCollection(
    new FieldDefinition(nameof(IActivityIndexItem.FromDate), FieldDefinitionTypes.FullText),
    new FieldDefinition(nameof(IActivityIndexItem.ToDate), FieldDefinitionTypes.FullText),
    new FieldDefinition(nameof(IActivityIndexItem.FromDateAsDateTime), FieldDefinitionTypes.DateTime));
    
    foreach(var definition in definitions){
    options.FieldDefinitions.AddOrUpdate(definition);} 
    

    And if i go in the backoffice and search the index i can see that the date is stored correctly in the index. (FromDate is the same value but stored as FullText)

    enter image description here

    But when i try to do a RangeQuery on the field called "FromDateAsDateTime" like this:

    DateTime dateFromDate;
    if (DateTime.TryParseExact(dateFrom, "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None, out dateFromDate))
    {
         searchQuery = searchQuery
              .And()
              .RangeQuery<DateTime>([CustomIndexKeys.FromDateAsDateTime], dateFromDate, DateTime.MaxValue);
    }
    

    I get the following error: Message = "Could not perform a range query on the field FromDateAsDateTime, it's value type is Examine.Lucene.Indexing.FullTextType"

    I've been pulling my hair about this all week. Can anyone help me understand why this happens?

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Apr 29, 2024 @ 14:05
    Huw Reddick
    0

    I had issues trying to use dates so I changed my index to store ticks instead and then used that in the range query

    Field definition new("updated", FieldDefinitionTypes.Long), populating index ["updated"] = content.UpdateDate.Ticks,

    Range query

    .And().RangeQuery<long>(new string[] { "updated" }, min, max)
    
  • Simon Jansson 2 posts 22 karma points
    Apr 29, 2024 @ 17:46
    Simon Jansson
    0

    Hello Huw!

    Thanks for your suggestion, unfortunately i have already tried that and got the same error.

    The good thing is that i think i might have found the issue. We use a multisearcher to search in several indexes at the same time. And it seems like when using the multisearcher all fields in the indexes are treated as FullTextFields for some reason. Not sure if it is a bug or if that is the intended behaviour.

    If i get a searcher directly from my custom activity index, i can do a RangeQuery the way i want to. So i guess not using the multisearcher will have to be my solution for now :)

Please Sign in or register to post replies

Write your reply to:

Draft