Click or drag to resize
IFulltextQueryTDocumentGroupByTKey Method (ExpressionFuncTDocument, TKey)
Group the results of this query by the given key.

Namespace: SphinxConnector.FluentApi
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 3.12.6
Syntax
IFulltextQuery<TDocument> GroupBy<TKey>(
	Expression<Func<TDocument, TKey>> keySelector
)

Parameters

keySelector
Type: System.Linq.ExpressionsExpressionFuncTDocument, TKey
A function to extract the key from a document.

Type Parameters

TKey
The type of the key returned by the function that is represented by keySelector.

Return Value

Type: IFulltextQueryTDocument
The current instance.
Exceptions
ExceptionCondition
ArgumentNullExceptionOccurs when keySelector is null.
InvalidOperationExceptionOccurs when this method called more than once for query.
Examples
To group by multiple attributes, create an anonymous type with the attributes to group by:
using (IFulltextSession fulltextSession = fulltextStore.StartSession())
{
    var results = fulltextSession.Query<Product>().
                                  Match("a product").
                                  GroupBy(p => new { p.CategoryId, p.VendorId }).
                                  Select(p => new
                                  {
                                      p,
                                      Count = Projection.Count()        
                                  }).ToList();
 }
Note that grouping by multiple attributes is only supported with Sphinx 2.1.2 and above.
See Also

Reference