Copied to clipboard

Flag this post as spam?

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


  • Peter van den Dungen 66 posts 365 karma points
    Apr 04, 2022 @ 13:25
    Peter van den Dungen
    0

    Examine Price Range Filter

    I am working on a custom filter for filtering prices, but I got a bit stuck.

    query = query.And().RangeQuery<float>(new[] { "price" }, filter.MinPrice.Value, filter.MaxPrice.Value);
    

    Could not perform a range query on the field price, it's value type is Examine.LuceneEngine.Indexing.FullTextType

    Price is of type: Vendr.Umbraco.Models.PricePropertyValue

    What is the best solution here?

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Apr 04, 2022 @ 13:59
    Matt Brailsford
    100

    Hi Peter,

    The price property editor stores it's value in a JSON format like

    {
        "currencyId" : value,
        "currencyId" : value
        "currencyId" : value
    }
    

    Where for each currency your store supports there is an entry with the given price for that currency.

    To search on these, you'll probably need to extend how they are stored in examine, breaking out the values into individual lucene fields.

    See the docs here for how you would add your own fields to the examine / lucene index based on values already in the index https://our.umbraco.com/documentation/reference/searching/examine/examine-events

  • Peter van den Dungen 66 posts 365 karma points
    Apr 04, 2022 @ 17:41
    Peter van den Dungen
    1

    Hi Matt,

    Thanks for your quick reply, your advice was also my first tought on this.

    if (e.ValueSet.Values.ContainsKey("price")) {
      using
      var ctx = _umbracoContextFactory.EnsureUmbracoContext();
      int.TryParse(e.ValueSet.Id, out
        var nodeId);
      IPublishedContent content = ctx.UmbracoContext.Content.GetById(nodeId);
    
      if (content != null) {
        ProductPage product = (ProductPage) content;
        if (product != null) {
          e.ValueSet.Set("priceWithTax", product.Price.First().Value);
        }
      }
    

    Works great!

Please Sign in or register to post replies

Write your reply to:

Draft