Unified search with categories

Vote:
 

Hi

 

I'm trying to use unified search to filter the results based on category. I've got so far

var results = SearchClient.Instance.UnifiedSearchFor(searchDefinition.SearchTerm, Language.English)
                                                                    .Filter(x => x.MatchTypeHierarchy(typeof(ContentPageBase)))
                                                                    .Filter(y => y.SearchCategories.Match("5"))
                                                                    .Skip(searchDefinition.Page - 1)
                                                                    .Take(pageSize);

And the SeachCategories method is implemented on ContentBasePage as

        [Ignore]
        public virtual IEnumerable<string> SearchCategories 
        { 
            get 
            {
                return this.Category.Select(x => x.ToString());
            } 
        }

    

Bu tfind doesn't return any results even though I know that there is a page in category "5" (filter hardcoded for demo purposes). Can anyone spot what is going on. Also - I would like to peek into Searchcategories in the search results (in VS debug mode) to see what is there - but the property seems to be unavailable.


Really appreciate any help

Thanks

   

 

 

 

#85904
May 08, 2014 11:45
Vote:
 

Think you need to change the:

.Filter(y => y.SearchCategories.Match("5"))

As the SearchCategories are a list over categories you can't use match.

In my solution I created my own filter and then added that to the query.

 var catalogBuilder = SearchClient.Instance.BuildFilter<PageData>();

                foreach (int category in input.Categories)
                    catalogBuilder = catalogBuilder.Or(x => x.Category.Match(category));

                query = query.Filter(catalogBuilder)

   

 

 

#85905
May 08, 2014 11:57
Vote:
 

Thanks Petter.

But it turns out that SearchCategories has the category name not the id. Sooo

y.SearchCategories.Match("CategoryName"))

Works.

I found this out by looking in the find index in the admin view of the CMS (click the find tab)

Cheers 

 

 

#85926
May 08, 2014 17:19
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.