Try our conversational search powered by Generative AI!

TermsFacetFor using MetaField defined in Commerce Manager

Vote:
 

I'm trying to create a dynamic faceting feature by using TermsFacetFor and a dynamic MetaField property.  My first thought was to do something like: 

var colourFacetsResults = SearchClient.Instance.Search()
                    .FilterHits(
                        x =>
                            x.ParentLink.ID.Match(productSearchData.ProductInputData.SelectedCategories.FirstOrDefault()))
                    .TermsFacetFor(x => x.Property["BaseColour"].Value.ToString())
                    .Take(0)
                    .GetResult();

                var colourFacets =
                    colourFacetsResults.TermsFacetFor(
                        x => x.GetPropertyValue(y => y.Property["BaseColour"].Value.ToString())).Terms;

However that doesn't return me any facets.  If i use a field defined in my BaseProduct class (eg. TermsFacetFor(x => x.BaseColour), it works, but this won't allow me to acheive what I'm trying to acheive.  Has anybody managed to get the idea above working??  If so, how?

#140990
Nov 05, 2015 17:33
Vote:
 

Hello Rob

An approach you can use is to use an extension method to push additional fields into your index that can then be faceted on. This has been discussed over in this thread:

http://world.episerver.com/forum/developer-forum/EPiServer-Search/Thread-Container/2015/9/epifind---how-to-index-additional-fields/

David

#140992
Nov 05, 2015 20:55
Vote:
 

HI David,

  Thanks for the reply, however we're trying to allow Editors to add new properties to a product using MetaFields and have them as facets, all without having to do a deployment, so we wouldn't be able to create an extension method to push those new fields in to the index.

Is there any other way of creating a facet based on product.Property["x"]?

Thanks

Rob

#140997
Nov 06, 2015 8:52
Vote:
 

I don't think it's possible yet, not in an easy way however. I will make sure the PM get's this information so we can create a way of doing facets against not strongly typed properties.

#141013
Nov 06, 2015 12:12
Vote:
 

Hi Jonas

  Thanks for the reply.  It would be good to be able to do this out of the box, however, I have found a way around this in our case.  I can create an extension method on our product class which loops through the metafields and adds them to a Dictionary object.  We then include that extension method in the index in our initialization module.  I also store a reference to the metafields we want to facet against in DDS, then, when building my facets, I can get those values from DDS and loop through, creating a facet for each, based on the values in the dictionary object.

It sounds much more complicated than it actually is, but I've managed to get it working.  I sense a blog post coming up! :)

Thanks

Rob

#141015
Nov 06, 2015 12:28
Vote:
 

Certainly sounds blog-worthy Rob - I'd be very interested in seeing that :)!

#141016
Nov 06, 2015 12:40
Vote:
 

Hi David, the blog is now live :) 

http://www.dev24seven.com/2015/11/09/faceting-on-metafields-in-episerver-commerce-with-episerver-find/

Thanks

Rob

#141054
Nov 09, 2015 9:25
Vote:
 

Thanks!

#141055
Nov 09, 2015 9:30
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.