开发的程序需要通过搜索出所需要的信息,因用户搜索的关键字过于模糊,所以采用分词进行搜索。
cd /usr/local/src
wget .2.3.tar.bz2
tar xvjf scws-1.2.3.tar.bz2
cd scws-1.2.3
./configure --prefix=/usr/local/scws
make && make install
/usr/local/scws/bin/scws -h
cd /usr/local/scws/etc
wget .tar.bz2
wget .tar.bz2
tar xvjf scws-dict-chs-gbk.tar.bz2
tar xvjf scws-dict-chs-utf8.tar.bz2
注意:/www/server/php/73/bin/ 要看清楚自己PHP安装的目录
cd ./scws-1.2.3 /phpext/
locate phpize
/www/server/php/73/bin/phpize
./configure --with-php-config=/www/server/php/73/bin/php-config --with-scws=/usr/local/scws
make && make install
注意:需要重启服务器php.ini才会生效,成功后在phpinfo中可以查询到scws
extension = scws.so
scws.default.charset = utf8
scws.default.fpath = /usr/local/scws/etc
<?php$scws = scws_open();scws_set_charset($scws, 'utf-8');scws_set_dict($scws, '/usr/local/scws/etc/dict.utf8.xdb');scws_set_rule($scws, '/usr/local/scws/etc/rules.utf8.ini');$text = "我爱写代码";scws_send_text($scws, $text);$tops = scws_get_tops($scws, 5);print_r($tops);
?>
// 输出结果
//Array
//(
//[0] => Array
//(
//[word] => 代码
//[times] => 1
//[weight] => 4.8200001716614
//[attr] => n
//)
//
//[1] => Array
//(
//[word] => 我爱
//[times] => 1
//[weight] => 4.5900001525879
//[attr] => n
//)
//
//)
本人在测试过程中出现了:open_basedir restriction in effect. File(/usr/local/scws/etc/dict.utf8.xdb) is not within the allowed path(s) 这个错误提示。由于我是宝塔面板安装的,只需要在相应的网站目录,勾选掉防跨站攻击(open_basedir)即可。
本文发布于:2024-02-02 13:07:27,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170685044844004.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |