Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best search Algorithm for PHP & MYSQL? [closed]

Tags:

php

search

mysql

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)

like image 846
WEBProject Avatar asked Feb 06 '11 08:02

WEBProject


People also ask

Which algorithm is used in PHP?

For sorting, PHP uses an implementation of quicksort that can be found in Zend/zend_sort.

Which algorithm is best for searching?

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.

Which is the fastest searching algorithm?

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.

What search algorithm does MySQL use?

The algorithm is a binary search (there are optimizations and improvements, but below is the general theory behind it).


2 Answers

You should look into using Full-Text Search.
It might also help you to read about the Tradeoffs of MySQL LIKE vs Full-Text

like image 127
chustar Avatar answered Oct 23 '22 06:10

chustar


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)

Like

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

Sphinx

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.

enter image description here

It is probably more difficult to setup then another(probably last) alternative.

MySQL full-text search

I also think MySQL full-text-search would probably be fast enough and a easier to use.

like image 31
Alfred Avatar answered Oct 23 '22 07:10

Alfred