Filtering searchresults by categories - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Filtering searchresults by categories

  • Filtering searchresults by categories
  • Hi all,

     I have extended the sitefinity search engine to filter search results by Categories. I found a blog by sitefinity which described how to do this but it's very outdated (2012). 

    The documentation for building a search query does not really exist but I managed to implement it anyway, I thought it could be helpfull to share this information.

     The setup is basically the same as in the blog, only the code for building the query changes:

    public static IEnumerable<IDocument> Search(string term, IEnumerable<string> categories, int take, int skip, out int hitcount)
                var searchFields = new List<string> "Title", "Subtitle", "Summary", "Description", "Categories" ;
                var searchService = Telerik.Sitefinity.Services.ServiceBus.ResolveService<ISearchService>();
                var queryBuilder = ObjectFactory.Resolve<IQueryBuilder>();
                var query = queryBuilder.BuildQuery(term, searchFields);
                query.IndexName = "search-index";
                query.Skip = skip;
                query.Take = take;
                query.OrderBy = null;
                if (categories != null && categories.Any())
                    var CategoryGroup = new SearchQueryGroup
                        Terms = categories.Select(c => new SearchTerm Field = "Categories", Value = c ),
                        Operator = QueryOperator.Or,
                    var SearchGroup = query.SearchGroup;
                    query.SearchGroup = new SearchQueryGroup
                        Groups = new[] SearchGroup, CategoryGroup,
                        Operator = QueryOperator.And
                var result = searchService.Search(query);
                hitcount = result.HitCount;
                return result.SetContentLinks();


  • Hello Jurgen,

    Thank you for sharing the info with the community. We will look at modifying the blog post to indicate that it is only applicable to earlier versions.

    Velizar Bishurov
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
  • I know this is an old post but I would appreciate any sort of feedback here. I managed to successfully compile and install the above custom search widget into my sitefinity website. I am running Sitefinity 8.0 for what its worth. However, it seems the search is not filtering by category because when I search a term, its returning all the files with the term in it regardless of whether they are in the specified category or not. Any insight?

    I'm using the code exactly as above. I made sure to create a search index, to categorize my files, and to reindex. 


  • Hi,

    How do I fix the assembly references which was explained in the blog?