/// <summary> /// Appends a $facet stage to the pipeline. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="aggregate">The aggregate.</param> /// <param name="facets">The facets.</param> /// <returns>The fluent aggregate interface.</returns> public static IAggregateFluent <AggregateFacetResults> Facet <TResult>( this IAggregateFluent <TResult> aggregate, IEnumerable <AggregateFacet <TResult> > facets) { var newResultSerializer = new AggregateFacetResultsSerializer( facets.Select(f => f.Name), facets.Select(f => f.OutputSerializer ?? BsonSerializer.SerializerRegistry.GetSerializer(f.OutputType))); var options = new AggregateFacetOptions <AggregateFacetResults> { NewResultSerializer = newResultSerializer }; return(aggregate.Facet(facets, options)); }
private async Task <IEnumerable <SearchFacet> > GenerateSearchFacets(IAggregateFluent <Recipe> matchResult, IEnumerable <SearchFacet> selectedFacets) { var searechFacets = await matchResult.Facet(CreateFacet().ToArray()).ToListAsync(); var results = searechFacets.First().Facets.Select(x => new { Group = x.Name, Facets = x.Output <AggregateSortByCountResult <string> >() }); return(from result in results from facet in result.Facets select (new SearchFacet { Count = (Int32)facet.Count, Title = facet.Id, Group = result.Group, Selected = (selectedFacets.Any(x => x.Group == result.Group && x.Title == facet.Id)) })); }
/// <summary> /// Appends a $facet stage to the pipeline. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <typeparam name="TNewResult">The type of the new result.</typeparam> /// <param name="aggregate">The aggregate.</param> /// <param name="facets">The facets.</param> /// <returns> /// The fluent aggregate interface. /// </returns> public static IAggregateFluent <TNewResult> Facet <TResult, TNewResult>( this IAggregateFluent <TResult> aggregate, params AggregateFacet <TResult>[] facets) { return(aggregate.Facet <TNewResult>((IEnumerable <AggregateFacet <TResult> >)facets)); }