More in this section
Forums / Developing with Sitefinity / Filtering searchresults by categories

Filtering searchresults by categories

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
4 posts, 0 answered
  1. Jurgen
    Jurgen avatar
    11 posts
    11 Oct 2011
    08 Jul 2015
    Link to this post

    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();


  2. Velizar Bishurov
    Velizar Bishurov avatar
    143 posts
    18 Sep 2017
    12 Jul 2015
    Link to this post
    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
  3. OMAR
    OMAR avatar
    3 posts
    10 May 2016
    04 Aug 2016
    Link to this post

    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. 


  4. Rohit
    Rohit avatar
    0 posts
    25 Oct 2016
    08 Nov 2016
    Link to this post


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


4 posts, 0 answered