Over a million developers have joined DZone.

Raven Suggest

DZone's Guide to

Raven Suggest

Free Resource
Since RavenDB’s indexing is based on Lucene, we get a lot of advantages. One of them is supporting suggestions.

What 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?
Enter user name: onre
Did you mean?

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.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}