I want to make a search for articles on my website - is it ok to use just plain 'LIKE' statement or is there a better search algorithm to use with MySQL? (its important it be efficient)
For sorting, PHP uses an implementation of quicksort that can be found in Zend/zend_sort.
This type of searching algorithm is used to find the position of a specific value contained in a sorted array. The binary search algorithm works on the principle of divide and conquer and it is considered the best searching algorithm because it's faster to run.
According to a simulation conducted by researchers, it is known that Binary search is commonly the fastest searching algorithm. A binary search is performed for the ordered list. This idea makes everything make sense that we can compare each element in a list systematically.
The algorithm is a binary search (there are optimizations and improvements, but below is the general theory behind it).
You should look into using Full-Text Search.
It might also help you to read about the Tradeoffs of MySQL LIKE vs Full-Text
is it ok to use just plain 'LIKE' statement or is there a better search algorithm to use with MySQL? (its important it be efficient)
If it is important to be efficient then I think LIKE is absolutely not the way to go.
Full Text Search: 392 Sec Full Text Search (Cached): 272 Sec
Full Text Boolean Mode 12 Sec Full Text Boolean (Cached) 11 Sec
Mnogosearch (external) 3.5 Sec Mnogosearch (external cached) 1.06 Sec
Sphinx 0.23 Sec Sphinx Cached 0.15 Sec
LIKE %...% 30sec Sec LIKE %...% (Cached) 29sec Sec
Probably Sphinx is the most efficient method, which also has support for MySQL. To be honest I have never used Sphinx myself, but some very big sites use it.
It is probably more difficult to setup then another(probably last) alternative.
I also think MySQL full-text-search would probably be fast enough and a easier to use.
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