Ayende @ Rahien

Hi!
My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 5,972 | Comments: 44,511

filter by tags archive

Raven Suggest


Originally posted at 11/18/2010

image 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

Jason Meckley

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.

Julio Camps

Hi, where is located Suggest() method?

ex: q.Suggest();

I can not find it.

Please excuse my poor english, i am cuban engineer.

John Harman

Great feature, I presume it's running off something similar to Snowball.NET?

Ayende Rahien

Julio,

You are probably looking at the stable branch, you should look at the unstable, that is where the new features are.

Ayende Rahien

John,

No, it is based on Spell.NET

jalchr

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")

     where user.Name.SuggestedFrom(name)

     select user;

Is this doable ... ?

Ayende Rahien

Jalchr,

You can certainly write a query that would do that, but why would you want to do this?

jalchr

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 ?

Ayende Rahien

Jalchr,

You can query for each of the possible names, sure. Or combine them into a single query.

Not very useful, though.

Julio Camps

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

Ayende Rahien

Julio,

Is is there, as an extension method, you need to import the namespace Raven.Client.Linq

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. Reducing parsing costs in RavenDB - one day from now

There are posts all the way to Aug 04, 2015

RECENT SERIES

  1. Production postmortem (5):
    29 Jul 2015 - The evil licensing code
  2. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
  3. API Design (7):
    20 Jul 2015 - We’ll let the users sort it out
  4. What is new in RavenDB 3.5 (3):
    15 Jul 2015 - Exploring data in the dark
  5. The RavenDB Comic Strip (3):
    28 May 2015 - Part III – High availability & sleeping soundly
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats