22
33namespace Meilisearch \Scout \Engines ;
44
5+ use Laravel \Scout \Builder ;
56use Laravel \Scout \Engines \Engine ;
67use MeiliSearch \Client as Meilisearch ;
78
89class MeilisearchEngine extends Engine
910{
10- protected Meilisearch $ meilisearch ;
11- protected bool $ softDelete ;
11+ /**
12+ * The Meilisearch client.
13+ *
14+ * @var Meilisearch
15+ */
16+ protected $ meilisearch ;
17+
18+ /**
19+ * Determines if soft deletes for Scout are enabled or not.
20+ *
21+ * @var bool
22+ */
23+ protected $ softDelete ;
1224
1325 public function __construct (Meilisearch $ meilisearch , bool $ softDelete = false )
1426 {
@@ -20,6 +32,7 @@ public function __construct(Meilisearch $meilisearch, bool $softDelete = false)
2032 * Update the given model in the index.
2133 *
2234 * @param \Illuminate\Database\Eloquent\Collection $models
35+ *
2336 * @return void
2437 */
2538 public function update ($ models )
@@ -42,7 +55,7 @@ public function update($models)
4255 return array_merge ($ searchableData , $ model ->scoutMetadata ());
4356 })->filter ()->values ()->all ();
4457
45- if (!empty ($ objects )) {
58+ if (! empty ($ objects )) {
4659 $ index ->addDocuments ($ objects , $ models ->first ()->getKeyName ());
4760 }
4861 }
@@ -51,14 +64,15 @@ public function update($models)
5164 * Remove the given model from the index.
5265 *
5366 * @param \Illuminate\Database\Eloquent\Collection $models
67+ *
5468 * @return void
5569 */
5670 public function delete ($ models )
5771 {
5872 $ index = $ this ->meilisearch ->getIndex ($ models ->first ()->searchableAs ());
5973
6074 $ index ->deleteDocuments (
61- $ models ->map ( fn ( $ model ) => $ model ->getScoutKey () )
75+ $ models ->map ->getScoutKey ()
6276 ->values ()
6377 ->all ()
6478 );
@@ -67,25 +81,27 @@ public function delete($models)
6781 /**
6882 * Perform the given search on the engine.
6983 *
70- * @param \Laravel\Scout\Builder $builder
84+ * @param Builder $builder
85+ *
7186 * @return mixed
7287 */
73- public function search (\ Laravel \ Scout \ Builder $ builder )
88+ public function search (Builder $ builder )
7489 {
7590 return $ this ->performSearch ($ builder , array_filter ([
76- 'limit ' => $ builder ->limit
91+ 'limit ' => $ builder ->limit ,
7792 ]));
7893 }
7994
8095 /**
8196 * Perform the given search on the engine.
8297 *
83- * @param \Laravel\Scout\ Builder $builder
98+ * @param Builder $builder
8499 * @param int $perPage
85100 * @param int $page
101+ *
86102 * @return mixed
87103 */
88- public function paginate (\ Laravel \ Scout \ Builder $ builder , $ perPage , $ page )
104+ public function paginate (Builder $ builder , $ perPage , $ page )
89105 {
90106 return $ this ->performSearch ($ builder , array_filter ([
91107 'limit ' => $ perPage ,
@@ -95,11 +111,12 @@ public function paginate(\Laravel\Scout\Builder $builder, $perPage, $page)
95111 /**
96112 * Perform the given search on the engine.
97113 *
98- * @param \Laravel\Scout\ Builder $builder
114+ * @param Builder $builder
99115 * @param array $options
116+ *
100117 * @return mixed
101118 */
102- protected function performSearch (\ Laravel \ Scout \ Builder $ builder , array $ options = [])
119+ protected function performSearch (Builder $ builder , array $ options = [])
103120 {
104121 $ meilisearch = $ this ->meilisearch ->getIndex ($ builder ->index ?: $ builder ->model ->searchableAs ());
105122
@@ -119,6 +136,7 @@ protected function performSearch(\Laravel\Scout\Builder $builder, array $options
119136 * Pluck and return the primary keys of the given results.
120137 *
121138 * @param mixed $results
139+ *
122140 * @return \Illuminate\Support\Collection
123141 */
124142 public function mapIds ($ results )
@@ -132,12 +150,13 @@ public function mapIds($results)
132150 /**
133151 * Map the given results to instances of the given model.
134152 *
135- * @param \Laravel\Scout\ Builder $builder
153+ * @param Builder $builder
136154 * @param mixed $results
137155 * @param \Illuminate\Database\Eloquent\Model $model
156+ *
138157 * @return \Illuminate\Database\Eloquent\Collection
139158 */
140- public function map (\ Laravel \ Scout \ Builder $ builder , $ results , $ model )
159+ public function map (Builder $ builder , $ results , $ model )
141160 {
142161 if (is_null ($ results ) || count ($ results ['hits ' ]) === 0 ) {
143162 return $ model ->newCollection ();
@@ -159,6 +178,7 @@ public function map(\Laravel\Scout\Builder $builder, $results, $model)
159178 * Get the total count from a raw result returned by the engine.
160179 *
161180 * @param mixed $results
181+ *
162182 * @return int
163183 */
164184 public function getTotalCount ($ results )
@@ -170,6 +190,7 @@ public function getTotalCount($results)
170190 * Flush all of the model's records from the engine.
171191 *
172192 * @param \Illuminate\Database\Eloquent\Model $model
193+ *
173194 * @return void
174195 */
175196 public function flush ($ model )
@@ -183,6 +204,7 @@ public function flush($model)
183204 * Determine if the given model uses soft deletes.
184205 *
185206 * @param \Illuminate\Database\Eloquent\Model $model
207+ *
186208 * @return bool
187209 */
188210 protected function usesSoftDelete ($ model )
@@ -195,6 +217,7 @@ protected function usesSoftDelete($model)
195217 *
196218 * @param string $method
197219 * @param array $parameters
220+ *
198221 * @return mixed
199222 */
200223 public function __call ($ method , $ parameters )
0 commit comments