Skip to content

Commit c6a58bd

Browse files
committed
Add RediSearch 2.0.11 + 2.0.12 options + fix version checking
1 parent 84cf02f commit c6a58bd

File tree

12 files changed

+120
-43
lines changed

12 files changed

+120
-43
lines changed

src/Redis/Command/AbstractCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
*/
3333
abstract class AbstractCommand extends Command
3434
{
35+
public const MAX_IMPLEMENTED_VERSION = '2.0.12';
36+
public const MIN_IMPLEMENTED_VERSION = '2.0.0';
3537
/**
3638
* @var array<array<CommandOption>|CommandOption|mixed>
3739
*/
@@ -153,8 +155,8 @@ private function buildArguments(): void
153155
return $option->isCompatible($this->rediSearchVersion) && $option->isValid();
154156
});
155157

156-
$arguments = array_reduce($arguments, static function ($carry, CommandOption $option) {
157-
return array_merge($carry, $option->render());
158+
$arguments = array_reduce($arguments, function ($carry, CommandOption $option) {
159+
return array_merge($carry, $option->render($this->rediSearchVersion));
158160
}, []);
159161
$this->setRawArguments($arguments);
160162
}

src/Redis/Command/AddFieldOptionTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ public function addGeoField(string $name, bool $noIndex = false): self
6363
);
6464
}
6565

66-
public function addTagField(string $name, ?string $separator = null, bool $sortable = false, bool $noIndex = false): self
66+
public function addTagField(string $name, ?string $separator = null, bool $sortable = false, bool $noIndex = false, bool $caseSensitive = false): self
6767
{
6868
return $this->addField(
6969
(new TagFieldOption())
7070
->setField($name)
7171
->setSeparator($separator)
72+
->setCaseSensitive($caseSensitive)
7273
->setSortable($sortable)
7374
->setNoIndex($noIndex)
7475
);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* Copyright MacFJA
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
9+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
10+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
11+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
14+
* Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
namespace MacFJA\RediSearch\Redis\Command\CreateCommand;
23+
24+
use MacFJA\RediSearch\Redis\Command\Option\CommandOption;
25+
use MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption;
26+
use MacFJA\RediSearch\Redis\Command\Option\FlagOption;
27+
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;
28+
use Respect\Validation\Rules\Callback;
29+
30+
trait BaseCreateFieldOptionTrait
31+
{
32+
/**
33+
* @param array<array<CommandOption>|CommandOption|mixed> $options $options
34+
*
35+
* @return array<array<CommandOption>|CommandOption|mixed> $options
36+
*/
37+
private function getConstructorOptions(string $type, array $options = []): array
38+
{
39+
$self = $this;
40+
41+
return array_merge(
42+
[
43+
'field' => new NamelessOption(null, '>=2.0.0'),
44+
'type' => new FlagOption($type, true, '>=2.0.0'),
45+
],
46+
$options,
47+
[
48+
'sortable' => new FlagOption('SORTABLE', false, '>=2.0.0'),
49+
'un_normalized_sortable' => new CustomValidatorOption(new FlagOption('UNF', false, '>=2.0.12'), new Callback(static function () use ($self) {
50+
return $self->getDataOfOption('sortable');
51+
})),
52+
'no_index' => new FlagOption('NOINDEX', false, '>=2.0.0'),
53+
]
54+
);
55+
}
56+
}

src/Redis/Command/CreateCommand/GeoFieldOption.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,23 @@
2121

2222
namespace MacFJA\RediSearch\Redis\Command\CreateCommand;
2323

24-
use MacFJA\RediSearch\Redis\Command\Option\FlagOption;
2524
use MacFJA\RediSearch\Redis\Command\Option\GroupedOption;
26-
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;
2725
use MacFJA\RediSearch\Redis\Command\Option\WithPublicGroupedSetterTrait;
2826

2927
/**
3028
* @method GeoFieldOption setField(string $name)
3129
* @method GeoFieldOption setNoIndex(bool $active)
3230
* @method GeoFieldOption setSortable(bool $active)
31+
* @method GeoFieldOption setUnNormalizedSortable(bool $unNormalized)
3332
*/
3433
class GeoFieldOption extends GroupedOption implements CreateCommandFieldOption
3534
{
35+
use BaseCreateFieldOptionTrait;
3636
use WithPublicGroupedSetterTrait;
3737

3838
public function __construct()
3939
{
40-
parent::__construct([
41-
'field' => new NamelessOption(null, '>=2.0.0'),
42-
'type' => new FlagOption('GEO', true, '>=2.0.0'),
43-
'no_index' => new FlagOption('NOINDEX', false, '>=2.0.0'),
44-
'sortable' => new FlagOption('SORTABLE', false, '>=2.0.10'),
45-
], ['field', 'type'], ['type'], '>=2.0.0');
40+
parent::__construct($this->getConstructorOptions('GEO'), ['field', 'type'], ['type'], '>=2.0.0');
4641
}
4742

4843
public function getFieldName(): string
@@ -55,6 +50,6 @@ public function getFieldName(): string
5550
*/
5651
protected function publicSetter(): array
5752
{
58-
return ['field', 'no_index', 'sortable'];
53+
return ['field', 'no_index', 'sortable', 'un_normalized_sortable'];
5954
}
6055
}

src/Redis/Command/CreateCommand/NumericFieldOption.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,23 @@
2121

2222
namespace MacFJA\RediSearch\Redis\Command\CreateCommand;
2323

24-
use MacFJA\RediSearch\Redis\Command\Option\FlagOption;
2524
use MacFJA\RediSearch\Redis\Command\Option\GroupedOption;
26-
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;
2725
use MacFJA\RediSearch\Redis\Command\Option\WithPublicGroupedSetterTrait;
2826

2927
/**
3028
* @method NumericFieldOption setField(string $name)
3129
* @method NumericFieldOption setNoIndex(bool $active)
3230
* @method NumericFieldOption setSortable(bool $active)
31+
* @method NumericFieldOption setUnNormalizedSortable(bool $unNormalized)
3332
*/
3433
class NumericFieldOption extends GroupedOption implements CreateCommandFieldOption
3534
{
35+
use BaseCreateFieldOptionTrait;
3636
use WithPublicGroupedSetterTrait;
3737

3838
public function __construct()
3939
{
40-
parent::__construct([
41-
'field' => new NamelessOption(null, '>=2.0.0'),
42-
'type' => new FlagOption('NUMERIC', true, '>=2.0.0'),
43-
'sortable' => new FlagOption('SORTABLE', false, '>=2.0.0'),
44-
'no_index' => new FlagOption('NOINDEX', false, '>=2.0.0'),
45-
], ['field', 'type'], ['type'], '>=2.0.0');
40+
parent::__construct($this->getConstructorOptions('NUMERIC'), ['field', 'type'], ['type'], '>=2.0.0');
4641
}
4742

4843
public function getFieldName(): string
@@ -55,6 +50,6 @@ public function getFieldName(): string
5550
*/
5651
protected function publicSetter(): array
5752
{
58-
return ['field', 'no_index', 'sortable'];
53+
return ['field', 'no_index', 'sortable', 'un_normalized_sortable'];
5954
}
6055
}

src/Redis/Command/CreateCommand/TagFieldOption.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use MacFJA\RediSearch\Redis\Command\Option\FlagOption;
2626
use MacFJA\RediSearch\Redis\Command\Option\GroupedOption;
2727
use MacFJA\RediSearch\Redis\Command\Option\NamedOption;
28-
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;
2928
use MacFJA\RediSearch\Redis\Command\Option\WithPublicGroupedSetterTrait;
3029
use Respect\Validation\Rules\Length;
3130

@@ -34,20 +33,20 @@
3433
* @method TagFieldOption setNoIndex(bool $active)
3534
* @method TagFieldOption setSortable(bool $active)
3635
* @method TagFieldOption setSeparator(?string $separator)
36+
* @method TagFieldOption setCaseSensitive(bool $active)
37+
* @method TagFieldOption setUnNormalizedSortable(bool $unNormalized)
3738
*/
3839
class TagFieldOption extends GroupedOption implements CreateCommandFieldOption
3940
{
41+
use BaseCreateFieldOptionTrait;
4042
use WithPublicGroupedSetterTrait;
4143

4244
public function __construct()
4345
{
44-
parent::__construct([
45-
'field' => new NamelessOption(null, '>=2.0.0'),
46-
'type' => new FlagOption('TAG', true, '>=2.0.0'),
46+
parent::__construct($this->getConstructorOptions('TAG', [
4747
'separator' => new CustomValidatorOption(new NamedOption('SEPARATOR', null, '>=2.0.0'), new Length(1, 1)),
48-
'sortable' => new FlagOption('SORTABLE', false, '>=2.0.0'),
49-
'no_index' => new FlagOption('NOINDEX', false, '>=2.0.0'),
50-
], ['field', 'type'], ['type'], '>=2.0.0');
48+
'case_sensitive' => new FlagOption('CASESENSITIVE', false, '>=2.0.11'),
49+
]), ['field', 'type'], ['type'], '>=2.0.0');
5150
}
5251

5352
public function getFieldName(): string
@@ -60,6 +59,6 @@ public function getFieldName(): string
6059
*/
6160
protected function publicSetter(): array
6261
{
63-
return ['field', 'separator', 'sortable', 'no_index'];
62+
return ['field', 'separator', 'sortable', 'no_index', 'case_sensitive', 'un_normalized_sortable'];
6463
}
6564
}

src/Redis/Command/CreateCommand/TextFieldOption.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use MacFJA\RediSearch\Redis\Command\Option\FlagOption;
2626
use MacFJA\RediSearch\Redis\Command\Option\GroupedOption;
2727
use MacFJA\RediSearch\Redis\Command\Option\NamedOption;
28-
use MacFJA\RediSearch\Redis\Command\Option\NamelessOption;
2928
use MacFJA\RediSearch\Redis\Command\Option\WithPublicGroupedSetterTrait;
3029

3130
/**
@@ -35,22 +34,20 @@
3534
* @method TextFieldOption setNoStem(bool $active)
3635
* @method TextFieldOption setWeight(?float $weight)
3736
* @method TextFieldOption setPhonetic(?string $phonetic)
37+
* @method TextFieldOption setUnNormalizedSortable(bool $unNormalized)
3838
*/
3939
class TextFieldOption extends GroupedOption implements CreateCommandFieldOption
4040
{
41+
use BaseCreateFieldOptionTrait;
4142
use WithPublicGroupedSetterTrait;
4243

4344
public function __construct()
4445
{
45-
parent::__construct([
46-
'field' => new NamelessOption(null, '>=2.0.0'),
47-
'type' => new FlagOption('TEXT', true, '>=2.0.0'),
46+
parent::__construct($this->getConstructorOptions('TEXT', [
4847
'no_stem' => new FlagOption('NOSTEM', false, '>=2.0.0'),
4948
'weight' => CustomValidatorOption::isNumeric(new NamedOption('WEIGHT', null, '>=2.0.0')),
5049
'phonetic' => CustomValidatorOption::allowedValues(new NamedOption('PHONETIC', null, '>=2.0.0'), ['dm:en', 'dm:fr', 'dm:pt', 'dm:es']),
51-
'sortable' => new FlagOption('SORTABLE', false, '>=2.0.0'),
52-
'no_index' => new FlagOption('NOINDEX', false, '>=2.0.0'),
53-
], ['field', 'type'], ['type'], '>=2.0.0');
50+
]), ['field', 'type'], ['type'], '>=2.0.0');
5451
}
5552

5653
public function getFieldName(): string
@@ -63,6 +60,6 @@ public function getFieldName(): string
6360
*/
6461
protected function publicSetter(): array
6562
{
66-
return ['field', 'no_stem', 'weight', 'phonetic', 'sortable', 'no_index'];
63+
return ['field', 'no_stem', 'weight', 'phonetic', 'sortable', 'no_index', 'un_normalized_sortable'];
6764
}
6865
}

src/Redis/Command/SearchCommand/SummarizeOption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct()
3737
'fields' => new NotEmptyOption(new NumberedOption('FIELDS', null, '>=2.0.0')),
3838
'frags' => CV::isNumeric(new NamedOption('FRAGS', null, '>=2.0.0')),
3939
'len' => CV::isNumeric(new NamedOption('LEN', null, '>=2.0.0')),
40-
'separator' => new NamedOption('SEPARATOR', null, '>=2.0.à'),
40+
'separator' => new NamedOption('SEPARATOR', null, '>=2.0.0'),
4141
], ['type'], ['type'], '>=2.0.0');
4242
}
4343
}

tests/Redis/Command/AddFieldOptionTraitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
* @uses \MacFJA\RediSearch\Redis\Command\AbstractCommand
3232
* @uses \MacFJA\RediSearch\Redis\Command\CreateCommand\NumericFieldOption
3333
* @uses \MacFJA\RediSearch\Redis\Command\Option\AbstractCommandOption
34+
* @uses \MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption
35+
* @uses \MacFJA\RediSearch\Redis\Command\Option\DecoratedOptionTrait
3436
* @uses \MacFJA\RediSearch\Redis\Command\Option\FlagOption
3537
* @uses \MacFJA\RediSearch\Redis\Command\Option\GroupedOption
3638
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamelessOption

tests/Redis/Command/AlterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* @uses \MacFJA\RediSearch\Redis\Command\Option\NamelessOption
3737
* @uses \MacFJA\RediSearch\Redis\Command\Option\FlagOption
3838
* @uses \MacFJA\RediSearch\Redis\Command\Option\GroupedOption
39+
* @uses \MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption
3940
*
4041
* @internal
4142
*/

0 commit comments

Comments
 (0)