ËùÒÔ,µ½ÕâÀïÄãÓ¦¸Ã»ámysql Ó¢ÎÄÈ«ÎÄËÑË÷ÁË.
Çë×¢ÒâÒ»¸öÎÊÌâ.
һЩ´ÊÔÚÈ«ÎÄËÑË÷ÖлᱻºöÂÔ£º
* ÈκιýÓڶ̵Ĵʶ¼»á±»ºöÂÔ¡£ È«ÎÄËÑË÷ËùÄÜÕÒµ½µÄ´ÊµÄĬÈÏ×îС³¤¶ÈΪ 4¸ö×Ö·û¡£
* Í£Ö¹×ÖÖеĴʻᱻºöÂÔ¡£
mysql»¹×Ô´ø²éѯÀ©Õ¹¹¦ÄÜ.ÕâÀï²»×ö¹ý¶àÌÖÂÛ.
ÏÂÃæ½øÐÐphpÖÐÎÄÈ«ÎÄËÑË÷µÄ·ÖÎö
Ôø¾ÓÐÒ»¸ö°æ±¾µÄmysqlÖ§³ÖÖÐÎÄÈ«ÎÄËÑË÷(º£Á¿ mysql chinese+,˵ÊÇGPLµ«ÊÇ×îÖÕûÓпªÔ´)
ÖÐÎÄÈ«ÎÄËÑË÷µÄ¹Ø¼üÊÇÔÚ·Ö´ÊÉÏ.mysql±¾Éí²»Ö§³ÖcjkµÄ·Ö´Ê(cjk:chinese,japanese,korean),
ËùÒÔ
!!!!****ÈçºÎÓÃphpÄ£Äâ·Ö´ÊÊÇmysqlÈ«ÎÄË÷ÒýµÄ¹Ø¼ü****!!!!
ÖÐÎÄ·Ö´ÊÊÇÓïÑÔ·Ö´ÊÖÐ×îÀ§ÄѵÄ.ÏÖÔÚҲûÓÐÈËÄܹ»³¹µ×ÍêÃÀµÄ½â¾ö(ËäÈ»ÕâЩËÑË÷ÒýÇæ×öµÄ¶¼»¹²»´í.)
//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('#|#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:Äã¿´,ʣϵIJ»¾ÍÈ«ÊÇÖÐÎÄÁË?
$strLen = $objEnc->StrLength($tmpStr)-1;
for( $i = 0 ; $i < $strLen ; $i++ ){
$returnVal[] = $objEnc->SubString($tmpStr,$i,2)
; //fcicq:×¢ÒâÕâÀïµÄsubstr,²»ÊÇÊÖ²áÉϵÄ.
//fcicq:Äã×Ðϸ¿´,ËùÓеĴʶ¼ÊÇ·Ö³ÉÁ½¸ö.
//±ÈÈç”Êý¾Ý¿âµÄÓ¦ÓÔ,»á±»·Ö³ÉÊý¾Ý ¾Ý¿â ¿âµÄ µÄÓ¦ Ó¦ÓÃ…
//È«ÎÄËÑË÷: È«ÎÄ ÎÄËÑ ËÑË÷
//Õâ·Ö´Ê×ÔÈ»ÊDz»ÔõôÑùµÄ
//µ«ÊÇ,ËÑË÷µÄʱºòͬÑùÕâô×ö.
//±ÈÈçËÑË÷Êý¾Ý¿â,¾ÍÏ൱ÓÚËÑË÷ÁËÊý¾Ý ¾Ý¿â.
//ÕâÊÇÒ»ÖÖÏ൱´«Í³µÄÈ«ÎÄËÑË÷·Ö´Ê·½·¨.
}
}
}
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È«ÎÄËÑË÷·Ö´Ê£¬mysql²»»á·Ö´Ê£¬¶øphp»á¡£¾ÍÕâô¼òµ¥¡£
ÕâËäÈ»ÊÇÒ»ÖֱȽϹýʱµÄ·½·¨£¬µ«ÊǷdz£ÊµÓá£