Created
April 12, 2016 08:41
-
-
Save lindstromhenrik/6da6a9b62349d12a9d49099d6e13038a to your computer and use it in GitHub Desktop.
NestedFacetExtensions. Extensions to the Find nested facets API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class NestedFacetExtensions | |
{ | |
// Allow passing Action<NestedTermsFacetRequest> facetRequestAction (in order to set for example Size on the request) | |
public static ITypeSearch<TSource> TermsFacetFor<TSource, TListItem> | |
(this ITypeSearch<TSource> search,Expression<Func<TSource, IEnumerable<TListItem>>> nestedFieldSelector, | |
Expression<Func<TListItem, string>> itemFieldSelector, | |
Expression<Func<TListItem, Filter>> filterExpression = null, | |
Action<NestedTermsFacetRequest> facetRequestAction = null) | |
{ | |
var facetFilter = NestedFilter.Create(search.Client.Conventions, nestedFieldSelector, filterExpression); | |
Action<NestedTermsFacetRequest> action = null; | |
if (facetRequestAction.IsNotNull()) | |
{ | |
action = x => | |
{ | |
x.FacetFilter = facetFilter; | |
facetRequestAction(x); | |
}; | |
} | |
else | |
{ | |
action = x => x.FacetFilter = facetFilter; | |
} | |
return search.TermsFacetFor(nestedFieldSelector, itemFieldSelector, action); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
it is not supporting when i have nested object and that object has list of string like List but it work only for string.
I have Replies as nested object and in reply i have list of receipients as list of string.
i am trying to do .NestedTermsFacetFor(x=>x.Replies, y=>y.RecipientIds.In(new[] { userName }, true))
can you help me?
/Yasir