mysql php 全文检索 中文_mysql全文检索中文解决方案

/*

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'];

}

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值