## 名称: phpBB3中文二分法搜索
## 作者: IOsetting
## 功能描述:
## 对中文应用二分法分词, 并限制分词结果数组大小, 提高搜索准确率, 降低服务器负载
## '中文二分法' 在默认分词中, 分为 '中 文 二 分 法', 二分法中分为 '中文 文二 二分 分法'
##
## 注意:
## 此分词法对日文搜索支持不好.
## 应用此分词法会导致索引词库较原词库增长两倍到三倍, 对MySQL空间大小有顾忌的请考虑清楚
##
## 版本: Build 20080709
##
## 安装难度: Easy
## 估计时间: 1 Minutes
##
##
#######################################################
打开\phpBB3\phpbb\search\fulltext_native.php
找到
代码: 全选
$exact_words = array();
preg_match_all('#([^\\s+\\-|*()]+)(?:$|[\\s+\\-|()])#u', $keywords, $exact_words);
$exact_words = $exact_words[1];
后面添加
代码: 全选
$exact_words = array_slice ($exact_words, 0, 3);
找到
代码: 全选
$pos = 0;
$len = strlen($text);
后面添加
代码: 全选
$single_utf8 = true;
找到
代码: 全选
{
$ret .= substr($text, $pos, $spn);
$pos += $spn;
后面添加
代码: 全选
$single_utf8 = true;
找到
代码: 全选
* We separate them with a space in order to index each character
* individually
*/
$ret .= ' ' . $utf_char . ' ';
将
代码: 全选
$ret .= ' ' . $utf_char . ' ';
替换为
代码: 全选
if ($pos < $len){
if ($spn = strspn($text, $legal_ascii, $pos)){
if ($single_utf8){
$ret .= ' ' . $utf_char . ' ';
}
continue;
} else {
$ret .= ' ' . $utf_char;
$utf_len = $utf_len_mask[$text[$pos] & "\xF0"];
$utf_char = substr($text, $pos, $utf_len);
if (($utf_char >= UTF8_HANGUL_FIRST && $utf_char <= UTF8_HANGUL_LAST)
|| ($utf_char >= UTF8_CJK_FIRST && $utf_char <= UTF8_CJK_LAST)
|| ($utf_char >= UTF8_CJK_B_FIRST && $utf_char <= UTF8_CJK_B_LAST))
{
$ret .= $utf_char . ' ';
}
}
} else {
if ($single_utf8){
$ret .= ' ' . $utf_char . ' ';
}
}
$single_utf8 = false;
然后
后台-> 维护->搜索索引-> Fulltext native 删除索引, 然后再创建索引