Raven Suggest
Originally posted at 11/18/2010
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? 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.
Comments
It's awesome to see Raven coming into it's own. The feature set incorporated into Raven is really making this product stand out among the competition.
Hi, where is located Suggest() method?
ex: q.Suggest();
I can not find it.
Please excuse my poor english, i am cuban engineer.
Great feature, I presume it's running off something similar to Snowball.NET?
Julio,
You are probably looking at the stable branch, you should look at the unstable, that is where the new features are.
John,
No, it is based on Spell.NET
That's a nice feature. What I need in addition to this, is I need to query for all possible matches as the "suggest" is doing ... but in a query
Something like this :
var q = from user in session.Query <user("Users/ByName")
Is this doable ... ?
Jalchr,
You can certainly write a query that would do that, but why would you want to do this?
You know users sometimes misspell names ... I need to check for name uniques even if it is entered "wrong" and use one copy of a name ...
Can you suggest a way to query this ... or can we expect raven to have such feature built in ?
Jalchr,
You can query for each of the possible names, sure. Or combine them into a single query.
Not very useful, though.
HI again :)
IN build 206, say that
Full support for suggestions, on both lucene & linq queries
But i can not find it :(, i must use a specific namespace ??
Where is located this feature?? You may post using clause for this sample? Thank's in advanced
Julio,
Is is there, as an extension method, you need to import the namespace Raven.Client.Linq
Comment preview