 | IFulltextQueryTDocumentGroupByTKey(ExpressionFuncTDocument, TKey) Method |
Group the results of this query by the given key.
Namespace: SphinxConnector.FluentApiAssembly: SphinxConnector (in SphinxConnector.dll) Version: 6.0.0
SyntaxIFulltextQuery<TDocument> GroupBy<TKey>(
Expression<Func<TDocument, TKey>> keySelector
)
Function GroupBy(Of TKey) (
keySelector As Expression(Of Func(Of TDocument, TKey))
) As IFulltextQuery(Of TDocument)
Parameters
- keySelector ExpressionFuncTDocument, 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
IFulltextQueryTDocumentThe current instance.
Exceptions
Example
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