Skip to content

Commit bf556aa

Browse files
committed
RediSearch 2.4.3 compatibility
1 parent c7c25cf commit bf556aa

16 files changed

+67
-9
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- `LOAD ALL` option on Aggregate command (RediSearch `2.0.13`)
1515
- Profile command (RediSearch `2.2.0`) ([Issue#4])
1616
- Vector feature (RediSearch `2.4.0` / `2.4.2`)
17+
- Add `DIALECT` option (RediSearch `2.4.3`) ([Issue#35])
1718
- (dev) Add `make clean` to remove all generated files
1819
- (dev) Add code coverage to `\MacFJA\RediSearch\Index`
1920
- (dev) Add integration test for document insertion
@@ -234,6 +235,7 @@ First version
234235
[Issue#12]: https://github.com/MacFJA/php-redisearch/issues/12
235236
[Issue#16]: https://github.com/MacFJA/php-redisearch/issues/16
236237
[Issue#26]: https://github.com/MacFJA/php-redisearch/issues/26
238+
[Issue#35]: https://github.com/MacFJA/php-redisearch/issues/35
237239
[Issue#38]: https://github.com/MacFJA/php-redisearch/issues/38
238240
[Issue#39]: https://github.com/MacFJA/php-redisearch/issues/39
239241
[Issue#46]: https://github.com/MacFJA/php-redisearch/issues/46

src/Query/Builder/QueryElementVector.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
use function array_key_exists;
2525
use function count;
2626
use function gettype;
27-
use InvalidArgumentException;
2827
use function is_int;
2928
use function is_string;
3029
use function strlen;
3130

31+
use InvalidArgumentException;
32+
3233
class QueryElementVector implements QueryElementDecorator
3334
{
3435
private const PARAMETERS = [

src/Redis/Command/AbstractCommand.php

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

3939
/**

src/Redis/Command/Aggregate.php

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

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

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

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);

src/Redis/Command/CreateCommand/VectorFieldOption.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
namespace MacFJA\RediSearch\Redis\Command\CreateCommand;
2323

2424
use function in_array;
25-
use InvalidArgumentException;
2625
use function is_int;
26+
27+
use InvalidArgumentException;
2728
use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption;
2829
use MacFJA\RediSearch\Redis\Command\Option\GroupedOption;
2930
use MacFJA\RediSearch\Redis\Command\Option\NamedOption;

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';

src/Redis/Command/ProfileCommand/QueryOption.php

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace MacFJA\RediSearch\Redis\Command\ProfileCommand;
2323

2424
use function assert;
25+
2526
use MacFJA\RediSearch\Redis\Command\Aggregate;
2627
use MacFJA\RediSearch\Redis\Command\Option\AbstractCommandOption;
2728
use MacFJA\RediSearch\Redis\Command\Search;

src/Redis/Command/Search.php

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

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

src/Redis/Command/SpellCheck.php

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
use MacFJA\RediSearch\Exception\UnexpectedServerResponseException;
2727
use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption;
28+
use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption as CV;
2829
use MacFJA\RediSearch\Redis\Command\Option\NamedOption;
2930
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;
3031
use MacFJA\RediSearch\Redis\Command\SpellCheckCommand\TermsOption;
@@ -42,6 +43,7 @@ public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VE
4243
new NamedOption('DISTANCE', null, '>=2.0.0'),
4344
Validator::intVal()->between(1, 4)
4445
),
46+
'dialect' => CV::isNumeric(new NamedOption('DIALECT', null, '>=2.4.3')),
4547
'terms' => [],
4648
], $rediSearchVersion);
4749
}
@@ -67,6 +69,13 @@ public function setDistance(int $distance): self
6769
return $this;
6870
}
6971

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

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

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
}

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
}

tests/Redis/Command/ProfileTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testFullOption(): void
7070
->setTypeAggregate()
7171
->setLimited()
7272
->setQuery($aggregate)
73-
;
73+
;
7474

7575
static::assertSame([
7676
'idx', 'AGGREGATE', 'LIMITED', 'QUERY', '@foo:bar',

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

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)