Overriding ResultFacetList

2013-04-22

This article describes a breaking change in the .Net Module between earlier versions of 4.2.74.1 and versions 4.2.74.1 and later.

It is only applicable if:

  1. You are trying to upgrade a version prior to 4.2.74.1 to 4.2.74.1 or later, AND
  2. You have overridden the method ResultFacetList

If you haven't overridden the method ResultFacetList, you may safely ignore this article.

Why is this a breaking change?

  1. Prior to 4.2.74.1, the method ResultFacetList(SearchResult result, params string[] facetKeys) called ResultFacetList(SearchResult result), and ResultFacetList(SearchResult result) implemented the html.
  2. This changed in order to fix a bug.
  3. From version 4.2.74.1, the order was changed, meaning that ResultFacetList(SearchResult result) now calls ResultFacetList(SearchResult result, params string[] facetKeys), and ResultFacetList(SearchResult result, params string[] facetKeys) implements the actual html.
  4. If your overriding code still depends on the implementation prior to 4.2.74.1 and performs the calls as described in point 1, then when you upgrade to 4.2.74.1 or later, you will most likely get a stack overflow. This is caused by an infinite execution path.

Make sure that you override the ResultFacetList(SearchResult result, params string[] facetKeys) method if you want to change the html, and that it does not call ResultFacetList(SearchResult result).

The new implementations of these methods look as follows:

        /// <summary>
        /// Generates html for the result list showing the facets, higlighting the selected facets
        /// </summary>
        /// <param name="result">the search response</param>
        /// <returns>html string</returns>
        public virtual string ResultFacetList(SearchResult result)
        {
            return ResultFacetList(result, result.Facets.Select(x => x.Key).ToArray());
        }

        ///<summary>
        /// Generates html for the facets which match the given facetKeys
        ///</summary>
        ///<param name="result">The search result</param>
        ///<param name="facetKeys">The Facet key</param>
        ///<returns>the html for the facets</returns>
        public virtual string ResultFacetList(SearchResult result, params string[] facetKeys)
        {
            if (result == null || result.Facets == null || !result.Facets.Any() || facetKeys == null || !facetKeys.Any()) return string.Empty;
            if (result.IsNull) return string.Empty;
            List<Facet> filteredFacets = facetKeys.Select(facetKey => result.Facets.FirstOrDefault(f => f.Key.Equals(facetKey))).Where(foundFacet => foundFacet != null).ToList();

            if (!DoRenderResultFacetList(result))
                return string.Empty;
            var aside = this.GetTagByName("aside");
            aside.AddCssClass("ess-facets");
            var h2 = this.GetHeadingByLevel(2);
            h2.AddCssClass("ess-facetsListHeader");
            h2.SetInnerText("Facetter");
            aside.InnerHtml += h2.ToString();
            filteredFacets.ForEach(facet => aside.InnerHtml += ResultFacetList_Facet(facet, result.Name));
            
            return aside.ToString();
        }