IFulltextQueryTDocumentGroupByTKey(ExpressionFuncTDocument, TKey, Int32) Method

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.

Definition

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

Parameters

keySelector  ExpressionFuncTDocument, TKey
A function to extract the key from a document.
maxResultsPerGroup  Int32
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

IFulltextQueryTDocument
The current instance.

Example

C#
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();
 }

Exceptions

ArgumentNullExceptionOccurs when keySelector is null.
ArgumentOutOfRangeExceptionOccurs when maxResultsPerGroup is less than one.
InvalidOperationExceptionOccurs when this method called more than once for query.

See Also