Click or drag to resize

IFulltextQueryTDocumentGroupByTKey Method (ExpressionFuncTDocument, TKey, Int32)

Group the results of this query by the given key and return a given amount of results per group. Supported with Sphinx 2.2.1 and above.

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

Parameters

keySelector
Type: System.Linq.ExpressionsExpressionFuncTDocument, TKey
A function to extract the key from a document.
maxResultsPerGroup
Type: SystemInt32
The (maximum) number of results to return per group.

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.
ArgumentOutOfRangeExceptionOccurs when maxResultsPerGroup is less than one.
InvalidOperationExceptionOccurs when this method called more than once for query.
Examples
using (IFulltextSession fulltextSession = fulltextStore.StartSession())
{
    var results = fulltextSession.Query<Product>().
                                  Match("a product").
                                  GroupBy(p => p.CategoryId, 5).
                                  Select(p => new
                                  {
                                      p.CategoryId,
                                      p.Name,
                                      p.Price                                               
                                  }).ToList();
 }
See Also