Skip to content

Commit 5bed266

Browse files
committed
RediSearch 2.4.3 compatibility
1 parent 79621c0 commit 5bed266

12 files changed

+61
-6
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- `LOAD ALL` option on Aggregate command (RediSearch `2.0.13`)
1616
- Profile command (RediSearch `2.2.0`) ([Issue#4])
1717
- Vector feature (RediSearch `2.4.0` / `2.4.2`)
18+
- Add `DIALECT` option (RediSearch `2.4.3`) ([Issue#35])
1819

1920
### Fixed
2021

@@ -228,6 +229,7 @@ First version
228229
[Issue#12]: https://github.com/MacFJA/php-redisearch/issues/12
229230
[Issue#16]: https://github.com/MacFJA/php-redisearch/issues/16
230231
[Issue#26]: https://github.com/MacFJA/php-redisearch/issues/26
232+
[Issue#35]: https://github.com/MacFJA/php-redisearch/issues/35
231233
[Issue#38]: https://github.com/MacFJA/php-redisearch/issues/38
232234
[Issue#39]: https://github.com/MacFJA/php-redisearch/issues/39
233235
[PR#1]: https://github.com/MacFJA/php-redisearch/pull/1

Diff for: src/Redis/Command/AbstractCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
abstract class AbstractCommand implements Command
3434
{
35-
public const MAX_IMPLEMENTED_VERSION = '2.4.0';
35+
public const MAX_IMPLEMENTED_VERSION = '2.4.3';
3636
public const MIN_IMPLEMENTED_VERSION = '2.0.0';
3737

3838
/**

Diff for: src/Redis/Command/Aggregate.php

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VE
6565
'limit' => new LimitOption(),
6666
'filter' => [],
6767
'cursor' => new WithCursor(),
68+
'dialect' => CV::isNumeric(new NamedOption('DIALECT', null, '>=2.4.3')),
6869
], $rediSearchVersion);
6970
}
7071

@@ -167,6 +168,13 @@ public function setLoadAll(): self
167168
return $this;
168169
}
169170

171+
public function setDialect(int $version): self
172+
{
173+
$this->options['dialect']->setValue($version);
174+
175+
return $this;
176+
}
177+
170178
public function setWithCursor(?int $count = null, ?int $maxIdle = null): self
171179
{
172180
$this->options['cursor']

Diff for: src/Redis/Command/ConfigSet.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VE
3333
'action' => new FlagOption('SET', true, '>=2.0.0'),
3434
'options' => [
3535
CustomValidatorOption::allowedValues(new NamelessOption(null, '>=2.0.0 <2.0.6'), ['NOGC', 'MAXEXPANSIONS', 'TIMEOUT', 'ON_TIMEOUT', 'MIN_PHONETIC_TERM_LEN']),
36-
CustomValidatorOption::allowedValues(new NamelessOption(null, '>=2.0.6'), ['NOGC', 'MINPREFIX', 'MAXEXPANSIONS', 'MAXFILTEREXPANSION', 'TIMEOUT', 'ON_TIMEOUT', 'MIN_PHONETIC_TERM_LEN']),
36+
CustomValidatorOption::allowedValues(new NamelessOption(null, '>=2.0.6 <2.4.3'), ['NOGC', 'MINPREFIX', 'MAXEXPANSIONS', 'MAXFILTEREXPANSION', 'TIMEOUT', 'ON_TIMEOUT', 'MIN_PHONETIC_TERM_LEN']),
37+
CustomValidatorOption::allowedValues(new NamelessOption(null, '>=2.4.3'), ['NOGC', 'MINPREFIX', 'MAXEXPANSIONS', 'TIMEOUT', 'ON_TIMEOUT', 'MIN_PHONETIC_TERM_LEN', 'DEFAULT_DIALECT']),
3738
],
3839
'value' => new NamelessOption(null, '>=2.0.0'),
3940
], $rediSearchVersion);

Diff for: src/Redis/Command/Explain.php

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
namespace MacFJA\RediSearch\Redis\Command;
2323

24+
use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption as CV;
25+
use MacFJA\RediSearch\Redis\Command\Option\NamedOption;
2426
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;
2527

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

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

56+
public function setDialect(int $version): self
57+
{
58+
$this->options['dialect']->setValue($version);
59+
60+
return $this;
61+
}
62+
5363
public function getId(): string
5464
{
5565
return 'FT.EXPLAIN';

Diff for: src/Redis/Command/Search.php

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VE
7878
'params' => new NotEmptyOption(new NumberedOption('PARAMS', null, '>=2.4.0')),
7979
'sortby' => new SortByOption(),
8080
'limit' => new LimitOption(),
81+
'dialect' => CV::isNumeric(new NamedOption('DIALECT', null, '>=2.4.3')),
8182
],
8283
$rediSearchVersion
8384
);
@@ -322,6 +323,13 @@ public function getSize(): ?int
322323
return $limit->getSize();
323324
}
324325

326+
public function setDialect(int $version): self
327+
{
328+
$this->options['dialect']->setValue($version);
329+
330+
return $this;
331+
}
332+
325333
/**
326334
* @param mixed $data
327335
*

Diff for: src/Redis/Command/SpellCheck.php

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use function is_array;
2525
use MacFJA\RediSearch\Exception\UnexpectedServerResponseException;
2626
use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption;
27+
use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption as CV;
2728
use MacFJA\RediSearch\Redis\Command\Option\NamedOption;
2829
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;
2930
use MacFJA\RediSearch\Redis\Command\SpellCheckCommand\TermsOption;
@@ -41,6 +42,7 @@ public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VE
4142
new NamedOption('DISTANCE', null, '>=2.0.0'),
4243
Validator::intVal()->between(1, 4)
4344
),
45+
'dialect' => CV::isNumeric(new NamedOption('DIALECT', null, '>=2.4.3')),
4446
'terms' => [],
4547
], $rediSearchVersion);
4648
}
@@ -66,6 +68,13 @@ public function setDistance(int $distance): self
6668
return $this;
6769
}
6870

71+
public function setDialect(int $version): self
72+
{
73+
$this->options['dialect']->setValue($version);
74+
75+
return $this;
76+
}
77+
6978
public function addTerms(string $dictionary, bool $isExcluding = false): self
7079
{
7180
$terms = new TermsOption();

Diff for: tests/Redis/Command/AggregateTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function testLoadAll(): void
165165

166166
public function testFullOption(): void
167167
{
168-
$command = new Aggregate();
168+
$command = new Aggregate(Aggregate::MAX_IMPLEMENTED_VERSION);
169169
$command
170170
->setIndex('idx')
171171
->setQuery('@text1:"hello world"')
@@ -179,6 +179,7 @@ public function testFullOption(): void
179179
->setLimit(12, 35)
180180
->addApply('@timestamp - (@timestamp % 86400)', 'day')
181181
->setWithCursor(20, 30)
182+
->setDialect(2)
182183
;
183184

184185
static::assertSame([
@@ -192,6 +193,7 @@ public function testFullOption(): void
192193
'LIMIT', 12, 35,
193194
'FILTER', "@name=='foo' && @age < 20",
194195
'WITHCURSOR', 'COUNT', 20, 'MAXIDLE', 30,
196+
'DIALECT', 2,
195197
], $command->getArguments());
196198
}
197199

Diff for: tests/Redis/Command/ExplainCliTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* @covers \MacFJA\RediSearch\Redis\Command\ExplainCli
3232
*
3333
* @uses \MacFJA\RediSearch\Redis\Command\Option\AbstractCommandOption
34+
* @uses \MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption
35+
* @uses \MacFJA\RediSearch\Redis\Command\Option\DecoratedOptionTrait
36+
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamedOption
3437
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamelessOption
3538
*
3639
* @internal
@@ -45,15 +48,17 @@ public function testGetId(): void
4548

4649
public function testFullOption(): void
4750
{
48-
$command = new ExplainCli();
51+
$command = new ExplainCli(ExplainCli::MAX_IMPLEMENTED_VERSION);
4952
$command
5053
->setIndex('idx')
5154
->setQuery('@text1:"hello world"')
55+
->setDialect(2)
5256
;
5357

5458
static::assertSame([
5559
'idx',
5660
'@text1:"hello world"',
61+
'DIALECT', 2,
5762
], $command->getArguments());
5863
}
5964
}

Diff for: tests/Redis/Command/ExplainTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
* @covers \MacFJA\RediSearch\Redis\Command\Explain
3131
*
3232
* @uses \MacFJA\RediSearch\Redis\Command\Option\AbstractCommandOption
33+
* @uses \MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption
34+
* @uses \MacFJA\RediSearch\Redis\Command\Option\DecoratedOptionTrait
35+
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamedOption
3336
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamelessOption
3437
*
3538
* @internal
@@ -44,15 +47,17 @@ public function testGetId(): void
4447

4548
public function testFullOption(): void
4649
{
47-
$command = new Explain();
50+
$command = new Explain(Explain::MAX_IMPLEMENTED_VERSION);
4851
$command
4952
->setIndex('idx')
5053
->setQuery('@text1:"hello world"')
54+
->setDialect(2)
5155
;
5256

5357
static::assertSame([
5458
'idx',
5559
'@text1:"hello world"',
60+
'DIALECT', 2,
5661
], $command->getArguments());
5762
}
5863
}

Diff for: tests/Redis/Command/SearchTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public function testFullOption(): void
112112
->setPayload('foobar')
113113
->setSortBy('@num1', 'ASC')
114114
->setLimit(12, 10)
115+
->setDialect(2)
115116
;
116117

117118
static::assertSame([
@@ -138,6 +139,7 @@ public function testFullOption(): void
138139
'PAYLOAD', 'foobar',
139140
'SORTBY', '@num1', 'ASC',
140141
'LIMIT', 12, 10,
142+
'DIALECT', 2,
141143
], $command->getArguments());
142144
}
143145

Diff for: tests/Redis/Command/SpellCheckTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
**
3737
* @uses \MacFJA\RediSearch\Redis\Command\Option\AbstractCommandOption
3838
* @uses \MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption
39+
* @uses \MacFJA\RediSearch\Redis\Command\Option\DecoratedOptionTrait
3940
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamelessOption
4041
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamedOption
4142
*
@@ -51,19 +52,21 @@ public function testGetId(): void
5152

5253
public function testFullOption(): void
5354
{
54-
$command = new SpellCheck();
55+
$command = new SpellCheck(SpellCheck::MAX_IMPLEMENTED_VERSION);
5556
$command
5657
->setIndex('idx')
5758
->setQuery('@text1:"hello world"')
5859
->setDistance(2)
5960
->addTerms('badword', true)
6061
->addTerms('cities', false)
62+
->setDialect(2)
6163
;
6264

6365
static::assertSame([
6466
'idx',
6567
'@text1:"hello world"',
6668
'DISTANCE', 2,
69+
'DIALECT', 2,
6770
'TERMS', 'EXCLUDE', 'badword',
6871
'TERMS', 'INCLUDE', 'cities',
6972
], $command->getArguments());

0 commit comments

Comments
 (0)