Hi guys,
my problem:
i have a checkbox property on a catalogitem.
public class TippingProduct : BaseProductContent { [EnumMany(typeof(TippingFrontEndCylinderHeadboardType))] [Display(Order = 8, Name = "Headboard Type", GroupName = Logic.Constants.TabNames.Filters, Description = "Filter Headboard Type - Frontend Cylinder")] public virtual string HeadboardType { get; set; } }
the enum looks like this:
public enum TippingFrontEndCylinderHeadboardType { Slanted, Straight }
now i want to filter on headboardtype
public static dynamic TippingProducts(TippingSearchData tippingSearchData) { IClient client = SearchClient.Instance; //start of the query var query = client.Search<TippingProduct>() .FilterForVisitor() .Filter(x => x.ShowInList.Match(true)); //selected headboard type if (tippingSearchData.Headboard != null && tippingSearchData.Headboard.Any()) { query = query.Filter(x => GetHeadBoardFilter(tippingSearchData.Headboard)); } var res = query.GetContentResult(); return new { items = res.Count() }; }
private static FilterBuilder<TippingProduct> GetHeadBoardFilter(List<TippingFrontEndCylinderHeadboardType> headboards) { var filter = SearchClient.Instance.BuildFilter<TippingProduct>(); // return headboards.Aggregate(filter, (current, headboard) => current.Or(x => x.HeadboardType.Match(headboard.ToString()))); foreach (var headboard in headboards) { filter = filter.Or(tp => tp.HeadboardType.Split(',').Match(headboard.ToString())); } return filter; }
So the property HeadBoardType of my TippingProduct saves the data as comma seperated string.
When searching using epifind i sent a List<TippingFrontEndCylinderHeavyDuty> headboards and want a filter on all my TippingProduct pages where the HeadBoardType property contains one of the items from the list.
You can see in my filter builder i had a aggregate uncommented. So that works good if each TippingProduct only has 1 checkbox selected, because then its not a comma seperated string. But once 1 tipping product has 2 checkboxes selected then that one is not found. Which is logical because it will not match. But my second approach trying to split and then check doesnt work either. So i must be missing something trivial here.