Page 1 of 1

"did you mean blah blah?" function!!!

Posted: Fri Nov 21, 2003 8:31 am
by mudkicker
i think you all have seen these sentence in google or altavista search..

when we write something wrong or mistyped there it goes:

did you mean "a word"?

any ideas how to make this?[/i]

Posted: Fri Nov 21, 2003 8:51 am
by Jean-Yves
Google will be storing all queries plus meta info from sites, and can therefore query its database for highest ranking near matches. I imagine that in order to decide what it thinks that the user meant to type in, it either uses SOUNDEX type functions (such as are available in Oracle and others), or it tracks the queries that are entered after an unsuccessful search. That way it can assume that the use has corrected his/her search params and THAT is what the incorrect param was supposed to be, within certain pattern-matching boundaries.

But I'm guessing here! :)

Posted: Fri Nov 21, 2003 9:06 am
by JayBird
Have a look at these functions

[php_man]soundex()[/php_man]
[php_man]levenshtein()[/php_man]
[php_man]metaphone()[/php_man]
[php_man]similar_text()[/php_man]

Mark

Posted: Fri Nov 21, 2003 9:58 am
by mudkicker
well, bech i looked at these functions and saw that soundex is the function at first i need. but i really don't know where i start from...

well at first i get the earch phrase... this is my first word to compare... but then... what should i compare with:?:

Posted: Fri Nov 21, 2003 5:13 pm
by Weirdan
mudkicker wrote: but then... what should i compare with:?:
With a dictionary :)

Posted: Fri Nov 21, 2003 5:22 pm
by mudkicker
:) nice try...

well where is this dictionary then? :)

more spesific please!!! :P

Posted: Fri Nov 21, 2003 6:08 pm
by Weirdan
Suppose you have the words table in your db:

Code: Select all

create table names( word  char(16));
insert into names values('Mudkicker');
insert into names values('Weirdan');
insert into names values('Bech100');
insert into names values('Whirl');

Code: Select all

//... connection code skipped
$_GET['Name']="Weirdna"; //I made a typo in my name 
mysql_query("select word from names where left('".$_GET['Name']."',1) =left(word,1) order by substring(soundex('".$_GET['Name']."'),2)-substring(soundex(word),2) desc limit 1");
list($suggested)=mysql_fetch_row();
if($suggested!=$_GET['Name']) //probably I made a typo
   echo "Did you mean $suggested?\n";
else //probably not 
   echo "You're right, your name is ".$_GET['Name']."\n";
//...... following code skipped
Something like this.

Posted: Sat Nov 22, 2003 3:04 am
by mudkicker
thank you weirdan really appreciated.
buthow do i increase this table's values? should i enter them manually?

Posted: Sat Nov 22, 2003 8:21 am
by RTT
The way i'd do it is allow your users to create the 'dictionary' for you.
When they enter a term (word), store it in a database, no matter what they enter.

As they use your search function, if no results are returned then compare whatever the search term was to whatever words are in the dictionary.

Over time, the dictionary will grow and eventually you should have not only a big dictionary but a dictionary that is tailored to your website ;)

If that makes any sense... :)

Posted: Sat Nov 22, 2003 5:59 pm
by Linkjames
Thats actually a bloody clever idea...