Session: Querying: How to work with suggestions?
Session Query
method contains extensions (Suggest
) that allow you to use suggestion feature.
Syntax
// This dynamic query on the 'Products' collection has NO resulting documents
List<Product> products = session
.Query<Product>()
.Where(x => x.Name == "chaig")
.ToList();
Parameters | ||
---|---|---|
query | SuggestionQuery | A suggestion query definition containing all information required to query a specified index. |
Return Value | |
---|---|
SuggestionQueryResult | Result containing array of all suggestions for executed query. |
Example
// Query for suggested terms for single term:
// ==========================================
Dictionary<string, SuggestionResult> suggestions = session
// Make a dynamic query on collection 'Products'
.Query<Product>()
// Call 'SuggestUsing'
.SuggestUsing(builder => builder
// Request to get terms from field 'Name' that are similar to 'chaig'
.ByField(x => x.Name, "chaig"))
.Execute();