SaaS CMS has officially launched! Learn more now.

TermsFacetFor using MetaField defined in Commerce Manager


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()
                        x =>
                    .TermsFacetFor(x => x.Property["BaseColour"].Value.ToString())

                var colourFacets =
                        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?

Nov 05, 2015 17:33

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:


Nov 05, 2015 20:55

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"]?



Nov 06, 2015 8:52

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.

Nov 06, 2015 12:12

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! :)



Nov 06, 2015 12:28

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

Nov 06, 2015 12:40

Hi David, the blog is now live :)



Nov 09, 2015 9:25


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.