volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

CategoryQuery example?

Hi!

I'm trying to use EPiServer Search and CategoryQuery to filter a search on categories without success.
Has anyone done that and could share an example?

Br

Erik Jonsson

#121508
May 12, 2015 15:18

In case someone else stumbles on this, because it's not documented anywhere, I managed to figure this out.

var mainQuery = new GroupQuery(LuceneOperator.AND);

var categoryQuery = new CategoryQuery(LuceneOperator.AND);

foreach (int categoryId in CurrentPage.Category)
{
  categoryQuery.Items.Add(categoryId.ToString());
}

mainQuery.QueryExpressions.Add(categoryQuery);

var result = SearchHandler.Instance.GetSearchResults(mainQuery, 1, 20);

Cheers
Fredrik

#138443
Sep 22, 2015 10:20

Thank you Fredrik!

/Erik

#138447
Sep 22, 2015 10:30
* 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.