Exemplo n.º 1
0
        public IEnumerable<SolrFacet> GetFacets(XElement facetType)
        {
            var facets = facetType.Elements("lst");

            foreach (var facet in facets)
            {
                var solrFacet = new SolrFacet() { Response = this };
                var name = facet.Attribute("name").Value;
                var values = facet
                    .Elements()
                    .Select(x => new SolrFacetValue() {
                        Name = x.Attribute("name").Value, Count=x.Value, Facet = solrFacet
                    });

                solrFacet.Name = name;
                solrFacet.Values = values;

                yield return solrFacet;
            }
        }
Exemplo n.º 2
0
        public IEnumerable<SolrFacet> GetQueryFacets(XElement facetType)
        {
            Dictionary<string, List<KeyValuePair<String, String>>> facets = new Dictionary<string, List<KeyValuePair<string,string>>>();

            var elements = facetType.Elements();

            foreach (var element in elements)
            {
                var nameValue = element
                    .Attribute("name")
                    .Value
                    .Split(':');

                var name = nameValue[0];
                var value = nameValue[1];
                var xpath = string.Format("//facet[@name='{0}']/facetQueries/facetQuery[@query='{1}']", name, value);
                value = configuration.XPathSelectElement(xpath).Attribute("en-GB").Value;

                if (facets.ContainsKey(name))
                {
                    facets[name].Add(new KeyValuePair<String,String>(value, element.Value));
                }
                else
                {
                    facets.Add(name, new List<KeyValuePair<String,String>>());
                    facets[name].Add(new KeyValuePair<String,String>(value, element.Value));
                }
            }

            foreach (var key in facets.Keys)
            {
                var facet = new SolrFacet() { Response = this };
                var values = facets[key].Select(x => new SolrFacetValue() { Name = x.Key, Count = x.Value, Facet = facet });
                facet.Name = key;
                facet.Values = values;

                yield return facet;
            }
        }