Laravel 使用 Elasticsearch 进行全文搜索怎样加上 where 条件啊?
比如实现下面这样类似的需求
public function search()
{
$this->validate(request(), [
'query' => 'required'
]);
$query = request(['query']);
$posts = App\Posts::search($query)->paginate(2);
return view('post.search', compact('posts'));
}
如果写成这样
$posts = App\Posts::search($query)->paginate(2);
是可以有搜索结果的,
但如果像是这样加上where条件
$posts = App\Posts::search($query)->where('type','1')->paginate(2);
搜索结果却为空是为什么
官方文档里面有提到可以这样写:
但是我这样却没有搜索结果
所以意思是我必须使用Scout 自带一个 Algolia 驱动才可以吗?
关于 LearnKu
可能跟你的 es 字段映射有关系
$params = [
'index' => 'products',
'type' => '_doc',
'id' => 1
];
app('es')->get($params);
供你参考
:sm