QQ扫一扫联系
「搜索中心」是一个提供全站通用的内容搜索中心
第一步、实现并注册搜索中心业务
use \Module\SearchCenter\Biz\SearchCenterBiz;
use \Module\SearchCenter\Biz\AbstractSearchCenterBiz;
// 实现搜索中心业务
class XxxSearchCenterBiz extends AbstractSearchCenterBiz
{
const NAME = 'xxx';
public function name()
{
return self::NAME;
}
public function title()
{
return '测试接入搜索中心';
}
public function syncBatch($nextId)
{
$batch = ModelUtil::batch('xxx', $nextId, 10);
$batch['records'] = array_map(function ($o) {
return [
'biz' => self::NAME,
'bizId' => $o['id'],
'url' => modstart_web_url('xxx/' . $o['id']),
'title' => $o['title'],
'content' => $o['content'],
'keywords' => [],
];
}, $batch['records']);
return $batch;
}
}
// 注册搜索中心业务
SearchCenterBiz::register(XxxSearchCenterBiz::class);
第二步、在业务逻辑代码中主动同步内容
use \Module\SearchCenter\Biz\SearchCenterBiz;
// 增加/更新内容
SearchCenterBiz::update('xxx',1,'/xxx/1','标题','内容',['关键词','关键词']);
// 删除内容
SearchCenterBiz::delete('xxx',1);