Skip to main content

Commands: Querying: How to work with Suggestion query?

To take advantage of a suggestion feature use the Suggest method from the commands.

Syntax

SuggestionQueryResult Suggest(string index, SuggestionQuery suggestionQuery);
Parameters
indexstringA name of an index to query.
suggestionQuerySuggestionQueryA suggestion query definition containing all information required to query a specified index.
Return Value
SuggestionQueryResultResult containing an array of all suggestions for executed query

Example

// Get suggestions for 'johne' using 'FullName' field in 'Users/ByFullName' index
SuggestionQueryResult result = store
.DatabaseCommands
.Suggest(
"Users/ByFullName",
new SuggestionQuery
{
Field = "FullName",
Term = "johne",
MaxSuggestions = 10
});

Console.WriteLine("Did you mean?");

foreach (string suggestion in result.Suggestions)
{
Console.WriteLine("\t{0}", suggestion);
}

// Did you mean?
// john
// jones
// johnson