Algolia PHP Laravel Scout : How do I search in multiple indices in single API call?

How can I search in multiple indices in single API call ?

currently we can search in single index vai Laravel Model level search method or create query search call in Algolia PHP client.

I have found following for Laravel but it requires Laravel 5.6 and I am using Laravel 5.4 :

this allows to search in multiple indices using Aggregator Model but lacks individual index/model pagination.

I have also found another Algolia PHP client example as mentioned here :

Algolia: searching multiple indices in Laravel

But how do I access Algolia client in Laravel Scout to perform above multipleQueries() function, create queries and paginiation with individual index ?

I have been using Algolia’s javascript client in AngularJs:

to search and show hits directly from Algolia server to Angular in browser for multiple indices but since I upgraded to Angular 6 and Alglia’s current libraries/widgets doesn’t support multiple indices search I am switching Algolia search service to backend webservice/API which is running on Laravel where I have been already using Laravel Scout to submit Model data save to Aloglia index as searchable.

Hi @manish.pithwa,

Sorry for the late response, but I have tried to contact you using the Laravel Discord.

Using Laravel Scout you can’t run multiple queries in the same API call.

You may want to take a look at {https://github.com/algolia/algoliasearch-client-php/tree/1.x#multiple-queries}. Using Algolia PHP v1, you can do multiple queries in the same API call.

Example:

// perform 3 queries in a single API call:
//  - 1st query targets index `categories`
//  - 2nd and 3rd queries target index `products`

$client = new \AlgoliaSearch\Client('YourApplicationID', 'YourAdminAPIKey');

$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']);

Tell me if this works for you.