Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Find : filtering on IEnumerable<T>.Count().Match()



I'm struggling doing something I though would be easy.

Here is the situation : I would like to filter a query based on a page property which is an IEnumerable. To be more precise, I'd like to filter pages that have exactly 10 items (for example). I tried many things but cannot make it work.

Here is what I tested with no luck :

search.Filter(page => page.Tags.Count().Match(10));

I also tried custom filters, but to no avail.

Any help would be really appreciated.



Feb 09, 2016 16:48

Create a separate property on the content type that calculates this but isn't stored in episerver and index that one instead?

Feb 09, 2016 17:16

Thanks a lot Daniel, it works. It was so simple, again thank you!

Feb 09, 2016 18:08


Feb 09, 2016 20:59

Tip: Instead of adding a new property, you could also add a convention for Count. Like this:

SearchClient.Instance.Conventions.ForInstancesOf<YourType>().IncludeField(x => x.Tags.Count());

That way, your original query will still work.
Make sure the convention is added in an initializable module.

Feb 10, 2016 10:18


I'm interested in this approach, I'll test it.

Thanks !


Feb 11, 2016 15:04

Convention is even better yes :)

Feb 11, 2016 15:09
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.