mysql全文检索中文

小天天天天    数据库    999+ 次    2017-03-28 03:22:31



runSql('CREATE TABLE IF NOT EXISTS `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'); /*数据加入*/ $title='我爱大家啊,大家好'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); $title='中国是什么'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'\',\''.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='问答系统'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); $title='1912网'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); $title='零九网络'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); //搜索: $_GET['q']="中国"; echo 'q'; if(isset($_GET['q'])){$sql=' match(url) against (\''.str_replace('\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']; } }

如果你觉得本篇文章对您有帮助,请打赏作者

上一篇: 分布式自增id->snowflake算法的php实现版本

下一篇: 使用PHP+Redis实现任务队列

最新评论

暂无评论

热门文章

最新评论

网站数据

网站文章数:483

今日UV/PV/IP:6/6/6

昨日UV/PV/IP:22/31 /22

TOP