"did you mean blah blah?" function!!!
Moderator: General Moderators
- mudkicker
- Forum Contributor
- Posts: 479
- Joined: Wed Jul 09, 2003 6:11 pm
- Location: Istanbul, TR
- Contact:
"did you mean blah blah?" function!!!
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]
when we write something wrong or mistyped there it goes:
did you mean "a word"?
any ideas how to make this?[/i]
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!
But I'm guessing here!
Suppose you have the words table in your db:
Something like this.
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
Last edited by Weirdan on Sat Dec 06, 2003 1:10 pm, edited 1 time in total.
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...
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...