PDA

View Full Version : PHP/MySQL Search?



duncanhall
February 27th, 2007, 08:16 AM
So I'm about to start a new project, which will involve a search feature. I've made fairly basic searches in PHP / MySQL before using a simple model of something like:



SELECT * FROM someTable WHERE field1 OR field2 LIKE '%seach_string%';


Obviously this will work, but to a fairly rudimentary level. What I'm looking for is something that can search several fields and return the results ordered to a certain degree of relevancy.

Does anyone know of any good tutorials on creating more advanced search features, or possibly some kind of open source search facility that can be fairly easily tied into a site?

Voetsjoeba
February 27th, 2007, 08:26 AM
What you described is exactly what MATCH fields AGAINST( value ) will do. It is the MySQL function that searches one or more fields for any occurences of value, provided those fields have FULLTEXT indices. That is required. MATCH will in fact return a number that represents a relevancy index, so that you can easily sort by that (the higher this number, the more relevant).

http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

duncanhall
February 27th, 2007, 08:31 AM
Sexcellent, that seems to be exactly what I needed. Looks like plenty of reading and annoying MySQL server beeps are coming my way.

Thanks!

Voetsjoeba
February 27th, 2007, 10:27 AM
Nah, it's pretty straightforward actually. Just keep in mind to get those FULLTEXT indices and you'll be fine :)

blazes
February 27th, 2007, 06:19 PM
Sexcellent

Best. Typo. Ever.

duncanhall
February 27th, 2007, 06:39 PM
Unfortunately not a typo, but a fantastic word nonetheless.

blazes
February 27th, 2007, 06:59 PM
^Very true.