Skip to content

Instantly share code, notes, and snippets.

@lindstromhenrik
Created April 12, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindstromhenrik/6da6a9b62349d12a9d49099d6e13038a to your computer and use it in GitHub Desktop.
Save lindstromhenrik/6da6a9b62349d12a9d49099d6e13038a to your computer and use it in GitHub Desktop.
NestedFacetExtensions. Extensions to the Find nested facets API
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);
}
}
@yasirbutt
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment