Skip to content

Commit 9033f69

Browse files
Merge pull request #74 from aou24/infix-parameter
Add infix parameter
2 parents 2655ac3 + 5e62727 commit 9033f69

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/Engines/TypesenseEngine.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ class TypesenseEngine extends Engine
107107
*/
108108
private string $facetQuery = '';
109109

110+
/**
111+
* @var string
112+
*/
113+
private string $infix = 'off';
114+
110115
/**
111116
* @var array
112117
*/
@@ -233,14 +238,6 @@ public function paginate(Builder $builder, $perPage, $page): mixed
233238
private function buildSearchParams(Builder $builder, int $page, int|null $perPage): array
234239
{
235240
$params = [
236-
'q' => $builder->query,
237-
'query_by' => implode(',', $builder->model->typesenseQueryBy()),
238-
'filter_by' => $this->filters($builder),
239-
'per_page' => $perPage,
240-
'page' => $page,
241-
'highlight_start_tag' => $this->startTag,
242-
'highlight_end_tag' => $this->endTag,
243-
'exhaustive_search' => $this->exhaustiveSearch,
244241
'q' => $builder->query,
245242
'query_by' => implode(',', $builder->model->typesenseQueryBy()),
246243
'filter_by' => $this->filters($builder),
@@ -255,6 +252,7 @@ private function buildSearchParams(Builder $builder, int $page, int|null $perPag
255252
'prioritize_exact_match' => $this->prioritizeExactMatch,
256253
'enable_overrides' => $this->enableOverrides,
257254
'highlight_affix_num_tokens' => $this->highlightAffixNumTokens,
255+
'infix' => $this->infix,
258256
];
259257

260258
if ($this->limitHits > 0) {
@@ -787,6 +785,21 @@ public function setHighlightAffixNumTokens(int $highlightAffixNumTokens): static
787785
return $this;
788786
}
789787

788+
/**
789+
* Set the infix search option for the field.
790+
*
791+
* @param string $infix The infix search option to enable for the field.
792+
* Possible values: "off" (disabled, default), "always" (along with regular search),
793+
* "fallback" (if regular search produces no results).
794+
* @return $this
795+
*/
796+
public function setInfix(string $infix): static
797+
{
798+
$this->infix = $infix;
799+
800+
return $this;
801+
}
802+
790803
/**
791804
* Field values under this length will be fully highlighted, instead of showing a snippet of relevant portion.
792805
*

src/Mixin/BuilderMixin.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,21 @@ public function setHighlightAffixNumTokens(): Closure
271271
};
272272
}
273273

274+
/**
275+
* @param string $infix
276+
*
277+
* @return \Closure
278+
*/
279+
public function setInfix(): Closure
280+
{
281+
return function (string $infix) {
282+
$this->engine()
283+
->setInfix($infix);
284+
285+
return $this;
286+
};
287+
}
288+
274289
/**
275290
* @param int $snippetThreshold
276291
*

0 commit comments

Comments
 (0)