You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 5.1 version.
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 | ||
---|---|---|
index | string | A name of an index to query. |
suggestionQuery | SuggestionQuery | A suggestion query definition containing all information required to query a specified index. |
Return Value | |
---|---|
SuggestionQueryResult | Result 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