# How does google do the "did you mean...."?

**URL:** <https://www.ruby-forum.com/t/how-does-google-do-the-did-you-mean/107101>\
**Category:** Rails\
**Created:** [June 18, 2007, 6:33am UTC](https://www.ruby-forum.com/t/how-does-google-do-the-did-you-mean/107101 "2007-06-18T06:33:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 18, 2007, 6:33am UTC](https://www.ruby-forum.com/t/how-does-google-do-the-did-you-mean/107101/1 "2007-06-18T06:33:16Z")

</div>

I have a search on my website that search names, so I know all of the  
values they could enter. How do I do something like google where if I  
type jonson it would say “did you mean johnson”?

Any ideas?

Thanks.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 18, 2007, 6:57am UTC](https://www.ruby-forum.com/t/how-does-google-do-the-did-you-mean/107101/2 "2007-06-18T06:57:57Z")

</div>

On Jun 17, 9:33 pm, Ben J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I have a search on my website that search names, so I know all of the  
> values they could enter. How do I do something like google where if I  
> type jonson it would say “did you mean johnson”?
> 
> Any ideas?
> 
> Thanks.
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

there’s several ways: Levenshtein distance, soundex, Metaphone and  
Phonex algo’s. There’ve been threads on “spelling correction” here  
and in rubytalk.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 18, 2007, 7:06am UTC](https://www.ruby-forum.com/t/how-does-google-do-the-did-you-mean/107101/3 "2007-06-18T07:06:58Z")

</div>

A bunch of useful stuff: [http://text.rubyforge.org/](http://text.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 18, 2007, 7:09am UTC](https://www.ruby-forum.com/t/how-does-google-do-the-did-you-mean/107101/4 "2007-06-18T07:09:39Z")

</div>

removed\_email\_address@domain.invalid wrote:

> > Posted viahttp://www.ruby-forum.com/.
> 
> there’s several ways: Levenshtein distance, soundex, Metaphone and  
> Phonex algo’s. There’ve been threads on “spelling correction” here  
> and in rubytalk.

I actually tried soundex, the problem is that I’m dealing with parts of  
the string in the database, not the entire string. There is not split()  
function for mysql. Example:

A person types “red sox” and my field has “boston red sox”, soundex  
would not detect that.

I’m trying to do this all in a query, for performance reasons, but this  
seems to be nearly impossible sicnce mysql does not have a split()  
function for strings.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 18, 2007, 7:16am UTC](https://www.ruby-forum.com/t/how-does-google-do-the-did-you-mean/107101/5 "2007-06-18T07:16:00Z")

</div>

Have you looked at SOLR or other full text search plug-ins.

Michael

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 18, 2007, 8:18am UTC](https://www.ruby-forum.com/t/how-does-google-do-the-did-you-mean/107101/6 "2007-06-18T08:18:04Z")

</div>

Quoting Ben J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I have a search on my website that search names, so I know all of the  
> values they could enter. How do I do something like google where if I  
> type jonson it would say “did you mean johnson”?
> 
> Any ideas?
> 
> Thanks.

Pete Norvig explains how he did it:  
[http://norvig.com/spell-correct.html](http://norvig.com/spell-correct.html)

–  
Pau Garcia i Quiles  
[http://www.elpauer.org](http://www.elpauer.org)  
(Due to the amount of work, I usually need 10 days to answer)

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [June 18, 2007, 3:17pm UTC](https://www.ruby-forum.com/t/how-does-google-do-the-did-you-mean/107101/7 "2007-06-18T15:17:06Z")

</div>

There’s also a plugin for the feature:

[http://agilewebdevelopment.com/plugins/acts\_as\_suggest](http://agilewebdevelopment.com/plugins/acts_as_suggest)

–  
Benjamin C.  
[http://www.bencurtis.com/](http://www.bencurtis.com/) – blog  
[http://agilewebdevelopment.com/rails-ecommerce](http://agilewebdevelopment.com/rails-ecommerce) – build e-commerce  
sites with Rails
