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 30, 2022 @ 17:28
    Peter van den Dungen
    0

    Examine contains filter

    Hello,

    I am working on filters to get products based on custom properties, but I got stuck on the size filter.

    In VendrComponents class I added a new definition.

    index.FieldDefinitionCollection.TryAdd(new FieldDefinition("sizes", FieldDefinitionTypes.FullText));
    

    And here this definition is set. The product node has children of type 'ProductVariant', this type has a property 'Size'.

     var sizes = product.Children.OfType<ProductVariant>().Select(x => x.Size.ToLower()).ToArray();
     e.ValueSet.Set("sizes", sizes);
    

    In the ProductSurfaceController I do this, but this is not working.

     if (!string.IsNullOrEmpty(filter.Size))
     {
        //query = query.And().Field("sizes", filter.Size);
        query = query.And().GroupedOr(new string[] { "sizes" }, new string[] { filter.Size });
     }
    

    It seems simple, but clearly need some help on this. 😎

  • Peter van den Dungen 66 posts 365 karma points
    Apr 30, 2022 @ 17:38
    Peter van den Dungen
    101

    Got it working already.

    I had to save my sizes collection as a comma seperated list.

    var sizes = product.Children.OfType<ProductVariant>().Select(x => x.Size.ToLower());
    e.ValueSet.Set("sizes", string.Join(",", sizes));
    

    The filtering.

    query = query.And().GroupedOr(new string[] { "sizes" }, filter.Size.Split(','));
    
  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 02, 2022 @ 12:16
    Matt Brailsford
    0

    Nice work on getting it working 👍

Please Sign in or register to post replies

Write your reply to:

Draft