Sitecore LinqToSolr, Pivot Facets and Empty Value

I found a minor bug, but I don't have a privilege for create a bug ticket, so I leave it this. May be it will helpful for someone.

Well, you can reproduce it when use pivot facet with empty value in first field, then GetFacets doesn't return this facet correct.

Example:

facet.pivot=field1,field2

"field1,field2":[{
          "field":"field1",
          "value":"",
          "count":8,
          "pivot":[{
              "field":"field2",
              "value":"value1",
              "count":6},
            {
              "field":"field2",
              "value":"value2",
              "count":2}]}]}}}

It happens because of this code:

Sitecore.ContentSearch.SolrProvider.dll

Sitecore.ContentSearch.SolrProvider.SolrSearchResults<TElement>

 

public Dictionary<string, ICollection<KeyValuePair<string, int>>> GetFacets()
    {
      IDictionary<string, ICollection<KeyValuePair<string, int>>> facetFields = this.searchResults.FacetFields;
      IDictionary<string, IList<Pivot>> facetPivots = this.searchResults.FacetPivots;
      Dictionary<string, ICollection<KeyValuePair<string, int>>> dictionary = facetFields.ToDictionary<KeyValuePair<string, ICollection<KeyValuePair<string, int>>>, string, ICollection<KeyValuePair<string, int>>>((Func<KeyValuePair<string, ICollection<KeyValuePair<string, int>>>, string>) (x => x.Key), (Func<KeyValuePair<string, ICollection<KeyValuePair<string, int>>>, ICollection<KeyValuePair<string, int>>>) (x => x.Value));
      if (facetPivots.Count > 0)
      {
        foreach (KeyValuePair<string, IList<Pivot>> keyValuePair in (IEnumerable<KeyValuePair<string, IList<Pivot>>>) facetPivots)
          dictionary[keyValuePair.Key] = this.Flatten((IEnumerable<Pivot>) keyValuePair.Value, string.Empty);
      }
      return dictionary;
    }

private ICollection<KeyValuePair<string, int>> Flatten(IEnumerable<Pivot> pivots, string parentName)
    {
      HashSet<KeyValuePair<string, int>> keyValuePairSet = new HashSet<KeyValuePair<string, int>>();
      foreach (Pivot pivot in pivots)
      {
        if (parentName != string.Empty)
          keyValuePairSet.Add(new KeyValuePair<string, int>(parentName + "/" + pivot.Value, pivot.Count));
        if (pivot.HasChildPivots)
          keyValuePairSet.UnionWith((IEnumerable<KeyValuePair<string, int>>) this.Flatten((IEnumerable<Pivot>) pivot.ChildPivots, pivot.Value));
      }
      return (ICollection<KeyValuePair<string, int>>) keyValuePairSet;
    }