Filtering searchresults by categories

Posted by Community Admin on 04-Aug-2018 07:54

Filtering searchresults by categories

All Replies

Posted by Community Admin on 08-Jul-2015 00:00

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

 

Posted by Community Admin on 12-Jul-2015 00:00

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.

Regards,
Velizar Bishurov
Telerik

 
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
 

Posted by Community Admin on 04-Aug-2016 00:00

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. 

 

Posted by Community Admin on 08-Nov-2016 00:00

Hi,

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

Thanks

This thread is closed