开发者

How to use mysql LIKE to create a search system?

开发者 https://www.devze.com 2023-01-02 23:53 出处:网络
How t开发者_Go百科o use mysql LIKE to create a search system?Don\'t.It will be hard to avoid false positives, and it will run hundreds or thousands of times slower than using a real fulltext search so

How t开发者_Go百科o use mysql LIKE to create a search system?


Don't. It will be hard to avoid false positives, and it will run hundreds or thousands of times slower than using a real fulltext search solution.

Suppose you search for the word "one":

SELECT * FROM SomeTable WHERE textfield LIKE '%one%';

This will also match text where words such as "money" "lonely" "bone" etc.

And it has to scan the whole table to compare the pattern to the text in every row. There's no way a conventional index can help.

Instead, use a FULLTEXT index, or a search engine like Solr or Sphinx Search, or external search engine like Google Custom Search Engine or Yahoo Search Web Services.

See also my presentation Practical Fulltext Search in MySQL.


SELECT * FROM mytable WHERE SEARCHABLE_FIELD LIKE "%SOMETHING%" 

It's not really a good way to create a search system, but that's what you are asking... so there you go.


select * from where like ''

Something like that ...

you can use % as a wildcard...

0

精彩评论

暂无评论...
验证码 换一张
取 消