IFulltext QueryTDocumentGroup ByTKey(ExpressionFuncTDocument, TKey) Method
Group the results of this query by the given key.
Definition
Namespace: SphinxConnector.FluentApi
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 6.1.0
The current instance.
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 6.1.0
C#
IFulltextQuery<TDocument> GroupBy<TKey>(
Expression<Func<TDocument, TKey>> keySelector
)
VB
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.
Example
To group by multiple attributes, create an anonymous type with the attributes to group by:
Note that grouping by multiple attributes is only supported with Sphinx 2.1.2 and above.
C#
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();
}Exceptions
| ArgumentNullException | Occurs when keySelector is null. |
| InvalidOperationException | Occurs when this method called more than once for query. |