Facetting SearchParameters

Kenny Deblaere asked on May 4, 2016 10:27

Hello

I'm currently looking to build a filter in code. I've created a query with SearchParameters, working correctly.

I have a list with checkboxes, to select my items. When I select a box, I make an API call and return the filtered items to my view.

The other problem is, my checkboxes have to show the number of items will be shown, when clicking on them. (facetting).

Is there a possible way to do this?

Thanks in advance

Kenny

Recent Answers


Felix Planjer answered on May 4, 2016 16:39

You can get the CurrentSearchDocuments from the SearchContext. You can search this list of current search results for the value of your checkbox to determine the number of items that have that value.

It could look something like this: First get all value of the field you are facetting into a list, then count the number of time the value of you checkbox appears in the list.

var values = SearchContext.CurrentSearchResults.TypedValues
     .Where(d => d.Table.Columns.Contains("fieldname") && d.Field<string>("fieldname") != null)
     .Select(b => b.Field<string>("fieldname")).ToList();

int count = values.Where(d => d == value).Count();
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.