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

Vote:
 

Hi,

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.

Thanks,

Matthieu

#144237
Feb 09, 2016 16:48
Vote:
 

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

#144238
Feb 09, 2016 17:16
Vote:
 

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

#144241
Feb 09, 2016 18:08
Vote:
 

:)

#144243
Feb 09, 2016 20:59
Vote:
 

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.

#144273
Feb 10, 2016 10:18
Vote:
 

Hi,

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

Thanks !

Matthieu

#144364
Feb 11, 2016 15:04
Vote:
 

Convention is even better yes :)

#144370
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.