這篇文章主要介紹了mysql 全文檢索中文解決方法及實例代碼的相關資料,需要的朋友可以參考下
mysql 全文檢索中文解決方法
??????????? 最近公司項目要求這樣的功能,在數據庫中檢索中文,很是棘手,上網查詢下資料,找的類似文章,這里及記錄下,希望能幫助到大家,
實例代碼:???
<?php /* mysql全文檢索中文解決方案! */ error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('display_errors', '1'); //數據庫支持 class SaeMysql{ //phpmysql操作類 } $DBS=new SaeMysql; //數據加入 echo '2'; /*創建數據表*/ $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'); /*數據加入*/ $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']; } } ?>
以上就是mysql 全文檢索中文解決方法及實例代碼分享的內容,更多相關內容請關注PHP中文網(www.php.cn)!
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END