Web Hosting Talk







View Full Version : MySQL; Search For Most Similar


TomorrowHosting
05-14-2006, 11:29 AM
I am working on a PHP script, and I want it so it searches a database for something (such as "MySQL is very fun to use"). Now I want it so that if there was no result called "MySQL is very fun to use", then it searches for the most similar entry (such as "MySQL is fun to use" or MySQL is easy to use".) Is that at all possible, and if it is, may somebody explain it to me, or point me to a place that does?

Thanks!

Also I understand basic MySQL (how to do searches, and other simple stuff like that).

Also if this isn't possible, is there any way to reverse wild card (wild card the results instead of the search). This would mean that if you searched for "MySQL is fun and easy to use", then "MySQL is fun" could show up.

thartdyke
05-14-2006, 11:38 AM
You could try using the full text search functionality. You put a full text index on the field(s) of interest, then run a search using MATCH...AGAINST. MySQL will return rows in relevance order.

Whether they seem relevant to you is another issue though. The comparison is mechanical and attaches no meaning to words.

TomorrowHosting
05-14-2006, 12:00 PM
Thank-you for that information. I guess this will lead into my next question. How would I split up variable with a multiword value (such as "WebHostingTalk is very useful" into as many variables to make each variable one word (so it would turn into one variable as "WebHostingTalk", one variable as "is", and one variable as "very", and one variable as "useful")?

Thank-you for your help!

thartdyke
05-14-2006, 12:20 PM
By default, the full text search treats each word individually. To treat words as a phrase, enclose in double quotes (where the entire search string is enclosed in single quotes).

TomorrowHosting
05-14-2006, 06:40 PM
Ok. Thanks! :D