本文介绍了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 中搜索多个索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 21:14