环境tp5.0 在类头部引入相关文件
use think\Db;
use plugins\pscws4;
文件在项目跟目录下的 extend\plugins 文件夹中 pscws4.php 和 xdb_r.class.php
在public 下创建文件夹scws 包含 dict.utf8.xdb rules.ini rules.utf8.ini 三个文件
public function addtwords(){
if (request()->isPost()){
$site_id = cookie('site_id');
$param = input('post.');
$str = '';
$pscws = new pscws4();
$pscws->set_dict('scws/dict.utf8.xdb');
$pscws->set_rule('scws/rules.utf8.ini');
$pscws->set_ignore(true);
$pscws->send_text($param['question']);
$words = $pscws->get_tops(20);
foreach ($words as $key => $value) {
$str .= base64_encode($value['word']).'-';
// $str .= $value['word'].'-';
}
$pscws->close();
$data['site_id'] = $param['site_id'];
$data['question'] = $param['question'];
$data['answer'] = $param['answer'];
$data['guide_id'] = $param['quiz2'];
$data['guidetype_id'] = $param['quiz1'];
$data['add_time'] = date("Y-m-d H:i:s",time());
$data['tag'] = $str;
$res = GuideModel::addtwords_model($data);
return $res;
}
return $this->fetch();
}
//分词存储的的表 必须是myisam 引擎,支持全文索引,这样才能匹配到
// 查询sql 如下
$data = base64_encode($param['data']);
$site_id = ’xxxxxxxxx‘;
$sql = "select id,question,answer from table_words where site_id=$site_id and status = 1 and match(tag) against('" . $data . "' in boolean mode) limit 5";
$res = db('table_words ')->query($sql);
需要本例相关资源可以私信我。