Raven Suggest
Join the DZone community and get the full member experience.
Join For FreeWhat is the Raven Suggest feature? Let us say that we give the user the option to perform some query, but the query that they sent us isn’t returning enough results (or non at all).
We can ask RavenDB to figure out what the user meant. Here is the code:
var q = from user in session.Query<User>("Users/ByName")
where user.Name == name
select user;
Now, we can call q.FirstOrDefault() on this query, and see if we got any results. If we didn’t get a result, we can now ask RavenDB for help:
var suggestionQueryResult = q.Suggest();
Console.WriteLine("Did you mean?");
foreach (var suggestion in suggestionQueryResult.Suggestions)
{
Console.WriteLine("\t{0}", suggestion);
}
This will produce the following output:
Enter user name: oren
Found user: users/1
Enter user name: ore
Did you mean?
oren
Enter user name: onre
Did you mean?
oren
This is a nice little feature, which can really make a difference in terms of your application’s user experience.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments