Gravatar for chris.ruderschmidt@americaneagle.com

Question by Chris Ruderschmidt, Aug 13, 2015 3:56 PM

FacetOn/GetFacets not returning Facet Categories

Is there any documentation or examples on how to correctly use the FacetOn/GetFacets functions dynamically? Here is my current code, however when using “GetFacets()” no categories are returned.

 using (var context = ContentSearchManager.GetIndex(indexName).CreateSearchContext())
    {
          var q = context.GetQueryable<SearchResultItem>();
          oCurrentFilters = q.Where(w => w["Technology"] == collectionItem.Name).Take(1000);

           //PartsProperties is the list of applicable facets
          foreach(PartProperties property in oSearchByParameter.PartsProperties) 
          {
               oCurrentFilters.FacetOn(f=> f[property.PartPropertyName]);
          }

          Foo(oCurrentFilters.GetFacets());
    }
1 Reply
Gravatar for sbelzile@coveo.com

Answer by Sébastien Belzile, Aug 14, 2015 9:58 AM

I did not try your dynamic code, but here is an interesting article: http://getfishtank.ca/blog/building-dynamic-content-search-linq-queries-in-sitecore-7 that may help you.

In the section "Always Return Your Expression", it says that you should try:

oCurrentFilters = oCurrentFilters.FacetOn(f=> f[property.PartPropertyName]);

Does that make it work?

Gravatar for chris.ruderschmidt@americaneagle.com

Comment by Chris Ruderschmidt, Aug 14, 2015 5:15 PM

That was it! Thanks!

Ask a question