private FacetModel ToCustomModel(FacetCategory category)
        {
            var facetDefinition = GetFacetDefinition(category);

            if (facetDefinition == null)
            {
                return(null);
            }

            return(new FacetModel
            {
                Enabled = true,
                FieldName = category.Name,
                ID = facetDefinition.ItemId.ToShortID().ToString(),
                SortOrder = facetDefinition.SortOrder,
                Title = !String.IsNullOrWhiteSpace(facetDefinition.Title) ? facetDefinition.Title : category.Name,
                ViewType = facetDefinition.FacetViewType,
                Values = category.Values.Where(q => q.AggregateCount > 0).Select(v => new FacetValueModel
                {
                    AgregateCount = v.AggregateCount,
                    Name = GetFacetName(facetDefinition, v.Name),
                    Value = v.Name
                }).Where(q => !String.IsNullOrWhiteSpace(q.Name)).OrderBy(v => v.Name).ToList()
            });
        }
 private bool IsFacetValueSelected(FacetCategory resultCategory, IQuery query, FacetValue resultValue)
 {
     if (query.Facets == null)
     {
         return(false);
     }
     return(query.Facets.Any(f => f.Key.Equals(resultCategory.Name, StringComparison.InvariantCultureIgnoreCase) && f.Value.Any(v => v.Equals(resultValue.Name, StringComparison.InvariantCultureIgnoreCase))));
 }
        protected void validateProperties()
        {
            // find all properties that have a PivotItem Attribute
            IEnumerable <PropertyInfo> properties = typeof(T).GetProperties().Where(p => p.GetCustomAttributes(false).Any(a => a.GetType() == typeof(PivotItemAttribute)));
            var facetCategoryList = new List <FacetCategory>();

            foreach (var property in properties)
            {
                var attr = property.GetCustomAttributes(typeof(PivotItemAttribute), false).FirstOrDefault() as PivotItemAttribute;
                if (attr != null)
                {
                    if (attr.IsFacet)
                    {
                        var facetCategory = new FacetCategory {
                            Name               = attr.FacetDisplayName,
                            Format             = attr.FacetFormat,
                            Type               = attr.FacetType,
                            IsFilterVisible    = attr.IsFilterVisible,
                            IsWordWheelVisible = attr.IsWordWheelVisible,
                            IsMetaDataVisible  = attr.IsMetaDataVisible,
                            PropertyName       = property.Name,
                            IsCollection       = attr.IsCollection,
                        };

                        facetCategoryList.Add(facetCategory);
                    }
                    else
                    {
                        if (attr.IsName)
                        {
                            nameProperty = property;
                        }
                        if (attr.IsHref)
                        {
                            hrefProperty = property;
                        }
                        if (attr.IsImage)
                        {
                            imageProperty = property;
                        }
                        if (attr.IsDescription)
                        {
                            descriptionProperty = property;
                        }
                    }
                }
            }
            if (nameProperty == null)
            {
                throw new Exception("Name is not optional. Please make one of the properties of this class as IsName=true on its PivotItem Attribute");
            }
            facetCategories = facetCategoryList.ToArray();
        }
 private IEnumerable <ISearchResultFacetValue> CreateFacetValues(FacetCategory resultCategory, IQuery query)
 {
     foreach (var resultValue in resultCategory.Values)
     {
         var facetValue = new SearchResultFacetValue
         {
             Value    = resultValue.Name,
             Count    = resultValue.AggregateCount,
             Selected = this.IsFacetValueSelected(resultCategory, query, resultValue),
             Title    = resultValue.Name
         };
         yield return(facetValue);
     }
 }
Exemple #5
0
        /// <summary>
        /// Updates the content search result with facets.
        /// </summary>
        /// <param name="facetResults">All possible facets.</param>
        /// <param name="facetResultsAfterSearch">Facets that contain results after querying using the search text. This is used to get the result count per facet.</param>
        /// <param name="searchResults">The collection of SearchResultItems after the search on searchtext and filtering on templates.</param>
        /// <param name="contentSearchResult">Result object which is updated with facets.</param>
        private void UpdateResultWithFacets(FacetResults facetResults, FacetResults facetResultsAfterSearch, SearchResults <SearchResultItem> searchResults, ContentSearchResult contentSearchResult)
        {
            var           allFacets    = facetResults.Categories.FirstOrDefault();
            FacetCategory searchFacets = null;

            if (facetResultsAfterSearch != null)
            {
                searchFacets = facetResultsAfterSearch.Categories.FirstOrDefault();
            }
            var searchResultFacets = searchResults.Facets.Categories.FirstOrDefault();

            if (allFacets != null && searchFacets != null)
            {
                contentSearchResult.Facets = allFacets.Values.Select(facet => GetFacet(facet, searchFacets, searchResultFacets)).OrderBy(facet => facet.Name).ToList();
            }
        }
        private FacetDefinition GetFacetDefinition(FacetCategory category)
        {
            if (category == null || SearchConfiguration.Facets == null)
            {
                return(null);
            }

            var facetDefinition = SearchConfiguration.Facets.FirstOrDefault(q => q.IndexFieldName.Equals(category.Name));

            if (facetDefinition == null)
            {
                Logging.Log.Warn("Can't find facet definition with name: " + category.Name);
            }

            return(facetDefinition);
        }
        private SearchResultFacet CreateFacet(IQuery query, FacetCategory resultCategory, IQueryFacet definition)
        {
            var facetValues = this.CreateFacetValues(resultCategory, query).ToArray();

            if (!facetValues.Any())
            {
                return(null);
            }
            var facet = new SearchResultFacet
            {
                Definition = definition,
                Values     = facetValues
            };

            this.FormatFacet(facet);

            return(facet);
        }
Exemple #8
0
        /// <summary>
        /// Gets the facet.
        /// </summary>
        /// <param name="facetValue">The name of the facet (Sitecore template ID).</param>
        /// <param name="searchFacetCategory">The FacetCategory after searching on the searchtext. This contains the resultcount per facet.</param>
        /// <param name="searchResultsCategory">The FacetCategory after filtering on template. This is used to determine which facets are selected.</param>
        /// <returns></returns>
        internal ContentSearchFacet GetFacet(FacetValue facetValue, FacetCategory searchFacetCategory, FacetCategory searchResultsCategory)
        {
            // A FacetValue doesn't contain a usable description of the facet, just the template ID (as a string).
            // A lookup will be done to get a usable desciption for the facet.

            var templateId             = facetValue.Name;
            var searchFacetValue       = searchFacetCategory.Values.FirstOrDefault(f => f.Name == facetValue.Name);
            var searchResultFacetValue = searchResultsCategory.Values.FirstOrDefault(f => f.Name == facetValue.Name);

            var facet = new ContentSearchFacet
            {
                ResultCount = searchFacetValue != null ? searchFacetValue.AggregateCount : 0,
                IsSelected  = searchResultFacetValue != null,
                TemplateId  = templateId,
                Name        = GetFacetName(templateId)
            };

            return(facet);
        }
Exemple #9
0
        public void BindFacetNavigation(FacetCategory facetCategories)
        {
            List <Tuple <FacetValue, Item, string> > items = new List <Tuple <FacetValue, Item, string> >();

            foreach (var value in facetCategories.Values.OrderByDescending(a => a.Name))
            {
                Item relatedItem = Sitecore.Context.Database.GetItem(new ID(Guid.Parse(value.Name)));

                if (relatedItem != null)
                {
                    items.Add(new Tuple <FacetValue, Item, string>(value, relatedItem,
                                                                   relatedItem.Fields["Title"] + " (" + value.AggregateCount + ")"));
                }
            }

            FacetRepeater.DataSource = items.OrderBy(a => a.Item3);

            FacetRepeater.DataBind();

            NoResultsPlaceholder.Visible = items.Count() == 0;
        }
        public void BindFacetNavigation(FacetCategory facetCategories)
        {
            List<Tuple<FacetValue, Item, string>> items = new List<Tuple<FacetValue, Item, string>>();

            foreach (var value in facetCategories.Values.OrderByDescending(a => a.Name))
            {
                Item relatedItem = Sitecore.Context.Database.GetItem(new ID(Guid.Parse(value.Name)));

                if (relatedItem != null)
                {
                    items.Add(new Tuple<FacetValue, Item, string>(value, relatedItem,
                        relatedItem.Fields["Title"] + " (" + value.AggregateCount + ")"));
                }
            }

            FacetRepeater.DataSource = items.OrderBy(a => a.Item3);

            FacetRepeater.DataBind();

            NoResultsPlaceholder.Visible = items.Count() == 0;
        }