PHP 同步写入迅搜(xunsearch)索引、更新索引和删除索引
1、同步写入迅搜索引
// 引入迅搜文件
use XS;
use XSDocument;
// 实例化迅搜
$xs = new XS('news');
$index = $xs->index;
// 整理迅搜索引所需文章信息
$data = [
'id' => $data['id'],
'title' => $data['title'],
'keywords' => $data['keywords'],
'description' => $data['description']
];
// 创建文档对象,默认字符集utf-8
$doc = new XSDocument;
$doc->setFields($data);
// 添加到索引数据库中
$index->add($doc);2、更新迅搜索引
// 引入迅搜文件
use XS;
use XSDocument;
// 实例化迅搜
$xs = new XS('news');
$index = $xs->index;
// 整理迅搜索引所需文章信息
$data = [
'id' => $data['id'],
'title' => $data['title'],
'keywords' => $data['keywords'],
'description' => $data['description']
];
// 创建文档对象,默认字符集utf-8
$doc = new XSDocument;
$doc->setFields($data);
// 更新到索引数据库中
$index->update($doc);3、删除迅搜索引
// 实例化迅搜
$xs = new XS('news');
$index = $xs->index;
// 删除索引操作,$id为项目主键id
$index->del($id);本文为原创文章,转载无需和我联系,但请注明来自:http://www.baiyongj.com/news/486.html