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!