Skip to content

Added slop functionality #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Implementation of SLOP parameter

## [1.3.0]

### Added
Expand Down
16 changes: 15 additions & 1 deletion src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class Search implements Builder, Pipeable
/** @var null|Highlight */
private $highlight;

//slop
/** @var null|int */
private $slop = null;

/** @var bool */
private $inOrder = false;
Expand Down Expand Up @@ -164,6 +165,7 @@ public function reset(): Builder
$this->returns = [];
$this->summarize = null;
$this->highlight = null;
$this->slop = null;
$this->inOrder = false;
$this->language = null;
$this->expander = null;
Expand Down Expand Up @@ -318,6 +320,14 @@ public function withHighlight(array $fields = [], ?string $openTag = null, ?stri
return $this;
}

public function withSlop(int $slop = 0): Search
{
$this->slop = $slop;

return $this;
}


public function withInOrder(bool $inOrder = true): Search
{
$this->inOrder = $inOrder;
Expand Down Expand Up @@ -506,6 +516,10 @@ private function buildQuery(): array
$query = RedisHelper::buildQueryPartial($query,
array_merge($this->filters, [$this->geoFilter, $this->summarize, $this->highlight])
);
if (is_int($this->slop)) {
$query[] = 'SLOP';
$query[] = $this->slop;
}
if (is_string($this->sortBy)) {
$query[] = 'SORTBY';
$query[] = $this->sortBy;
Expand Down