|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* This file is part of Scout Extended. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Algolia Team <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Algolia\ScoutExtended\Engines; |
|
15
|
|
|
|
|
16
|
|
|
use Laravel\Scout\Builder; |
|
17
|
|
|
use Algolia\AlgoliaSearch\Client; |
|
18
|
|
|
use Algolia\ScoutExtended\Jobs\DeleteJob; |
|
19
|
|
|
use Algolia\ScoutExtended\Jobs\UpdateJob; |
|
20
|
|
|
use Illuminate\Database\Eloquent\Collection; |
|
21
|
|
|
use Algolia\ScoutExtended\Searchable\ModelsResolver; |
|
22
|
|
|
use Laravel\Scout\Engines\AlgoliaEngine as BaseAlgoliaEngine; |
|
23
|
|
|
|
|
24
|
|
|
class AlgoliaEngine extends BaseAlgoliaEngine |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @param \Algolia\AlgoliaSearch\Client $algolia |
|
28
|
|
|
*/ |
|
29
|
20 |
|
public function setClient(Client $algolia): void |
|
30
|
|
|
{ |
|
31
|
20 |
|
$this->algolia = $algolia; |
|
|
|
|
|
|
32
|
20 |
|
} |
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
12 |
|
public function update($searchables) |
|
37
|
|
|
{ |
|
38
|
12 |
|
dispatch_now(new UpdateJob($searchables)); |
|
39
|
12 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
5 |
|
public function delete($searchables) |
|
45
|
|
|
{ |
|
46
|
5 |
|
dispatch_now(new DeleteJob($searchables)); |
|
47
|
5 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
4 |
|
public function map(Builder $builder, $results, $searchable) |
|
53
|
|
|
{ |
|
54
|
4 |
|
if (count($results['hits']) === 0) { |
|
55
|
2 |
|
return Collection::make(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
2 |
|
$ids = collect($results['hits'])->pluck('objectID')->values()->all(); |
|
59
|
|
|
|
|
60
|
2 |
|
return resolve(ModelsResolver::class)->from($builder, $searchable, $ids); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..