mysql全文搜索 sql命令的写法
2011-01-03 14:31
826 查看
//fcicq:下面给大家看看这里php的分词是怎么做的.
function &DV_ChineseWordSegment($str,$encodingName='gbk'){
static $objEnc = null;
if( $objEnc === null ){
if( !class_exists('DV_Encoding') ){
require_once ROOT_PATH.'inc/DV_Encoding.class.php';
}
$objEnc =& DV_Encoding::GetEncoding($encodingName);
}
$strLen = $objEnc->StrLength($str);
$returnVal = array();
if( $strLen < = 1 ){
return $str;
}
$arrStopWords =& DV_GetStopWordList();
//print_r($arrStopWords);
//过滤所有HTML标签
$str = preg_replace('#<[a-zA-Z]+?.*?>|#is', ”, $str);
//过滤所有stopword
$str = str_replace($arrStopWords['StrRepl'],' ‘,$str);
$str = preg_replace($arrStopWords['PregRepl'],' ‘,$str);
//echo “$str:{$str}
“;
$arr = explode(' ‘,$str);
//fcicq:好了,这下面的才是php分词关键 *************
foreach( $arr as $tmpStr ){
if ( preg_match(”/^[x00-x7f]+$/i”,$tmpStr) === 1 )
{ //fcicq:全是E文,没关系,mysql可以认识的
$returnVal[] = ‘ ‘.$tmpStr;
} else{ //fcicq:中英混合…
preg_match_all(”/([a-zA-Z]+)/i”, $tmpStr, $matches);
if( !empty($matches) ){ //fcicq:英语部分
foreach( $matches[0] as $matche ){
$returnVal[] = $matche;
}
}
//过滤ASCII字符
$tmpStr = preg_replace(”/([x00-x7f]+)/i”, ”
, $tmpStr); //fcicq:你看,剩下的不就全是中文了?
$strLen = $objEnc->StrLength($tmpStr)-1;
for( $i = 0 ; $i < $strLen ; $i++ ){
$returnVal[] = $objEnc->SubString($tmpStr,$i,2)
; //fcicq:注意这里的substr,不是手册上的.
//fcicq:你仔细看,所有的词都是分成两个.
//比如”数据库的应用”,会被分成数据 据库 库的 的应 应用…
//全文搜索: 全文 文搜 搜索
//这分词自然是不怎么样的
//但是,搜索的时候同样这么做.
//比如搜索数据库,就相当于搜索了数据 据库.
//这是一种相当传统的全文搜索分词方法.
}
}
}
return $returnVal;
}//end function DV_ChineseWordSegment
//fcicq:这就是传说中的substr.偶相信许多人写出来的php代码都比这个好.
function &SubString(&$str,$start,$length=null){
if( !is_numeric($start) ){
return false;
}
$strLen = strlen($str);
if( $strLen < = 0 ){
return false;
}
if( $start < 0 || $length < 0 ){
$mbStrLen = $this->StrLength($str);
} else{
$mbStrLen = $strLen;
}
if( !is_numeric($length) ){
$length = $mbStrLen;
} elseif( $length < 0 ){
$length = $mbStrLen + $length - 1;
}
if( $start < 0 ){
$start = $mbStrLen + $start;
}
$returnVal = '';
$mbStart = 0;
$mbCount = 0;
for( $i = 0 ; $i < $strLen ; $i++ ){
if( $mbCount >= $length ){
break;
}
$currOrd = ord($str{$i});
if( $mbStart >= $start ){
$returnVal .= $str{$i};
if( $currOrd > 0×7f ){
$returnVal .= $str{$i+1}.$str{$i+2};
$i += 2;
}
$mbCount++;
} elseif( $currOrd > 0×7f ){
$i += 2;
}
$mbStart++;
}
return $returnVal;
}//end function SubString
//插入全文搜索分词表.一共两个,一个 topic_ft,一个bbs_ft
$arrTopicIndex =& DV_ChineseWordSegment($topic);
if( !empty($arrTopicIndex) && is_array($arrTopicIndex) ){
$topicindex = $db->escape_string(implode(' ‘,$arrTopicIndex));
if( $topicindex !== ” ){
$db->query(”UPD ATE {$dv}topic_ft SET topicindex='
{$topicindex}' WHERE topicid='{$RootID}'”);
} else{
$db->query(”DEL ETE FROM {$dv}topic_ft
WHERE topicid='{$RootID}'”);
}
}
}
相关文章推荐
- mysql全文搜索 sql命令的写法
- mysql全文搜索:sql的写法
- mysql 多表关联查询 实现 全文匹配的 模糊搜索接口 SQL
- mysql 全文搜索
- Mysql 常用sql命令
- MySQL数据检索+查询+全文本搜索
- Mysql:命令选项、配置选项、(全局、会话)系统变量、状态变量:SQL模式
- mysql全文搜索match+against
- 实现一个简单的mysql带权重的中文全文搜索
- MySQL导入.sql文件及常用命令
- mysql修改字段长度(sql命令)
- Mysql全文搜索match against的用法
- mysql中获取一天、一周、一月时间数据的各种sql语句写法
- mac 下 sphinx + mysql + php 实现全文搜索(xampp)(3)sphinx 的配置项解析
- MySQL+Sphinx实现全文搜索
- 利用mysql 命令进行sql 语句的格式化输出
- SQL Server之3:全文搜索(3)
- 使用SQL的全文搜索功能构建 Web 搜索应用程序
- mysql命令行命令和SQL语句,MySQL修改删除增加字段类型,字段数据等。。
- MySQL执行外部sql脚本文件的命令