主頁(yè) > 知識(shí)庫(kù) > mysql 全文檢索中文解決方法及實(shí)例代碼

mysql 全文檢索中文解決方法及實(shí)例代碼

熱門標(biāo)簽:百度競(jìng)價(jià)排名 AI電銷 地方門戶網(wǎng)站 Linux服務(wù)器 鐵路電話系統(tǒng) 網(wǎng)站排名優(yōu)化 服務(wù)外包 呼叫中心市場(chǎng)需求

mysql 全文檢索中文解決方法

            最近公司項(xiàng)目要求這樣的功能,在數(shù)據(jù)庫(kù)中檢索中文,很是棘手,上網(wǎng)查詢下資料,找的類似文章,這里及記錄下,希望能幫助到大家,

實(shí)例代碼:   

?php
/*
mysql全文檢索中文解決方案!
*/
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors', '1');
//數(shù)據(jù)庫(kù)支持
class SaeMysql{
//phpmysql操作類
}
$DBS=new SaeMysql;
//數(shù)據(jù)加入
echo '2';
/*創(chuàng)建數(shù)據(jù)表*/
$DBS->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');
/*數(shù)據(jù)加入*/
$title='我愛(ài)大家啊,大家好';
$DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'',\''.str_replace('u','u',trim(json_encode($title))).'')');
$title='中國(guó)是什么';
$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='問(wèn)答系統(tǒng)';
$DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'',\''.str_replace('u','u',trim(json_encode($title))).'')');
$title='1912網(wǎng)';
$DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'',\''.str_replace('u','u',trim(json_encode($title))).'')');
$title='零九網(wǎng)絡(luò)';
$DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'',\''.str_replace('u','u',trim(json_encode($title))).'')');
//搜索:
$_GET['q']="中國(guó)";
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'];
}
}

?>

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

您可能感興趣的文章:
  • Mysql實(shí)現(xiàn)全文檢索、關(guān)鍵詞跑分的方法實(shí)例
  • PHP+MySQL+sphinx+scws實(shí)現(xiàn)全文檢索功能詳解
  • 深度解析MySQL 5.7之中文全文檢索
  • MySQL 全文檢索的使用示例

標(biāo)簽:蘭州 崇左 湖南 銅川 黃山 衡水 湘潭 仙桃

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《mysql 全文檢索中文解決方法及實(shí)例代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266