Mysql full-text retrieval Chinese solution and instance code, mysql full-text retrieval

Source: Internet
Author: User

Mysql full-text retrieval Chinese solution and instance code, mysql full-text retrieval

Mysql full-text retrieval Chinese Solution

Recently, the company's projects require such a function. It is very tricky to search for Chinese characters in the database. You can search for documents online and find similar articles. Here and below, I hope to help you,

Instance code:

<? Php/* mysql full-text retrieval Chinese solution! */Error_reporting (E_ERROR | E_WARNING | E_PARSE); ini_set ('display _ errors ', '1 '); // The Database supports class SaeMysql {// phpmysql operation class} $ DBS = new SaeMysql; // Add echo '2' to the data '; /* CREATE a data TABLE */$ DBS-> runSql ('create table if not exist' ces _ articles '('id' mediumint (8) unsigned not null AUTO_INCREMENT, 'title' varchar (255) COLLATE utf8_unicode_ci not null default \ ', 'url' varchar (255) character set utf8 COLLATE utf8_bin default null, Primary key ('id'), fulltext key 'url' ('url') ENGINE = MyISAM AUTO_INCREMENT = 1 default charset = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = DYNAMIC '); /* add data */$ title = 'Hello everyone! '; $ DBS-> runSql ('insert INTO 'ces _ articles' (id, title, url) VALUES (0 ,\''. $ title. '\',\''. str_replace ('\ U', 'U', trim (json_encode ($ title ))). '\') '; $ title = 'what is China'; $ DBS-> runSql ('insert INTO 'ces _ articles' (id, title, url) VALUES (0 ,\''. $ t Itle. '\',\''. str_replace ('\ U', 'U', trim (json_encode ($ title ))). '\'); $ title = 'HTTP: // ask.1912news.com '; $ DBS-> runSql ('insert INTO 'ces _ articles' (id, title, url) VALUES (0 ,\''. $ title. '\',\''. str_replace ('\ U', 'U', trim (json_encode ($ title ))). '\') '; $ title = 'q & A system'; $ DBS-> runSql ('insert INTO 'ces _ articles' (id, title, url) VALUES (0, \''. $ title. '\',\''. str_replace ('\ U', 'U', trim (json_encode ($ title ))). '\'); $ ti Tle = '1970 net'; $ DBS-> runSql ('insert INTO 'ces _ articles '(id, title, url) VALUES (0 ,\''. $ title. '\',\''. str_replace ('\ U', 'U', trim (json_encode ($ title ))). '\'); $ title = 'zero nine network'; $ DBS-> runSql ('insert INTO 'ces _ articles '(id, title, url) VALUES (0 ,\''. $ title. '\',\''. str_replace ('\ U', 'U', trim (json_encode ($ title ))). '\'); // search: $ _ GET ['q'] = "China"; echo 'q '; if (isset ($ _ GET ['q']) {$ SQL = 'match (url) against (\''. str_repla Ce ('\ U', 'U', trim (json_encode ($ _ GET ['q']). '\ 'In boolean mode)';} $ query = $ DBS-> getData ('select * FROM 'ces _ articles 'where '. $ SQL. 'limit 10'); echo 'q'; if ($ query) {foreach ($ query as $ article) {echo $ article ['id'] ;}}?>

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.