Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to build a SMART mySQL & PHP search engine?

Tags:

php

search

mysql

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?

like image 623
Latox Avatar asked Jan 10 '11 02:01

Latox


People also ask

Which software is used for MySQL?

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.

How big can a MySQL table be?

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).

How many queries can MySQL handle?

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.


2 Answers

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

like image 67
ajreal Avatar answered Sep 28 '22 11:09

ajreal


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

like image 39
timpng1 Avatar answered Sep 28 '22 10:09

timpng1