EPi find get all variants if search hit on product

183 views Asked by At

A EPi find question coming up, We have WebProducts and WebVariants and when showing a simple product listing on the category page I'm showing the following result correctly

  • If a WebProduct doesn't have any variants - show the WebProduct on the result

  • If a WebProduct has variants - show the WebVariants and hide the WebProduct

But when I'm trying to use the same functionality for the site-search it gets complicated. The WebProduct has a property named Brand while the WebVariants doesn't have that property. So when I search for "My brand" and I get a hit on a WebProduct that has WebVariants, it won't show the WebProduct because point 2 is true in that case.

I on the other hand don't want to show the product, but I want to get the variants for that product... It might sound confusing :grimacing:

I'll add a code snippet of the code that makes point 1 and 2 to work.

                .SearchAndFilterFor(q)
                .Filter(x =>
                    (x.MatchType(typeof(WebVariant))) |
                    (x.MatchType(typeof(WebProduct)) & ((WebProduct)x).HasVariants().Match(false)))```

1

There are 1 answers

0
James Johnson On BEST ANSWER

I would say that you have a couple of options to choose from.

Either:

1: Change the way your variants are indexed so that they include some of the key info (in this case brand) that they currently lack and as such, appear in the search results.

OR

2: Just do the search for WebProduct and then loop through those results afterward to do the processing for ones that do/don't have variants.