Entry
A search for 'charlie brown' using two fields returns results for 'charlie brown','charlie' and 'brown' but how can I prioritise these results?
Jun 10th, 2001 21:14
Michael Nolan, Dave Martindale,
Firstly, you need to set the fields you're searching to be FULL TEXT
indexed using the alter table statement. Then you can do a search on
the table:
$search_result = mysql_query("SELECT id,concat(surname,', ',firstname)
AS fullname, MATCH (firstname,surname) AGAINST ('" .
$sq .
"') AS score FROM personal WHERE MATCH
(firstname,surname) AGAINST ('" .
$sq .
"') ORDER BY score DESC;");
$sq is the search query. The where clause in this case makes sure that
only results which match something are returned. The score column will
contain a float number representing how accurate the match is. Sort by
score and Bob's your Uncle.