Copied to clipboard

Flag this post as spam?

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


  • Remko 70 posts 189 karma points
    Jul 16, 2019 @ 08:57
    Remko
    0

    Using RangeQuery on custom (string) fields (Umbraco 8)

    We used to add some rewritten values to the Examine Index to query it with Examine.

    For example a datetime picker with name "date" we used to save to index as "dateRewritten" with the correct format to order it and query with ranges like this: And().Range("dateRewritten", dateFrom, dateTo)

    Now in Umbraco 8 we managed to get the dateRewritten correctly in the index, with _TransformingIndexValues event.

    But when we now try to query on this field, and use .RangeQuery, we need to pass non nullable type, like long (we save ticks), but then an exception pops up: : 'Could not perform a range query on the field dateRewritten, it's value type is Examine.LuceneEngine.Indexing.FullTextType'

    Is there any way to do a RangeQuery on string field, like it was possible in U7?

  • Nik 1091 posts 4547 karma points MVP 2x c-trib
    Jul 16, 2019 @ 09:37
    Nik
    0

    Hey Remko,

    How are you manipulating your "dateRewritten" field?

    You will need to change it's type to a long in the index so you can do the range, this is the same as what was happening in v7 as you can't do range on text.

    Thanks

    Nik

  • Nik 1091 posts 4547 karma points MVP 2x c-trib
    Jul 16, 2019 @ 09:40
    Nik
    100

    Assuming you are using the External Index you can do the following:

    var externalIndex = examineManager.Indexes.FirstOrDefault(i=>i.Name == "ExternalIndex");
    if(externalIndex != null)
    {
          externalIndex.FieldDefinitionCollection.AddOrUpdate(new FiledDefinition("dateRewritten", FieldDefinitionTypes.Long));
    }
    

    This can then be used to perform a ranged query against once you've populated it with the ticks value for the given date.

    Nik

  • Remko 70 posts 189 karma points
    Jul 17, 2019 @ 13:11
    Remko
    1

    This was where I was looking for, thank you!

Please Sign in or register to post replies

Write your reply to:

Draft