Skip to content

Commit 4a5c419

Browse files
authored
Merge 366a4b0 into 8c2aac4
2 parents 8c2aac4 + 366a4b0 commit 4a5c419

File tree

11 files changed

+195
-9
lines changed

11 files changed

+195
-9
lines changed

src/Command/Argument/Search/SchemaFields/AbstractField.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ abstract class AbstractField implements FieldInterface
2929
* @param string $alias
3030
* @param bool|string $sortable
3131
* @param bool $noIndex
32+
* @param bool $allowsMissing
3233
* @return void
3334
*/
3435
protected function setCommonOptions(
3536
string $fieldType,
3637
string $identifier,
3738
string $alias = '',
3839
$sortable = self::NOT_SORTABLE,
39-
bool $noIndex = false
40+
bool $noIndex = false,
41+
bool $allowsMissing = false
4042
): void {
4143
$this->fieldArguments[] = $identifier;
4244

@@ -57,6 +59,10 @@ protected function setCommonOptions(
5759
if ($noIndex) {
5860
$this->fieldArguments[] = 'NOINDEX';
5961
}
62+
63+
if ($allowsMissing) {
64+
$this->fieldArguments[] = 'INDEXMISSING';
65+
}
6066
}
6167

6268
/**

src/Command/Argument/Search/SchemaFields/GeoField.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ class GeoField extends AbstractField
1919
* @param string $alias
2020
* @param bool|string $sortable
2121
* @param bool $noIndex
22+
* @param bool $allowsMissing
2223
*/
2324
public function __construct(
2425
string $identifier,
2526
string $alias = '',
2627
$sortable = self::NOT_SORTABLE,
27-
bool $noIndex = false
28+
bool $noIndex = false,
29+
bool $allowsMissing = false
2830
) {
29-
$this->setCommonOptions('GEO', $identifier, $alias, $sortable, $noIndex);
31+
$this->setCommonOptions('GEO', $identifier, $alias, $sortable, $noIndex, $allowsMissing);
3032
}
3133
}

src/Command/Argument/Search/SchemaFields/NumericField.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ class NumericField extends AbstractField
1919
* @param string $alias
2020
* @param bool|string $sortable
2121
* @param bool $noIndex
22+
* @param bool $allowsMissing
2223
*/
2324
public function __construct(
2425
string $identifier,
2526
string $alias = '',
2627
$sortable = self::NOT_SORTABLE,
27-
bool $noIndex = false
28+
bool $noIndex = false,
29+
bool $allowsMissing = false
2830
) {
29-
$this->setCommonOptions('NUMERIC', $identifier, $alias, $sortable, $noIndex);
31+
$this->setCommonOptions('NUMERIC', $identifier, $alias, $sortable, $noIndex, $allowsMissing);
3032
}
3133
}

src/Command/Argument/Search/SchemaFields/TagField.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ class TagField extends AbstractField
2121
* @param bool $noIndex
2222
* @param string $separator
2323
* @param bool $caseSensitive
24+
* @param bool $allowsEmpty
2425
*/
2526
public function __construct(
2627
string $identifier,
2728
string $alias = '',
2829
$sortable = self::NOT_SORTABLE,
2930
bool $noIndex = false,
3031
string $separator = ',',
31-
bool $caseSensitive = false
32+
bool $caseSensitive = false,
33+
bool $allowsEmpty = false,
34+
bool $allowsMissing = false
3235
) {
33-
$this->setCommonOptions('TAG', $identifier, $alias, $sortable, $noIndex);
36+
$this->setCommonOptions('TAG', $identifier, $alias, $sortable, $noIndex, $allowsMissing);
3437

3538
if ($separator !== ',') {
3639
$this->fieldArguments[] = 'SEPARATOR';
@@ -40,5 +43,9 @@ public function __construct(
4043
if ($caseSensitive) {
4144
$this->fieldArguments[] = 'CASESENSITIVE';
4245
}
46+
47+
if ($allowsEmpty) {
48+
$this->fieldArguments[] = 'INDEXEMPTY';
49+
}
4350
}
4451
}

src/Command/Argument/Search/SchemaFields/TextField.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class TextField extends AbstractField
2323
* @param string $phonetic
2424
* @param int $weight
2525
* @param bool $withSuffixTrie
26+
* @param bool $allowsEmpty
27+
* @param bool $allowsMissing
2628
*/
2729
public function __construct(
2830
string $identifier,
@@ -32,9 +34,11 @@ public function __construct(
3234
bool $noStem = false,
3335
string $phonetic = '',
3436
int $weight = 1,
35-
bool $withSuffixTrie = false
37+
bool $withSuffixTrie = false,
38+
bool $allowsEmpty = false,
39+
bool $allowsMissing = false
3640
) {
37-
$this->setCommonOptions('TEXT', $identifier, $alias, $sortable, $noIndex);
41+
$this->setCommonOptions('TEXT', $identifier, $alias, $sortable, $noIndex, $allowsMissing);
3842

3943
if ($noStem) {
4044
$this->fieldArguments[] = 'NOSTEM';
@@ -53,5 +57,9 @@ public function __construct(
5357
if ($withSuffixTrie) {
5458
$this->fieldArguments[] = 'WITHSUFFIXTRIE';
5559
}
60+
61+
if ($allowsEmpty) {
62+
$this->fieldArguments[] = 'INDEXEMPTY';
63+
}
5664
}
5765
}

tests/Predis/Command/Argument/Search/SchemaFields/GeoFieldTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function geoFieldsProvider(): array
5252
['field_name', '', AbstractField::NOT_SORTABLE, true],
5353
['field_name', 'GEO', 'NOINDEX'],
5454
],
55+
'with INDEXMISSING modifier' => [
56+
['field_name', '', AbstractField::NOT_SORTABLE, false, true],
57+
['field_name', 'GEO', 'INDEXMISSING'],
58+
],
5559
];
5660
}
5761
}

tests/Predis/Command/Argument/Search/SchemaFields/NumericFieldTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function numericFieldsProvider(): array
5252
['field_name', '', AbstractField::NOT_SORTABLE, true],
5353
['field_name', 'NUMERIC', 'NOINDEX'],
5454
],
55+
'with INDEXMISSING modifier' => [
56+
['field_name', '', AbstractField::NOT_SORTABLE, false, true],
57+
['field_name', 'NUMERIC', 'INDEXMISSING'],
58+
],
5559
];
5660
}
5761
}

tests/Predis/Command/Argument/Search/SchemaFields/TagFieldTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ public function tagFieldsProvider(): array
5252
['field_name', '', AbstractField::NOT_SORTABLE, true],
5353
['field_name', 'TAG', 'NOINDEX'],
5454
],
55+
'with INDEXEMPTY modifier' => [
56+
['field_name', '', AbstractField::NOT_SORTABLE, false, ',', false, true],
57+
['field_name', 'TAG', 'INDEXEMPTY'],
58+
],
59+
'with INDEXMISSING modifier' => [
60+
['field_name', '', AbstractField::NOT_SORTABLE, false, ',', false, false, true],
61+
['field_name', 'TAG', 'INDEXMISSING'],
62+
],
5563
];
5664
}
5765
}

tests/Predis/Command/Argument/Search/SchemaFields/TextFieldTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ public function textFieldsProvider(): array
5252
['field_name', '', AbstractField::NOT_SORTABLE, true],
5353
['field_name', 'TEXT', 'NOINDEX'],
5454
],
55+
'with INDEXEMPTY modifier' => [
56+
['field_name', '', AbstractField::NOT_SORTABLE, false, false, '', 1, false, true],
57+
['field_name', 'TEXT', 'INDEXEMPTY'],
58+
],
59+
'with INDEXMISSING modifier' => [
60+
['field_name', '', AbstractField::NOT_SORTABLE, false, false, '', 1, false, false, true],
61+
['field_name', 'TEXT', 'INDEXMISSING'],
62+
],
5563
];
5664
}
5765
}

tests/Predis/Command/Redis/Search/FTCREATE_Test.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Predis\Command\Redis\Search;
1414

1515
use Predis\Command\Argument\Search\CreateArguments;
16+
use Predis\Command\Argument\Search\SchemaFields\GeoField;
1617
use Predis\Command\Argument\Search\SchemaFields\NumericField;
1718
use Predis\Command\Argument\Search\SchemaFields\TagField;
1819
use Predis\Command\Argument\Search\SchemaFields\TextField;
@@ -113,6 +114,43 @@ public function testCreatesSearchIndexWithFloat16Vector(): void
113114
$this->assertEquals('OK', $actualResponse);
114115
}
115116

117+
/**
118+
* @group connected
119+
* @group relay-resp3
120+
* @return void
121+
* @requiresRediSearchVersion >= 2.9.0
122+
*/
123+
public function testCreatesSearchIndexWithMissingAndEmptyFields(): void
124+
{
125+
$redis = $this->getClient();
126+
127+
$schema = [
128+
new TextField(
129+
'text_empty',
130+
'',
131+
false, false, false, '', 1, false, true
132+
),
133+
new TagField('tag_empty',
134+
'', false, false, ',', false, true
135+
),
136+
new NumericField('num_missing', '', false, false, true),
137+
new GeoField('geo_missing', '', false, false, true),
138+
new TextField(
139+
'text_empty_missing',
140+
'',
141+
false,
142+
false, false, '', 1, false, true, true
143+
),
144+
new TagField('tag_empty_missing',
145+
'', false, false, ',', false, true, true
146+
),
147+
];
148+
149+
$actualResponse = $redis->ftcreate('index', $schema);
150+
151+
$this->assertEquals('OK', $actualResponse);
152+
}
153+
116154
public function argumentsProvider(): array
117155
{
118156
return [

0 commit comments

Comments
 (0)