pritaeas
Posting Prodigy
9,310 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,465
Skill Endorsements: 86
Put the percentage signs inside the single quotes.
pritaeas
Posting Prodigy
9,310 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,465
Skill Endorsements: 86
Using LIKE has always bugged the hell out of me, as it doesn't take relevancy into account (e.g. exact matches before partials). I did a bit of searching for 'fulltext indexing'. I found this thread:
http://stackoverflow.com/questions/1016804/how-to-sort-mysql-fulltext-search-results-by-relevancy
From which the following example has been cobbled:
ALTER TABLE `users` ADD FULLTEXT INDEX `SEARCH`(`username`);
SELECT *, MATCH(username) AGAINST ('John' IN BOOLEAN MODE) AS relevance
FROM `users`
WHERE MATCH(username) AGAINST ('John' IN BOOLEAN MODE)
ORDER BY relevance DESC
I *think* you can use multiple fields for searching in the MATCH list too.
diafol
Keep Smiling
10,666 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,514
Skill Endorsements: 57
Note that you have to have MyISAM tables, to use full-text search.
pritaeas
Posting Prodigy
9,310 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,465
Skill Endorsements: 86
Question Answered as of 1 Year Ago by
pritaeas
and
diafol