Skip to content

Add DIALECT option #37

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

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased v2.x]

### Added

- Add `DIALECT` option from RediSearch `2.4.3`

### Changed

- (dev) Update version and rules of PHP-CS-Fixer and PHPStan
Expand Down
2 changes: 1 addition & 1 deletion src/Redis/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
abstract class AbstractCommand implements Command
{
public const MAX_IMPLEMENTED_VERSION = '2.0.12';
public const MAX_IMPLEMENTED_VERSION = '2.4.3';
public const MIN_IMPLEMENTED_VERSION = '2.0.0';

/**
Expand Down
9 changes: 9 additions & 0 deletions src/Redis/Command/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use MacFJA\RediSearch\Redis\Command\AggregateCommand\SortByOption;
use MacFJA\RediSearch\Redis\Command\AggregateCommand\WithCursor;
use MacFJA\RediSearch\Redis\Command\Option\CommandOption;
use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption as CV;
use MacFJA\RediSearch\Redis\Command\Option\FlagOption;
use MacFJA\RediSearch\Redis\Command\Option\NamedOption;
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;
Expand Down Expand Up @@ -63,6 +64,7 @@ public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VE
'limit' => new LimitOption(),
'filter' => [],
'cursor' => new WithCursor(),
'dialect' => CV::isNumeric(new NamedOption('DIALECT', null, '>=2.4.3')),
], $rediSearchVersion);
}

Expand Down Expand Up @@ -156,6 +158,13 @@ public function setLoad(string ...$field): self
return $this;
}

public function setDialect(int $version): self
{
$this->options['dialect']->setValue($version);

return $this;
}

public function setWithCursor(?int $count = null, ?int $maxIdle = null): self
{
$this->options['cursor']
Expand Down
3 changes: 2 additions & 1 deletion src/Redis/Command/ConfigSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VE
'action' => new FlagOption('SET', true, '>=2.0.0'),
'options' => [
CustomValidatorOption::allowedValues(new NamelessOption(null, '>=2.0.0 <2.0.6'), ['NOGC', 'MAXEXPANSIONS', 'TIMEOUT', 'ON_TIMEOUT', 'MIN_PHONETIC_TERM_LEN']),
CustomValidatorOption::allowedValues(new NamelessOption(null, '>=2.0.6'), ['NOGC', 'MINPREFIX', 'MAXEXPANSIONS', 'MAXFILTEREXPANSION', 'TIMEOUT', 'ON_TIMEOUT', 'MIN_PHONETIC_TERM_LEN']),
CustomValidatorOption::allowedValues(new NamelessOption(null, '>=2.0.6 < 2.4.3'), ['NOGC', 'MINPREFIX', 'MAXEXPANSIONS', 'MAXFILTEREXPANSION', 'TIMEOUT', 'ON_TIMEOUT', 'MIN_PHONETIC_TERM_LEN']),
CustomValidatorOption::allowedValues(new NamelessOption(null, '>=2.4.3'), ['NOGC', 'MINPREFIX', 'MAXEXPANSIONS', 'TIMEOUT', 'ON_TIMEOUT', 'MIN_PHONETIC_TERM_LEN', 'DEFAULT_DIALECT']),
],
'value' => new NamelessOption(null, '>=2.0.0'),
], $rediSearchVersion);
Expand Down
10 changes: 10 additions & 0 deletions src/Redis/Command/Explain.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace MacFJA\RediSearch\Redis\Command;

use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption as CV;
use MacFJA\RediSearch\Redis\Command\Option\NamedOption;
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;

/**
Expand All @@ -33,6 +35,7 @@ public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VE
parent::__construct([
'index' => new NamelessOption(null, '>=2.0.0'),
'query' => new NamelessOption(null, '>=2.0.0'),
'dialect' => CV::isNumeric(new NamedOption('DIALECT', null, '>=2.4.3')),
], $rediSearchVersion);
}

Expand All @@ -50,6 +53,13 @@ public function setQuery(string $query): self
return $this;
}

public function setDialect(int $version): self
{
$this->options['dialect']->setValue($version);

return $this;
}

public function getId(): string
{
return 'FT.EXPLAIN';
Expand Down
8 changes: 8 additions & 0 deletions src/Redis/Command/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VE
'payload' => new NamedOption('PAYLOAD', null, '>=2.0.0'),
'sortby' => new SortByOption(),
'limit' => new LimitOption(),
'dialect' => CV::isNumeric(new NamedOption('DIALECT', null, '>=2.4.3')),
],
$rediSearchVersion
);
Expand Down Expand Up @@ -301,6 +302,13 @@ public function getSize(): ?int
return $limit->getSize();
}

public function setDialect(int $version): self
{
$this->options['dialect']->setValue($version);

return $this;
}

/**
* @param mixed $data
*
Expand Down
9 changes: 9 additions & 0 deletions src/Redis/Command/SpellCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use function is_array;
use MacFJA\RediSearch\Exception\UnexpectedServerResponseException;
use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption;
use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption as CV;
use MacFJA\RediSearch\Redis\Command\Option\NamedOption;
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;
use MacFJA\RediSearch\Redis\Command\SpellCheckCommand\TermsOption;
Expand All @@ -41,6 +42,7 @@ public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VE
new NamedOption('DISTANCE', null, '>=2.0.0'),
Validator::intVal()->between(1, 4)
),
'dialect' => CV::isNumeric(new NamedOption('DIALECT', null, '>=2.4.3')),
'terms' => [],
], $rediSearchVersion);
}
Expand All @@ -66,6 +68,13 @@ public function setDistance(int $distance): self
return $this;
}

public function setDialect(int $version): self
{
$this->options['dialect']->setValue($version);

return $this;
}

public function addTerms(string $dictionary, bool $isExcluding = false): self
{
$terms = new TermsOption();
Expand Down
4 changes: 3 additions & 1 deletion tests/Redis/Command/AggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function testSizeOptions(): void

public function testFullOption(): void
{
$command = new Aggregate();
$command = new Aggregate(Aggregate::MAX_IMPLEMENTED_VERSION);
$command
->setIndex('idx')
->setQuery('@text1:"hello world"')
Expand All @@ -137,6 +137,7 @@ public function testFullOption(): void
->setLimit(12, 35)
->addApply('@timestamp - (@timestamp % 86400)', 'day')
->setWithCursor(20, 30)
->setDialect(2)
;

static::assertSame([
Expand All @@ -150,6 +151,7 @@ public function testFullOption(): void
'LIMIT', 12, 35,
'FILTER', "@name=='foo' && @age < 20",
'WITHCURSOR', 'COUNT', 20, 'MAXIDLE', 30,
'DIALECT', 2,
], $command->getArguments());
}

Expand Down
7 changes: 6 additions & 1 deletion tests/Redis/Command/ExplainCliTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
* @covers \MacFJA\RediSearch\Redis\Command\ExplainCli
*
* @uses \MacFJA\RediSearch\Redis\Command\Option\AbstractCommandOption
* @uses \MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption
* @uses \MacFJA\RediSearch\Redis\Command\Option\DecoratedOptionTrait
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamedOption
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamelessOption
*
* @internal
Expand All @@ -45,15 +48,17 @@ public function testGetId(): void

public function testFullOption(): void
{
$command = new ExplainCli();
$command = new ExplainCli(ExplainCli::MAX_IMPLEMENTED_VERSION);
$command
->setIndex('idx')
->setQuery('@text1:"hello world"')
->setDialect(2)
;

static::assertSame([
'idx',
'@text1:"hello world"',
'DIALECT', 2,
], $command->getArguments());
}
}
7 changes: 6 additions & 1 deletion tests/Redis/Command/ExplainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
* @covers \MacFJA\RediSearch\Redis\Command\Explain
*
* @uses \MacFJA\RediSearch\Redis\Command\Option\AbstractCommandOption
* @uses \MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption
* @uses \MacFJA\RediSearch\Redis\Command\Option\DecoratedOptionTrait
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamedOption
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamelessOption
*
* @internal
Expand All @@ -44,15 +47,17 @@ public function testGetId(): void

public function testFullOption(): void
{
$command = new Explain();
$command = new Explain(Explain::MAX_IMPLEMENTED_VERSION);
$command
->setIndex('idx')
->setQuery('@text1:"hello world"')
->setDialect(2)
;

static::assertSame([
'idx',
'@text1:"hello world"',
'DIALECT', 2,
], $command->getArguments());
}
}
2 changes: 2 additions & 0 deletions tests/Redis/Command/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function testFullOption(): void
->setPayload('foobar')
->setSortBy('@num1', 'ASC')
->setLimit(12, 10)
->setDialect(2)
;

static::assertSame([
Expand All @@ -128,6 +129,7 @@ public function testFullOption(): void
'PAYLOAD', 'foobar',
'SORTBY', '@num1', 'ASC',
'LIMIT', 12, 10,
'DIALECT', 2,
], $command->getArguments());
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Redis/Command/SpellCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
**
* @uses \MacFJA\RediSearch\Redis\Command\Option\AbstractCommandOption
* @uses \MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption
* @uses \MacFJA\RediSearch\Redis\Command\Option\DecoratedOptionTrait
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamelessOption
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamedOption
*
Expand All @@ -51,19 +52,21 @@ public function testGetId(): void

public function testFullOption(): void
{
$command = new SpellCheck();
$command = new SpellCheck(SpellCheck::MAX_IMPLEMENTED_VERSION);
$command
->setIndex('idx')
->setQuery('@text1:"hello world"')
->setDistance(2)
->addTerms('badword', true)
->addTerms('cities', false)
->setDialect(2)
;

static::assertSame([
'idx',
'@text1:"hello world"',
'DISTANCE', 2,
'DIALECT', 2,
'TERMS', 'EXCLUDE', 'badword',
'TERMS', 'INCLUDE', 'cities',
], $command->getArguments());
Expand Down