@@ -142,6 +142,11 @@ class TypesenseEngine extends Engine
142
142
*/
143
143
private array $ optionsMulti = [];
144
144
145
+ /**
146
+ * @var string|null
147
+ */
148
+ private ?string $ prefix ;
149
+
145
150
/**
146
151
* TypesenseEngine constructor.
147
152
*
@@ -306,6 +311,10 @@ private function buildSearchParams(Builder $builder, int $page, int|null $perPag
306
311
}
307
312
$ params ['sort_by ' ] .= $ this ->parseOrderBy ($ builder ->orders );
308
313
}
314
+
315
+ if (!empty ($ this ->prefix )) {
316
+ $ params ['prefix ' ] = $ this ->prefix ;
317
+ }
309
318
310
319
return $ params ;
311
320
}
@@ -403,7 +412,7 @@ protected function filters(Builder $builder): string
403
412
404
413
return $ whereFilter . (
405
414
($ whereFilter !== '' && $ whereInFilter !== '' ) ? ' && ' : ''
406
- ) . $ whereInFilter ;
415
+ ) . $ whereInFilter ;
407
416
}
408
417
409
418
/**
@@ -850,6 +859,25 @@ public function setPrioritizeExactMatch(bool $prioritizeExactMatch): static
850
859
return $ this ;
851
860
}
852
861
862
+ /**
863
+ * Indicates that the last word in the query should be treated as a prefix, and not as a whole word.
864
+ *
865
+ * You can also control the behavior of prefix search on a per field basis.
866
+ * For example, if you are querying 3 fields and want to enable prefix searching only on the first field, use ?prefix=true,false,false.
867
+ * The order should match the order of fields in query_by.
868
+ * If a single value is specified for prefix the same value is used for all fields specified in query_by.
869
+ *
870
+ * @param string $prefix
871
+ *
872
+ * @return $this
873
+ */
874
+ public function setPrefix (string $ prefix ): static
875
+ {
876
+ $ this ->prefix = $ prefix ;
877
+
878
+ return $ this ;
879
+ }
880
+
853
881
/**
854
882
* If you have some overrides defined but want to disable all of them for a particular search query
855
883
*
0 commit comments