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

3

18

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)

Escalator answered 6/2, 2011 at 8:26 Comment(0)
C
14

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

Clausen answered 6/2, 2011 at 8:57 Comment(1)
Note: The MySQL link refers to the 5.0 documentation. In 5.0, FTS is only allowed on MyISAM tables. In MySQL versions >= 5.6, FTS is allowed on both MyISAM and InnoDB.Jordison
S
14

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.

Savor answered 6/2, 2011 at 10:8 Comment(0)
J
0

I would consider Using Apache Solr https://lucene.apache.org/solr/ or Elastic Search http://www.elasticsearch.org/

Jud answered 24/12, 2013 at 3:22 Comment(1)
Could you expand your answer as to why these would be appropriate. Otherwise it's just a link.Tref

© 2022 - 2024 — McMap. All rights reserved.