Filter by all categories

Vote:
 

Hi

I've to filter a page type ie Article pages conating a list of categories

My query is


var selectedCategories = new List{1,2,3}

var result = _client.Search()

        

this code return articles conatain any of the categories in the list. But I want to return articles contain all the categories in list

#187211
Jan 16, 2018 6:42
Vote:
 

You could try creating a extension method something like this. (haven't tested this)

 public static ITypeSearch<T> AllCategoriesMatch<T>(this ITypeSearch<T> search, IEnumerable<int> categories) where T : ICategorizable
 {
      foreach (var category in categories)
      {
          search = search.Filter(p => p.Category.Match(category));
      }
            return search;
}

and in your query

_client.Search<ArticlePage>().AllCategoriesMatch(selectedCategories)

#187228
Edited, Jan 16, 2018 13:14
* 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.