@@ -57,6 +57,11 @@ class TypesenseEngine extends Engine
57
57
*/
58
58
private array $ locationOrderBy = [];
59
59
60
+ /**
61
+ * @var bool
62
+ */
63
+ private bool $ exhaustiveSearch = false ;
64
+
60
65
/**
61
66
* TypesenseEngine constructor.
62
67
*
@@ -148,6 +153,7 @@ private function buildSearchParams(Builder $builder, int $page, int | null $perP
148
153
'page ' => $ page ,
149
154
'highlight_start_tag ' => $ this ->startTag ,
150
155
'highlight_end_tag ' => $ this ->endTag ,
156
+ 'exhaustive_search ' => $ this ->exhaustiveSearch ,
151
157
];
152
158
153
159
if ($ this ->limitHits > 0 ) {
@@ -240,24 +246,34 @@ protected function performSearch(Builder $builder, array $options = []): mixed
240
246
*/
241
247
protected function filters (Builder $ builder ): string
242
248
{
243
- return collect ($ builder ->wheres )
244
- ->map ([
245
- $ this ,
246
- 'parseFilters ' ,
247
- ])
248
- ->values ()
249
- ->implode (' && ' );
249
+ $ whereFilter = collect ($ builder ->wheres )
250
+ ->map ([
251
+ $ this ,
252
+ 'parseWhereFilter ' ,
253
+ ])
254
+ ->values ()
255
+ ->implode (' && ' );
256
+
257
+ $ whereInFilter = collect ($ builder ->whereIns )
258
+ ->map ([
259
+ $ this ,
260
+ 'parseWhereInFilter ' ,
261
+ ])
262
+ ->values ()
263
+ ->implode (' && ' );
264
+
265
+ return $ whereFilter . ' && ' . $ whereInFilter ;
250
266
}
251
267
252
268
/**
253
- * Parse typesense filters .
269
+ * Parse typesense where filter .
254
270
*
255
271
* @param array|string $value
256
272
* @param string $key
257
273
*
258
274
* @return string
259
275
*/
260
- public function parseFilters (array |string $ value , string $ key ): string
276
+ public function parseWhereFilter (array |string $ value , string $ key ): string
261
277
{
262
278
if (is_array ($ value )) {
263
279
return sprintf ('%s:%s ' , $ key , implode ('' , $ value ));
@@ -266,6 +282,18 @@ public function parseFilters(array|string $value, string $key): string
266
282
return sprintf ('%s:=%s ' , $ key , $ value );
267
283
}
268
284
285
+ /**
286
+ * Parse typesense whereIn filter.
287
+ *
288
+ * @param array $value
289
+ * @param string $key
290
+ *
291
+ * @return string
292
+ */
293
+ public function parseWhereInFilter (array $ value , string $ key ): string
294
+ {
295
+ return sprintf ('%s:=%s ' , $ key , '[ ' . implode (', ' , $ value ).'] ' );
296
+ }
269
297
270
298
/**
271
299
* @param mixed $results
@@ -477,6 +505,20 @@ public function orderByLocation(string $column, float $lat, float $lng, string $
477
505
return $ this ;
478
506
}
479
507
508
+ /**
509
+ * Setting this to true will make Typesense consider all variations of prefixes and typo corrections of the words in the query exhaustively.
510
+ *
511
+ * @param bool $exhaustiveSearch
512
+ *
513
+ * @return $this
514
+ */
515
+ public function exhaustiveSearch (bool $ exhaustiveSearch ): static
516
+ {
517
+ $ this ->exhaustiveSearch = $ exhaustiveSearch ;
518
+
519
+ return $ this ;
520
+ }
521
+
480
522
/**
481
523
* @param string $name
482
524
*
0 commit comments