Skip to content

Commit

Permalink
[10.x] Fix Algolia 3/4 engines (#884)
Browse files Browse the repository at this point in the history
* Fix Algolia 3/4 engines

* Update src/Engines/Algolia4Engine.php

---------

Co-authored-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
dwightwatson and crynobone authored Nov 13, 2024
1 parent 53ad5c9 commit cfce53b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/Engines/Algolia3Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Algolia\AlgoliaSearch\Config\SearchConfig as Algolia3SearchConfig;
use Algolia\AlgoliaSearch\SearchClient as Algolia3SearchClient;
use Illuminate\Support\Arr;
use Laravel\Scout\Builder;
use Laravel\Scout\Jobs\RemoveableScoutCollection;

Expand Down Expand Up @@ -34,24 +35,23 @@ public function __construct(Algolia3SearchClient $algolia, $softDelete = false)
*/
public static function make(array $config, array $headers, bool $softDelete = false)
{
$config = Algolia3SearchConfig::create([
'appId' => $config['id'],
'apiKey' => $config['secret'],
])->setDefaultHeaders($headers);
$configuration = Algolia3SearchConfig::create(
$config['id'], $config['secret'],
)->setDefaultHeaders($headers);

if (is_int($connectTimeout = $config['connect_timeout'])) {
if (is_int($connectTimeout = Arr::get($config, 'connect_timeout'))) {
$configuration->setConnectTimeout($connectTimeout);
}

if (is_int($readTimeout = $config['read_timeout'])) {
if (is_int($readTimeout = Arr::get($config, 'read_timeout'))) {
$configuration->setReadTimeout($readTimeout);
}

if (is_int($writeTimeout = $config['write_timeout'])) {
if (is_int($writeTimeout = Arr::get($config, 'write_timeout'))) {
$configuration->setWriteTimeout($writeTimeout);
}

if (is_int($batchSize = $config['batch_size'])) {
if (is_int($batchSize = Arr::get($config, 'batch_size'))) {
$configuration->setBatchSize($batchSize);
}

Expand Down
9 changes: 5 additions & 4 deletions src/Engines/Algolia4Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Algolia\AlgoliaSearch\Api\SearchClient as Algolia4SearchClient;
use Algolia\AlgoliaSearch\Configuration\SearchConfig as Algolia4SearchConfig;
use Illuminate\Support\Arr;
use Laravel\Scout\Builder;
use Laravel\Scout\Jobs\RemoveableScoutCollection;

Expand Down Expand Up @@ -38,18 +39,18 @@ public static function make(array $config, array $headers, bool $softDelete = fa
'appId' => $config['id'],
'apiKey' => $config['secret'],
]), array_filter([
'batchSize' => $config['batch_size'],
'batchSize' => transform(Arr::get($config, 'batch_size'), fn ($batchSize) => is_int($batchSize) ? $batchSize : null),
])))->setDefaultHeaders($headers);

if (is_int($connectTimeout = $config['connect_timeout'])) {
if (is_int($connectTimeout = Arr::get($config, 'connect_timeout'))) {
$configuration->setConnectTimeout($connectTimeout);
}

if (is_int($readTimeout = $config['read_timeout'])) {
if (is_int($readTimeout = Arr::get($config, 'read_timeout'))) {
$configuration->setReadTimeout($readTimeout);
}

if (is_int($writeTimeout = $config['write_timeout'])) {
if (is_int($writeTimeout = Arr::get($config, 'write_timeout'))) {
$configuration->setWriteTimeout($writeTimeout);
}

Expand Down

0 comments on commit cfce53b

Please sign in to comment.