有個(gè)違禁詞庫的需求,也可以做關(guān)鍵詞提取,我們的搜索的詞庫用的是httpcws 張宴先生的,他的詞庫封裝進(jìn)去了 不能編譯,scws支持自定義詞庫 很好用。
cd /Data/tgz/
wgethttp://www.xunsearch.com/scws/down/scws-1.2.2.tar.bz2
tar xvjf scws-1.2.2.tar.bz2
cd scws-1.2.2
./configure --prefix=/Data/apps/scws
make
make install
cd phpext/
ls
/Data/apps/php/bin/phpize
./configure --with-scws=/Data/apps/scws/ --with-php-config=/Data/apps/php/bin/php-config
make
make install
vi /Data/apps/php/etc/php.ini
添加
extension =scws.so
scws.default.charset = utf8
scws.default.fpath = /Data/apps/scws/etc
保存退出
killall php-fpm
/Data/apps/php/sbin/php-fpm
詞庫起名為lianchuang.txt
放到/Data/apps/scws/etc下
格式
麻痹性斜視? ? 1.0? ? 1.0? ? @
麻痹性癡呆? ? 1.0? ? 1.0? ? @
麻痹性腸梗阻? ? 1.0? ? 1.0? ? @
麻痹性臂叢神經(jīng)炎? ? 1.0? ? 1.0? ? @
麻醉? ? 1.0? ? 1.0? ? @
麻風(fēng)??? 1.0??? 1.0??? @
用法
$content=$this->getRequest()->getQuery('content','');
$scws= scws_new();
$scws->set_charset('utf8');
// 這里沒有調(diào)用 set_dict 和 set_rule 系統(tǒng)會(huì)自動(dòng)試調(diào)用 ini 中指定路徑下的詞典和規(guī)則文件
$scws->send_text($content);
$scws->add_dict(ini_get("scws.default.fpath")."/lianchuang.txt",SCWS_XDICT_TXT);
$scws->set_ignore(false);
//是否復(fù)式分割,如“中國人”返回“中國+人+中國人”三個(gè)詞。
$scws->set_multi(false);
//設(shè)定將文字自動(dòng)以二字分詞法聚合
$scws->set_duality(true);
$result=$scws->get_words('@');
if(is_array($result) &&count($result) >0) {
$words= [];
foreach($resultas$key=>$value) {
$words[] =$value['word'];
}
var_dump($words);
}
$scws->close();