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

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

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

Post 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]
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post 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! :)
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post 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:?:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

mudkicker wrote: but then... what should i compare with:?:
With a dictionary :)
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

:) nice try...

well where is this dictionary then? :)

more spesific please!!! :P
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
Last edited by Weirdan on Sat Dec 06, 2003 1:10 pm, edited 1 time in total.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

thank you weirdan really appreciated.
buthow do i increase this table's values? should i enter them manually?
RTT
Forum Commoner
Posts: 38
Joined: Thu Jul 17, 2003 10:22 am
Location: Wolverhampton, UK
Contact:

Post 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... :)
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Post by Linkjames »

Thats actually a bloody clever idea...
Post Reply