阿尔及利亚:在Laravel中搜索多个索引 [英] Algolia: searching multiple indices in Laravel
本文介绍了阿尔及利亚:在Laravel中搜索多个索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用类似这样的简单方法来建立algolia来搜索Laravel中的多个索引。
I would like to set up algolia to search multiple indices in Laravel, using something simple like this.
Route::get('/search/{query}', function ($query) {
$queries = [
[
'indexName' => 'movies_index',
'query' => $query,
'hitsPerPage' => 3
],
[
'indexName' => 'directors',
'query' => $query,
'hitsPerPage' => 3,
],
[
'indexName' => 'screenwriters',
'query' => $query,
'hitsPerPage' => 10
]
];
var_dump($queries);});
但是我也是laravel和algolia的初学者,所以我不确定如何
But I'm a beginner in laravel and algolia as well so I'm not entirely sure how to go on about it.
推荐答案
按照 Algolia Docs 状态:
// perform 3 queries in a single API call:
// - 1st query targets index `categories`
// - 2nd and 3rd queries target index `products`
$queries = [
[
'indexName' => 'categories',
'query' => $myQueryString,
'hitsPerPage' => 3
],
[
'indexName' => 'products',
'query' => $myQueryString,
'hitsPerPage' => 3,
'facetFilters' => 'promotion'
],
[
'indexName' => 'products',
'query' => $myQueryString,
'hitsPerPage' => 10
]
];
$results = $client->multipleQueries($queries);
var_dump($results['results']);
别忘了初始化 $ client
首先:
$client = new \AlgoliaSearch\Client('APP_ID', 'APP_KEY');
这篇关于阿尔及利亚:在Laravel中搜索多个索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文