November Happy Hour will be moved to Thursday December 5th.

Search on the basis of category in unified Search ( Episerver Find )

Vote:
 

We are using Episerver Find search functionality for our blogs. I have a
page type (BlogItemPage) where we are displaying the category(using
EPiServer built-in category property) of the page.

I also want to search blogs on the basis of blog category. I am successfully
able to search it on basis of any query entered by the user.

In find index in the admin view of the CMS, the category are index and
stored in SearchCategories property. I have implemented the SearchCategories
method on BlogItemPage.cs class as

public virtual IEnumerable SearchCategories

{

get

{

return Category.Select(x => x.ToString());

}

}

and I am registering it in my Initialization module as

SearchClient.Instance.Conventions.ForInstancesOf().IncludeFiel
d(x => x.SearchCategories());

and on my controller (FindSearchPageController.cs)

var unifiedSearch =
SearchClient.Instance.UnifiedSearchFor(q).Skip(skipNumber).Take(pageSize).Fi
lter(x =>x.SearchCategories.Match(q));

model.Results = unifiedSearch.GetResult();

but the model.Results giving 0 hits for every category I search.

Also I want to provide both search option to user i.e. on the basis of any
search query enter by the user and if search query entered by user is
category name it should display that blog results.

Any suggestions on how can I achieve this.

#180814
Jul 27, 2017 10:28
Vote:
 

Something like this should work:

.Filter<BlogItemPage>(x => x.SearchCategories().Match(somecategory))

#180863
Jul 31, 2017 8:41
Vote:
 

Or actually, a better solution would be to just specify that you wish to search in the SearchCategories field:

.UnifiedSearch().For(q).UsingUnifiedWeights().InStandardFields().AndInField(x => x.SearchCategories)

You can remove your added convention and "SearchCategories" property that you added.

#180865
Jul 31, 2017 9:47
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.