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; |
15
|
|
|
|
16
|
|
|
use Closure; |
17
|
|
|
use Laravel\Scout\Builder; |
18
|
|
|
use function call_user_func; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @internal |
22
|
|
|
*/ |
23
|
|
|
final class BuilderMacros |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @return \Closure |
27
|
|
|
*/ |
28
|
18 |
|
public function count(): Closure |
29
|
|
|
{ |
30
|
|
|
/* |
31
|
|
|
* Count the number of items in the search results. |
32
|
|
|
* |
33
|
|
|
* @return int |
34
|
|
|
*/ |
35
|
|
|
return function (): int { |
36
|
|
|
$raw = $this->engine()->search($this); |
|
|
|
|
37
|
|
|
|
38
|
|
|
return array_key_exists('nbHits', $raw) ? (int) $raw['nbHits'] : 0; |
39
|
18 |
|
}; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return \Closure |
44
|
|
|
*/ |
45
|
18 |
|
public function aroundLatLng(): Closure |
46
|
|
|
{ |
47
|
|
|
/* |
48
|
|
|
* Search for entries around a given location. |
49
|
|
|
* |
50
|
|
|
* @link https://www.algolia.com/doc/guides/geo-search/geo-search-overview/ |
51
|
|
|
* |
52
|
|
|
* @param float $lat Latitude of the center |
53
|
|
|
* @param float $lng Longitude of the center |
54
|
|
|
* |
55
|
|
|
* @return \Laravel\Scout\Builder |
56
|
|
|
*/ |
57
|
|
|
return function (float $lat, float $lng): Builder { |
58
|
|
|
$callback = $this->callback; |
59
|
|
|
$this->callback = function ($algolia, $query, $options) use ($lat, $lng, $callback) { |
|
|
|
|
60
|
|
|
$options['aroundLatLng'] = (float) $lat.','.(float) $lng; |
61
|
|
|
if ($callback) { |
62
|
|
|
return call_user_func($callback, $algolia, $query, $options); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $algolia->search($query, $options); |
66
|
|
|
}; |
67
|
|
|
|
68
|
|
|
return $this; |
|
|
|
|
69
|
18 |
|
}; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return \Closure |
74
|
|
|
*/ |
75
|
18 |
|
public function with(): Closure |
76
|
|
|
{ |
77
|
|
|
/* |
78
|
|
|
* Customize the request with the provided options |
79
|
|
|
* |
80
|
|
|
* @param array $options Latitude of the center |
81
|
|
|
* |
82
|
|
|
* @return \Laravel\Scout\Builder |
83
|
|
|
*/ |
84
|
|
|
return function (array $options): Builder { |
85
|
|
|
$callback = $this->callback; |
86
|
|
|
|
87
|
|
|
$this->callback = function ($algolia, $query, $baseOptions) use ($options, $callback) { |
|
|
|
|
88
|
|
|
$options = array_merge($options, $baseOptions); |
89
|
|
|
|
90
|
|
|
if ($callback) { |
91
|
|
|
return call_user_func($callback, $algolia, $query, $options); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $algolia->search($query, $options); |
95
|
|
|
}; |
96
|
|
|
|
97
|
|
|
return $this; |
|
|
|
|
98
|
18 |
|
}; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.