Algolia:在 Laravel 中搜索多个索引

编程入门 行业动态 更新时间:2024-10-26 22:24:48
本文介绍了Algolia:在 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 文档 状态:

// 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 AlgoliaSearchClient('APP_ID', 'APP_KEY');

更多推荐

Algolia:在 Laravel 中搜索多个索引

本文发布于:2023-11-28 19:50:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643733.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   索引   Algolia   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!