Skip to content

Commit f805aff

Browse files
committed
Added slop functionality
1 parent e3e66ca commit f805aff

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Search.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class Search implements Builder, Pipeable
109109
/** @var null|Highlight */
110110
private $highlight;
111111

112-
//slop
112+
/** @var int */
113+
private $slop = 0;
113114

114115
/** @var bool */
115116
private $inOrder = false;
@@ -164,6 +165,7 @@ public function reset(): Builder
164165
$this->returns = [];
165166
$this->summarize = null;
166167
$this->highlight = null;
168+
$this->slop = 0;
167169
$this->inOrder = false;
168170
$this->language = null;
169171
$this->expander = null;
@@ -318,6 +320,14 @@ public function withHighlight(array $fields = [], ?string $openTag = null, ?stri
318320
return $this;
319321
}
320322

323+
public function withSlop(int $slop = 0): Search
324+
{
325+
$this->slop = $slop;
326+
327+
return $this;
328+
}
329+
330+
321331
public function withInOrder(bool $inOrder = true): Search
322332
{
323333
$this->inOrder = $inOrder;
@@ -506,6 +516,10 @@ private function buildQuery(): array
506516
$query = RedisHelper::buildQueryPartial($query,
507517
array_merge($this->filters, [$this->geoFilter, $this->summarize, $this->highlight])
508518
);
519+
if (is_int($this->slop)) {
520+
$query[] = 'SLOP';
521+
$query[] = $this->slop;
522+
}
509523
if (is_string($this->sortBy)) {
510524
$query[] = 'SORTBY';
511525
$query[] = $this->sortBy;

0 commit comments

Comments
 (0)