What is the best way to build a mySQL & PHP search?
I am currently using things like
%term%
I want it to be able to find the result even if they spell it slightly wrong, for example:
Field value = "One: Stop Shop:
They search:
One Shop Stop
OR
One Stop Shop
Etc.. I want a really smart search so they find the information even if they don't search the exact thing.
What is the best way to build a smart search like this?
MySQL, the most popular Open Source SQL database management system, is developed, distributed, and supported by Oracle Corporation. The MySQL website (http://www.mysql.com/) provides the latest information about MySQL software. MySQL is a database management system. A database is a structured collection of data.
You are using a MyISAM table and the space required for the table exceeds what is permitted by the internal pointer size. MyISAM permits data and index files to grow up to 256TB by default, but this limit can be changed up to the maximum permissible size of 65,536TB (2567 − 1 bytes).
MySQL can run more than 50,000 simple queries per second on commodity server hardware and over 2,000 queries per second from a single correspondent on a Gigabit network, so running multiple queries isn't necessarily such a bad thing.
like '%term%'
is terrible slow and unoptimized , you might want to add full-text for this column, and use boolean mode for this
Such as
match(column) against('+One +Shop +Stop' in boolean mode)
Take note on the min word lengths is 4, so, you need to consider change it to three, and full-text search only available for myisam
Other opensource search engine like sphinx is ideal for this too
Ajreal
is right...just thought I'd add an example to help out:
$query = sprintf("SELECT *,
MATCH(col1, col2) AGAINST('%s' IN BOOLEAN MODE) AS relevance
FROM my_table
ORDER BY relevance DESC LIMIT 20", $keyword);
$rs = $conn->query($query);
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With