Low-level implementation for FT.CREATE command (#1187)

* Added support for new arguments for BITPOS, BITCOUNT commands (#1045)

* Added support for new arguments for EXPIRE, EXPIREAT commands (#1046)

* Extended core support by implementing SORT_RO command (#1044)

* Added support for SORT_RO command

* Codestyle fixes

* Added command description

---------

Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>

* fix deprecated call

* Added support for container commands (#1049)

* Added support for container commands FUNCTION LOAD, FUNCTION DELETE and FCALL

* Changed ContainerInterface and AbstractContainer

* Re-implement logic of abstract methods

---------

Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>

* Added stream commands to KeyPrefixProcessor (#1051)

Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>

* Fix return type of ReplicationInterface::getSlaves (#1111)

* Codestyle fixes

* Changed return annotation

* Implemented low-level solution with builder under the hood

* Renamed variable

* Codestyle fixes

* New Schema implementation

* Removed deprecated payload_field argument

* Changed command argument name to more meaningful

* Added arguments default values according to documentation

* Changed letter to capital

* Changed arguments inteface, using builder directly

* Removed unused interface

* Fix misspelling error

* Fixed tests, remove old Schema object

* Removed SchemaTest

* Removed broken references

---------

Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>
Co-authored-by: Till Krüss <till@kruss.io>
Co-authored-by: Stephan <glaubinix@users.noreply.github.com>
Co-authored-by: Chayim <chayim@users.noreply.github.com>
This commit is contained in:
Vladyslav Vildanov
2023-03-14 10:31:38 +02:00
committed by GitHub
parent 3a921190a1
commit 684bb34cf2
35 changed files with 657 additions and 559 deletions
+3 -3
View File
@@ -18,7 +18,7 @@ use Predis\Command\Argument\Search\AlterArguments;
use Predis\Command\Argument\Search\CreateArguments;
use Predis\Command\Argument\Search\DropArguments;
use Predis\Command\Argument\Search\ProfileArguments;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\FieldInterface;
use Predis\Command\Argument\Search\SearchArguments;
use Predis\Command\Argument\Search\SugAddArguments;
use Predis\Command\Argument\Search\SugGetArguments;
@@ -98,8 +98,8 @@ use Predis\Command\Container\Search\FTCONFIG;
* @method $this ftaliasadd(string $alias, string $index)
* @method $this ftaliasdel(string $alias)
* @method $this ftaliasupdate(string $alias, string $index)
* @method $this ftalter(string $index, Schema $schema, ?AlterArguments $arguments = null)
* @method $this ftcreate(string $index, Schema $schema, ?CreateArguments $arguments = null)
* @method $this ftalter(string $index, FieldInterface[] $schema, ?AlterArguments $arguments = null)
* @method $this ftcreate(string $index, FieldInterface[] $schema, ?CreateArguments $arguments = null)
* @method $this ftdictadd(string $dict, ...$term)
* @method $this ftdictdel(string $dict, ...$term)
* @method $this ftdictdump(string $dict)
+3 -3
View File
@@ -18,7 +18,7 @@ use Predis\Command\Argument\Search\AlterArguments;
use Predis\Command\Argument\Search\CreateArguments;
use Predis\Command\Argument\Search\DropArguments;
use Predis\Command\Argument\Search\ProfileArguments;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\FieldInterface;
use Predis\Command\Argument\Search\SearchArguments;
use Predis\Command\Argument\Search\SugAddArguments;
use Predis\Command\Argument\Search\SugGetArguments;
@@ -107,8 +107,8 @@ use Predis\Response\Status;
* @method Status ftaliasadd(string $alias, string $index)
* @method Status ftaliasdel(string $alias)
* @method Status ftaliasupdate(string $alias, string $index)
* @method Status ftalter(string $index, Schema $schema, ?AlterArguments $arguments = null)
* @method Status ftcreate(string $index, Schema $schema, ?CreateArguments $arguments = null)
* @method Status ftalter(string $index, FieldInterface[] $schema, ?AlterArguments $arguments = null)
* @method Status ftcreate(string $index, FieldInterface[] $schema, ?CreateArguments $arguments = null)
* @method int ftdictadd(string $dict, ...$term)
* @method int ftdictdel(string $dict, ...$term)
* @method array ftdictdump(string $dict)
@@ -27,7 +27,7 @@ class CommonArguments implements ArrayableArgument
* @param string $defaultLanguage
* @return $this
*/
public function language(string $defaultLanguage): self
public function language(string $defaultLanguage = 'english'): self
{
$this->arguments[] = 'LANGUAGE';
$this->arguments[] = $defaultLanguage;
@@ -30,7 +30,7 @@ class CreateArguments extends CommonArguments
* @param string $modifier
* @return $this
*/
public function on(string $modifier): self
public function on(string $modifier = 'HASH'): self
{
if (in_array(strtoupper($modifier), $this->supportedDataTypesEnum)) {
$this->arguments[] = 'ON';
@@ -92,7 +92,7 @@ class CreateArguments extends CommonArguments
* @param float $defaultScore
* @return $this
*/
public function score(float $defaultScore): self
public function score(float $defaultScore = 1.0): self
{
$this->arguments[] = 'SCORE';
$this->arguments[] = $defaultScore;
@@ -114,20 +114,6 @@ class CreateArguments extends CommonArguments
return $this;
}
/**
* Document attribute that you use as a binary safe payload string.
*
* @param string $payloadAttribute
* @return $this
*/
public function payloadField(string $payloadAttribute): self
{
$this->arguments[] = 'PAYLOAD_FIELD';
$this->arguments[] = $payloadAttribute;
return $this;
}
/**
* Forces RediSearch to encode indexes as if there were more than 32 text attributes.
*
@@ -155,11 +141,13 @@ class CreateArguments extends CommonArguments
/**
* Creates a lightweight temporary index that expires after a specified period of inactivity, in seconds.
*
* @param int $seconds
* @return $this
*/
public function temporary(): self
public function temporary(int $seconds): self
{
$this->arguments[] = 'TEMPORARY';
$this->arguments[] = $seconds;
return $this;
}
-210
View File
@@ -1,210 +0,0 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search;
use Predis\Command\Argument\ArrayableArgument;
class Schema implements ArrayableArgument
{
public const SORTABLE = true;
public const NOT_SORTABLE = false;
public const SORTABLE_UNF = 'UNF';
/**
* @var array
*/
private $arguments = ['SCHEMA'];
/**
* @param bool $additive Defines if schema should be additive, for additional attributes
*/
public function __construct(bool $additive = false)
{
if ($additive) {
$this->arguments[] = 'ADD';
}
}
/**
* Adds text field to schema configuration.
*
* @param string $fieldName
* @param string $alias
* @param bool|string $sortable
* @param bool $noIndex
* @return $this
*/
public function addTextField(
string $fieldName,
string $alias = '',
$sortable = false,
bool $noIndex = false
): self {
return $this->addField('TEXT', $fieldName, $alias, $sortable, $noIndex);
}
/**
* Adds tag field to schema configuration.
*
* @param string $fieldName
* @param string $alias
* @param bool|string $sortable
* @param bool $noIndex
* @return $this
*/
public function addTagField(
string $fieldName,
string $alias = '',
$sortable = false,
bool $noIndex = false
): self {
return $this->addField('TAG', $fieldName, $alias, $sortable, $noIndex);
}
/**
* Adds numeric field to schema configuration.
*
* @param string $fieldName
* @param string $alias
* @param bool|string $sortable
* @param bool $noIndex
* @return $this
*/
public function addNumericField(
string $fieldName,
string $alias = '',
$sortable = self::NOT_SORTABLE,
bool $noIndex = false
): self {
return $this->addField('NUMERIC', $fieldName, $alias, $sortable, $noIndex);
}
/**
* Adds geo field to schema configuration.
*
* @param string $fieldName
* @param string $alias
* @param bool|string $sortable
* @param bool $noIndex
* @return $this
*/
public function addGeoField(
string $fieldName,
string $alias = '',
$sortable = self::NOT_SORTABLE,
bool $noIndex = false
): self {
return $this->addField('GEO', $fieldName, $alias, $sortable, $noIndex);
}
/**
* Adds vector field to schema configuration.
*
* @param string $fieldName
* @param string $algorithm
* @param array $attributeNameValueDictionary ['attribute_name', 'attribute_value'...]
* @return $this
*/
public function addVectorField(
string $fieldName,
string $algorithm,
array $attributeNameValueDictionary
): self {
array_push($this->arguments, $fieldName, 'VECTOR', $algorithm, count($attributeNameValueDictionary));
$this->arguments = array_merge($this->arguments, $attributeNameValueDictionary);
return $this;
}
/**
* Adds given field to schema configuration.
*
* @param string $type
* @param string $fieldName
* @param string $alias
* @param bool|string $sortable
* @param bool $noIndex
* @return $this
*/
private function addField(
string $type,
string $fieldName,
string $alias = '',
$sortable = self::NOT_SORTABLE,
bool $noIndex = false
): self {
$this->arguments[] = $fieldName;
$this->setAlias($alias);
$this->arguments[] = $type;
$this->setFieldConfiguration($sortable, $noIndex);
return $this;
}
/**
* @param bool|string $sortable
* @param bool $noIndex
* @return void
*/
private function setFieldConfiguration($sortable, bool $noIndex): void
{
if ($sortable) {
$this->setSortable($sortable);
}
if ($noIndex) {
$this->setNoIndex();
}
}
/**
* @param string $alias
* @return void
*/
private function setAlias(string $alias): void
{
if ($alias !== '') {
$this->arguments[] = 'AS';
$this->arguments[] = $alias;
}
}
/**
* @param bool|string $sortable
* @return void
*/
private function setSortable($sortable): void
{
$this->arguments[] = 'SORTABLE';
if ($sortable === self::SORTABLE_UNF) {
$this->arguments[] = 'UNF';
}
}
/**
* @return void
*/
private function setNoIndex(): void
{
$this->arguments[] = 'NOINDEX';
}
/**
* {@inheritDoc}
*/
public function toArray(): array
{
return $this->arguments;
}
}
@@ -0,0 +1,69 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
abstract class AbstractField implements FieldInterface
{
public const SORTABLE = true;
public const NOT_SORTABLE = false;
public const SORTABLE_UNF = 'UNF';
/**
* @var array
*/
protected $fieldArguments = [];
/**
* @param string $fieldType
* @param string $identifier
* @param string $alias
* @param bool|string $sortable
* @param bool $noIndex
* @return void
*/
protected function setCommonOptions(
string $fieldType,
string $identifier,
string $alias = '',
$sortable = self::NOT_SORTABLE,
bool $noIndex = false
): void {
$this->fieldArguments[] = $identifier;
if ($alias !== '') {
$this->fieldArguments[] = 'AS';
$this->fieldArguments[] = $alias;
}
$this->fieldArguments[] = $fieldType;
if ($sortable === self::SORTABLE) {
$this->fieldArguments[] = 'SORTABLE';
} elseif ($sortable === self::SORTABLE_UNF) {
$this->fieldArguments[] = 'SORTABLE';
$this->fieldArguments[] = 'UNF';
}
if ($noIndex) {
$this->fieldArguments[] = 'NOINDEX';
}
}
/**
* {@inheritDoc}
*/
public function toArray(): array
{
return $this->fieldArguments;
}
}
@@ -0,0 +1,22 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
use Predis\Command\Argument\ArrayableArgument;
/**
* Represents field in search schema.
*/
interface FieldInterface extends ArrayableArgument
{
}
@@ -0,0 +1,31 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
class GeoField extends AbstractField
{
/**
* @param string $identifier
* @param string $alias
* @param bool|string $sortable
* @param bool $noIndex
*/
public function __construct(
string $identifier,
string $alias = '',
$sortable = self::NOT_SORTABLE,
bool $noIndex = false
) {
$this->setCommonOptions('GEO', $identifier, $alias, $sortable, $noIndex);
}
}
@@ -0,0 +1,31 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
class NumericField extends AbstractField
{
/**
* @param string $identifier
* @param string $alias
* @param bool|string $sortable
* @param bool $noIndex
*/
public function __construct(
string $identifier,
string $alias = '',
$sortable = self::NOT_SORTABLE,
bool $noIndex = false
) {
$this->setCommonOptions('NUMERIC', $identifier, $alias, $sortable, $noIndex);
}
}
@@ -0,0 +1,44 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
class TagField extends AbstractField
{
/**
* @param string $identifier
* @param string $alias
* @param bool|string $sortable
* @param bool $noIndex
* @param string $separator
* @param bool $caseSensitive
*/
public function __construct(
string $identifier,
string $alias = '',
$sortable = self::NOT_SORTABLE,
bool $noIndex = false,
string $separator = ',',
bool $caseSensitive = false
) {
$this->setCommonOptions('TAG', $identifier, $alias, $sortable, $noIndex);
if ($separator !== ',') {
$this->fieldArguments[] = 'SEPARATOR';
$this->fieldArguments[] = $separator;
}
if ($caseSensitive) {
$this->fieldArguments[] = 'CASESENSITIVE';
}
}
}
@@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
class TextField extends AbstractField
{
/**
* @param string $identifier
* @param string $alias
* @param bool|string $sortable
* @param bool $noIndex
* @param bool $noStem
* @param string $phonetic
* @param int $weight
* @param bool $withSuffixTrie
*/
public function __construct(
string $identifier,
string $alias = '',
$sortable = self::NOT_SORTABLE,
bool $noIndex = false,
bool $noStem = false,
string $phonetic = '',
int $weight = 1,
bool $withSuffixTrie = false
) {
$this->setCommonOptions('TEXT', $identifier, $alias, $sortable, $noIndex);
if ($noStem) {
$this->fieldArguments[] = 'NOSTEM';
}
if ($phonetic !== '') {
$this->fieldArguments[] = 'PHONETIC';
$this->fieldArguments[] = $phonetic;
}
if ($weight !== 1) {
$this->fieldArguments[] = 'WEIGHT';
$this->fieldArguments[] = $weight;
}
if ($withSuffixTrie) {
$this->fieldArguments[] = 'WITHSUFFIXTRIE';
}
}
}
@@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
class VectorField implements FieldInterface
{
/**
* @var array
*/
protected $fieldArguments = [];
/**
* @param string $fieldName
* @param string $algorithm
* @param array $attributeNameValueDictionary
*/
public function __construct(
string $fieldName,
string $algorithm,
array $attributeNameValueDictionary
) {
array_push($this->fieldArguments, $fieldName, 'VECTOR', $algorithm, count($attributeNameValueDictionary));
$this->fieldArguments = array_merge($this->fieldArguments, $attributeNameValueDictionary);
}
/**
* {@inheritDoc}
*/
public function toArray(): array
{
return $this->fieldArguments;
}
}
+8 -5
View File
@@ -12,6 +12,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\SchemaFields\FieldInterface;
use Predis\Command\Command as RedisCommand;
class FTALTER extends RedisCommand
@@ -24,16 +25,18 @@ class FTALTER extends RedisCommand
public function setArguments(array $arguments)
{
[$index, $schema] = $arguments;
$commandArguments = [];
$commandArguments = (!empty($arguments[2])) ? $arguments[2]->toArray() : [];
if (!empty($arguments[2])) {
$commandArguments = $arguments[2]->toArray();
}
$schema = array_reduce($schema, static function (array $carry, FieldInterface $field) {
return array_merge($carry, $field->toArray());
}, []);
array_unshift($schema, 'SCHEMA', 'ADD');
parent::setArguments(array_merge(
[$index],
$commandArguments,
$schema->toArray()
$schema
));
}
}
+8 -1
View File
@@ -12,6 +12,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\SchemaFields\FieldInterface;
use Predis\Command\Command as RedisCommand;
/**
@@ -31,10 +32,16 @@ class FTCREATE extends RedisCommand
[$index, $schema] = $arguments;
$commandArguments = (!empty($arguments[2])) ? $arguments[2]->toArray() : [];
$schema = array_reduce($schema, static function (array $carry, FieldInterface $field) {
return array_merge($carry, $field->toArray());
}, []);
array_unshift($schema, 'SCHEMA');
parent::setArguments(array_merge(
[$index],
$commandArguments,
$schema->toArray()
$schema
));
}
}
+1 -1
View File
@@ -57,7 +57,7 @@ class Connections implements OptionInterface
* The factory instance is configured according to the supplied named array
* mapping URI schemes (passed as keys) to the FCQN of classes implementing
* Predis\Connection\NodeConnectionInterface, or callable objects acting as
* lazy initalizers and returning new instances of classes implementing
* lazy initializers and returning new instances of classes implementing
* Predis\Connection\NodeConnectionInterface.
*
* @param OptionsInterface $options Client options
@@ -98,16 +98,6 @@ class CreateArgumentsTest extends TestCase
$this->assertSame(['SCORE_FIELD', 'score_field'], $this->arguments->toArray());
}
/**
* @return void
*/
public function testCreatesArgumentsWithPayloadFieldModifier(): void
{
$this->arguments->payloadField('payload_field');
$this->assertSame(['PAYLOAD_FIELD', 'payload_field'], $this->arguments->toArray());
}
/**
* @return void
*/
@@ -133,9 +123,9 @@ class CreateArgumentsTest extends TestCase
*/
public function testCreatesArgumentsWithTemporaryModifier(): void
{
$this->arguments->temporary();
$this->arguments->temporary(1);
$this->assertSame(['TEMPORARY'], $this->arguments->toArray());
$this->assertSame(['TEMPORARY', 1], $this->arguments->toArray());
}
/**
@@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
use PHPUnit\Framework\TestCase;
class GeoFieldTest extends TestCase
{
/**
* @dataProvider geoFieldsProvider
* @param array $arguments
* @param array $expectedSchema
* @return void
*/
public function testReturnsCorrectFieldArgumentsArray(
array $arguments,
array $expectedSchema
): void {
$this->assertSame($expectedSchema, (new GeoField(...$arguments))->toArray());
}
public function geoFieldsProvider(): array
{
return [
'with default arguments' => [
['field_name'],
['field_name', 'GEO'],
],
'with alias' => [
['field_name', 'fn'],
['field_name', 'AS', 'fn', 'GEO'],
],
'with sortable - no UNF' => [
['field_name', '', AbstractField::SORTABLE],
['field_name', 'GEO', 'SORTABLE'],
],
'with sortable - with UNF' => [
['field_name', '', AbstractField::SORTABLE_UNF],
['field_name', 'GEO', 'SORTABLE', 'UNF'],
],
'with NOINDEX modifier' => [
['field_name', '', AbstractField::NOT_SORTABLE, true],
['field_name', 'GEO', 'NOINDEX'],
],
];
}
}
@@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
use PHPUnit\Framework\TestCase;
class NumericFieldTest extends TestCase
{
/**
* @dataProvider numericFieldsProvider
* @param array $arguments
* @param array $expectedSchema
* @return void
*/
public function testReturnsCorrectFieldArgumentsArray(
array $arguments,
array $expectedSchema
): void {
$this->assertSame($expectedSchema, (new NumericField(...$arguments))->toArray());
}
public function numericFieldsProvider(): array
{
return [
'with default arguments' => [
['field_name'],
['field_name', 'NUMERIC'],
],
'with alias' => [
['field_name', 'fn'],
['field_name', 'AS', 'fn', 'NUMERIC'],
],
'with sortable - no UNF' => [
['field_name', '', AbstractField::SORTABLE],
['field_name', 'NUMERIC', 'SORTABLE'],
],
'with sortable - with UNF' => [
['field_name', '', AbstractField::SORTABLE_UNF],
['field_name', 'NUMERIC', 'SORTABLE', 'UNF'],
],
'with NOINDEX modifier' => [
['field_name', '', AbstractField::NOT_SORTABLE, true],
['field_name', 'NUMERIC', 'NOINDEX'],
],
];
}
}
@@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
use PHPUnit\Framework\TestCase;
class TagFieldTest extends TestCase
{
/**
* @dataProvider tagFieldsProvider
* @param array $arguments
* @param array $expectedSchema
* @return void
*/
public function testReturnsCorrectFieldArgumentsArray(
array $arguments,
array $expectedSchema
): void {
$this->assertSame($expectedSchema, (new TagField(...$arguments))->toArray());
}
public function tagFieldsProvider(): array
{
return [
'with default arguments' => [
['field_name'],
['field_name', 'TAG'],
],
'with alias' => [
['field_name', 'fn'],
['field_name', 'AS', 'fn', 'TAG'],
],
'with sortable - no UNF' => [
['field_name', '', AbstractField::SORTABLE],
['field_name', 'TAG', 'SORTABLE'],
],
'with sortable - with UNF' => [
['field_name', '', AbstractField::SORTABLE_UNF],
['field_name', 'TAG', 'SORTABLE', 'UNF'],
],
'with NOINDEX modifier' => [
['field_name', '', AbstractField::NOT_SORTABLE, true],
['field_name', 'TAG', 'NOINDEX'],
],
];
}
}
@@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
use PHPUnit\Framework\TestCase;
class TextFieldTest extends TestCase
{
/**
* @dataProvider textFieldsProvider
* @param array $arguments
* @param array $expectedSchema
* @return void
*/
public function testReturnsCorrectFieldArgumentsArray(
array $arguments,
array $expectedSchema
): void {
$this->assertSame($expectedSchema, (new TextField(...$arguments))->toArray());
}
public function textFieldsProvider(): array
{
return [
'with default arguments' => [
['field_name'],
['field_name', 'TEXT'],
],
'with alias' => [
['field_name', 'fn'],
['field_name', 'AS', 'fn', 'TEXT'],
],
'with sortable - no UNF' => [
['field_name', '', AbstractField::SORTABLE],
['field_name', 'TEXT', 'SORTABLE'],
],
'with sortable - with UNF' => [
['field_name', '', AbstractField::SORTABLE_UNF],
['field_name', 'TEXT', 'SORTABLE', 'UNF'],
],
'with NOINDEX modifier' => [
['field_name', '', AbstractField::NOT_SORTABLE, true],
['field_name', 'TEXT', 'NOINDEX'],
],
];
}
}
@@ -0,0 +1,28 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search\SchemaFields;
use PHPUnit\Framework\TestCase;
class VectorFieldTest extends TestCase
{
/**
* @return void
*/
public function testReturnsCorrectFieldArgumentsArray(): void
{
$this->assertSame(
['field_name', 'VECTOR', 'FLAT', 2, 'attribute_name', 'attribute_value'],
(new VectorField('field_name', 'FLAT', ['attribute_name', 'attribute_value']))->toArray());
}
}
@@ -1,227 +0,0 @@
<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Argument\Search;
use PHPUnit\Framework\TestCase;
class SchemaTest extends TestCase
{
/**
* @var Schema
*/
private $schema;
protected function setUp(): void
{
$this->schema = new Schema();
}
/**
* @dataProvider textFieldsProvider
* @param array $arguments
* @param array $expectedSchema
* @return void
*/
public function testAddsTextFieldToSchemaConfiguration(
array $arguments,
array $expectedSchema
): void {
$this->schema->addTextField(...$arguments);
$this->assertSame($expectedSchema, $this->schema->toArray());
}
/**
* @dataProvider tagFieldsProvider
* @param array $arguments
* @param array $expectedSchema
* @return void
*/
public function testAddsTagFieldToSchemaConfiguration(
array $arguments,
array $expectedSchema
): void {
$this->schema->addTagField(...$arguments);
$this->assertSame($expectedSchema, $this->schema->toArray());
}
/**
* @dataProvider numericFieldsProvider
* @param array $arguments
* @param array $expectedSchema
* @return void
*/
public function testAddsNumericFieldToSchemaConfiguration(
array $arguments,
array $expectedSchema
): void {
$this->schema->addNumericField(...$arguments);
$this->assertSame($expectedSchema, $this->schema->toArray());
}
/**
* @dataProvider geoFieldsProvider
* @param array $arguments
* @param array $expectedSchema
* @return void
*/
public function testAddsGeoFieldToSchemaConfiguration(
array $arguments,
array $expectedSchema
): void {
$this->schema->addGeoField(...$arguments);
$this->assertSame($expectedSchema, $this->schema->toArray());
}
/**
* @return void
*/
public function testAddsVectorFieldToSchemaConfiguration(): void
{
$this->schema->addVectorField('field_name', 'FLAT', ['attribute_name', 'attribute_value']);
$this->assertSame(
['SCHEMA', 'field_name', 'VECTOR', 'FLAT', 2, 'attribute_name', 'attribute_value'],
$this->schema->toArray()
);
}
/**
* @return void
*/
public function testCreatesCorrectSchemaConfigurationOnMethodsChainCall(): void
{
$expectedSchema = [
'SCHEMA', 'text_field', 'AS', 'txtf', 'TEXT', 'SORTABLE',
'tag_field', 'AS', 'tf', 'TAG', 'SORTABLE',
'numeric_field', 'AS', 'nf', 'NUMERIC', 'SORTABLE',
'geo_field', 'AS', 'gf', 'GEO', 'SORTABLE',
'vector_field', 'VECTOR', 'FLAT', 2, 'attribute_name', 'attribute_value',
];
$this->schema->addTextField('text_field', 'txtf', true);
$this->schema->addTagField('tag_field', 'tf', true);
$this->schema->addNumericField('numeric_field', 'nf', true);
$this->schema->addGeoField('geo_field', 'gf', true);
$this->schema->addVectorField('vector_field', 'FLAT', ['attribute_name', 'attribute_value']);
$this->assertSame($expectedSchema, $this->schema->toArray());
}
public function geoFieldsProvider(): array
{
return [
'with default arguments' => [
['field_name'],
['SCHEMA', 'field_name', 'GEO'],
],
'with alias' => [
['field_name', 'fn'],
['SCHEMA', 'field_name', 'AS', 'fn', 'GEO'],
],
'with sortable - no UNF' => [
['field_name', '', Schema::SORTABLE],
['SCHEMA', 'field_name', 'GEO', 'SORTABLE'],
],
'with sortable - with UNF' => [
['field_name', '', Schema::SORTABLE_UNF],
['SCHEMA', 'field_name', 'GEO', 'SORTABLE', 'UNF'],
],
'with NOINDEX modifier' => [
['field_name', '', Schema::NOT_SORTABLE, true],
['SCHEMA', 'field_name', 'GEO', 'NOINDEX'],
],
];
}
public function numericFieldsProvider(): array
{
return [
'with default arguments' => [
['field_name'],
['SCHEMA', 'field_name', 'NUMERIC'],
],
'with alias' => [
['field_name', 'fn'],
['SCHEMA', 'field_name', 'AS', 'fn', 'NUMERIC'],
],
'with sortable - no UNF' => [
['field_name', '', Schema::SORTABLE],
['SCHEMA', 'field_name', 'NUMERIC', 'SORTABLE'],
],
'with sortable - with UNF' => [
['field_name', '', Schema::SORTABLE_UNF],
['SCHEMA', 'field_name', 'NUMERIC', 'SORTABLE', 'UNF'],
],
'with NOINDEX modifier' => [
['field_name', '', Schema::NOT_SORTABLE, true],
['SCHEMA', 'field_name', 'NUMERIC', 'NOINDEX'],
],
];
}
public function textFieldsProvider(): array
{
return [
'with default arguments' => [
['field_name'],
['SCHEMA', 'field_name', 'TEXT'],
],
'with alias' => [
['field_name', 'fn'],
['SCHEMA', 'field_name', 'AS', 'fn', 'TEXT'],
],
'with sortable - no UNF' => [
['field_name', '', Schema::SORTABLE],
['SCHEMA', 'field_name', 'TEXT', 'SORTABLE'],
],
'with sortable - with UNF' => [
['field_name', '', Schema::SORTABLE_UNF],
['SCHEMA', 'field_name', 'TEXT', 'SORTABLE', 'UNF'],
],
'with NOINDEX modifier' => [
['field_name', '', Schema::NOT_SORTABLE, true],
['SCHEMA', 'field_name', 'TEXT', 'NOINDEX'],
],
];
}
public function tagFieldsProvider(): array
{
return [
'with default arguments' => [
['field_name'],
['SCHEMA', 'field_name', 'TAG'],
],
'with alias' => [
['field_name', 'fn'],
['SCHEMA', 'field_name', 'AS', 'fn', 'TAG'],
],
'with sortable - no UNF' => [
['field_name', '', Schema::SORTABLE],
['SCHEMA', 'field_name', 'TAG', 'SORTABLE'],
],
'with sortable - with UNF' => [
['field_name', '', Schema::SORTABLE_UNF],
['SCHEMA', 'field_name', 'TAG', 'SORTABLE', 'UNF'],
],
'with NOINDEX modifier' => [
['field_name', '', Schema::NOT_SORTABLE, true],
['SCHEMA', 'field_name', 'TAG', 'NOINDEX'],
],
];
}
}
@@ -13,7 +13,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\CreateArguments;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
@@ -72,10 +72,9 @@ class FTALIASADD_Test extends PredisCommandTestCase
$arguments = new CreateArguments();
$arguments->prefix(['prefix:']);
$arguments->language('english');
$arguments->language();
$schema = new Schema();
$schema->addTextField('text_field');
$schema = [new TextField('text_field')];
$createResponse = $redis->ftcreate('index', $schema, $arguments);
$this->assertEquals('OK', $createResponse);
@@ -110,10 +109,9 @@ class FTALIASADD_Test extends PredisCommandTestCase
$arguments = new CreateArguments();
$arguments->prefix(['prefix:']);
$arguments->language('english');
$arguments->language();
$schema = new Schema();
$schema->addTextField('text_field');
$schema = [new TextField('text_field')];
$createResponse = $redis->ftcreate('index', $schema, $arguments);
$this->assertEquals('OK', $createResponse);
@@ -12,7 +12,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
@@ -69,8 +69,7 @@ class FTALIASDEL_Test extends PredisCommandTestCase
{
$redis = $this->getClient();
$schema = new Schema();
$schema->addTextField('field_name');
$schema = [new TextField('text_field')];
$this->assertEquals('OK', $redis->ftcreate('index', $schema));
$this->assertEquals('OK', $redis->ftaliasadd('alias', 'index'));
@@ -12,7 +12,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
@@ -69,8 +69,7 @@ class FTALIASUPDATE_Test extends PredisCommandTestCase
{
$redis = $this->getClient();
$schema = new Schema();
$schema->addTextField('text_field');
$schema = [new TextField('text_field')];
$createResponse = $redis->ftcreate('index', $schema);
$this->assertEquals('OK', $createResponse);
@@ -88,8 +87,7 @@ class FTALIASUPDATE_Test extends PredisCommandTestCase
{
$redis = $this->getClient();
$schema = new Schema();
$schema->addTextField('text_field');
$schema = [new TextField('text_field')];
$createResponse = $redis->ftcreate('index', $schema);
$this->assertEquals('OK', $createResponse);
@@ -13,7 +13,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\AlterArguments;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
@@ -68,13 +68,11 @@ class FTALTER_Test extends PredisCommandTestCase
{
$redis = $this->getClient();
$schema = new Schema();
$schema->addTextField('field_name');
$schema = [new TextField('field_name')];
$this->assertEquals('OK', $redis->ftcreate('index', $schema));
$schema = new Schema(true);
$schema->addTextField('new_field_name');
$schema = [new TextField('new_field_name')];
$this->assertEquals('OK', $redis->ftalter('index', $schema));
}
@@ -91,18 +89,18 @@ class FTALTER_Test extends PredisCommandTestCase
$this->expectException(ServerException::class);
$this->expectExceptionMessage('Unknown index name');
$redis->ftalter('alias', (new Schema())->addTextField('field_name'));
$redis->ftalter('alias', [new TextField('field_name')]);
}
public function argumentsProvider(): array
{
return [
'with default arguments' => [
['index', (new Schema(true))->addTextField('text_field')],
['index', [new TextField('text_field')]],
['index', 'SCHEMA', 'ADD', 'text_field', 'TEXT'],
],
'with SKIPINITIALSCAN modifier' => [
['index', (new Schema(true))->addTextField('text_field'), (new AlterArguments())->skipInitialScan()],
['index', [new TextField('text_field')], (new AlterArguments())->skipInitialScan()],
['index', 'SKIPINITIALSCAN', 'SCHEMA', 'ADD', 'text_field', 'TEXT'],
],
];
@@ -13,7 +13,9 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\CreateArguments;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\NumericField;
use Predis\Command\Argument\Search\SchemaFields\TagField;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Redis\PredisCommandTestCase;
/**
@@ -67,16 +69,17 @@ class FTCREATE_Test extends PredisCommandTestCase
{
$redis = $this->getClient();
$schema = [
new TextField('first', 'fst', true, true),
new TextField('last'),
new NumericField('age'),
];
$arguments = new CreateArguments();
$arguments->prefix(['prefix:', 'prefix1:']);
$arguments->filter('@age>16');
$arguments->stopWords(['hello', 'world']);
$schema = new Schema();
$schema->addTextField('first', 'fst', true, true);
$schema->addTextField('last');
$schema->addNumericField('age');
$actualResponse = $redis->ftcreate('index', $schema, $arguments);
$this->assertEquals('OK', $actualResponse);
@@ -86,80 +89,80 @@ class FTCREATE_Test extends PredisCommandTestCase
{
return [
'without arguments' => [
['index', (new Schema())->addTextField('field_name')],
['index', [new TextField('field_name')]],
['index', 'SCHEMA', 'field_name', 'TEXT'],
],
'with ON modifier - HASH' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->on('hash')],
['index', [new TextField('field_name')], (new CreateArguments())->on()],
['index', 'ON', 'HASH', 'SCHEMA', 'field_name', 'TEXT'],
],
'with ON modifier - JSON' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->on('json')],
['index', [new TextField('field_name')], (new CreateArguments())->on('JSON')],
['index', 'ON', 'JSON', 'SCHEMA', 'field_name', 'TEXT'],
],
'with prefixes' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->prefix(['prefix1:', 'prefix2:'])],
['index', [new TextField('field_name')], (new CreateArguments())->prefix(['prefix1:', 'prefix2:'])],
['index', 'PREFIX', 2, 'prefix1:', 'prefix2:', 'SCHEMA', 'field_name', 'TEXT'],
],
'with FILTER' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->filter('@age>16')],
['index', [new TextField('field_name')], (new CreateArguments())->filter('@age>16')],
['index', 'FILTER', '@age>16', 'SCHEMA', 'field_name', 'TEXT'],
],
'with LANGUAGE' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->language('english')],
['index', [new TextField('field_name')], (new CreateArguments())->language()],
['index', 'LANGUAGE', 'english', 'SCHEMA', 'field_name', 'TEXT'],
],
'with LANGUAGE_FIELD' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->languageField('language_attribute')],
['index', [new TextField('field_name')], (new CreateArguments())->languageField('language_attribute')],
['index', 'LANGUAGE_FIELD', 'language_attribute', 'SCHEMA', 'field_name', 'TEXT'],
],
'with SCORE' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->score(1.0)],
['index', [new TextField('field_name')], (new CreateArguments())->score()],
['index', 'SCORE', 1.0, 'SCHEMA', 'field_name', 'TEXT'],
],
'with SCORE_FIELD' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->scoreField('score_attribute')],
['index', [new TextField('field_name')], (new CreateArguments())->scoreField('score_attribute')],
['index', 'SCORE_FIELD', 'score_attribute', 'SCHEMA', 'field_name', 'TEXT'],
],
'with PAYLOAD_FIELD' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->payloadField('payload_attribute')],
['index', 'PAYLOAD_FIELD', 'payload_attribute', 'SCHEMA', 'field_name', 'TEXT'],
],
'with MAXTEXTFIELDS' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->maxTextFields()],
['index', [new TextField('field_name')], (new CreateArguments())->maxTextFields()],
['index', 'MAXTEXTFIELDS', 'SCHEMA', 'field_name', 'TEXT'],
],
'with TEMPORARY' => [
['index', [new TextField('field_name')], (new CreateArguments())->temporary(1)],
['index', 'TEMPORARY', 1, 'SCHEMA', 'field_name', 'TEXT'],
],
'with NOOFFSETS' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->noOffsets()],
['index', [new TextField('field_name')], (new CreateArguments())->noOffsets()],
['index', 'NOOFFSETS', 'SCHEMA', 'field_name', 'TEXT'],
],
'with NOHL' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->noHl()],
['index', [new TextField('field_name')], (new CreateArguments())->noHl()],
['index', 'NOHL', 'SCHEMA', 'field_name', 'TEXT'],
],
'with NOFIELDS' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->noFields()],
['index', [new TextField('field_name')], (new CreateArguments())->noFields()],
['index', 'NOFIELDS', 'SCHEMA', 'field_name', 'TEXT'],
],
'with NOFREQS' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->noFreqs()],
['index', [new TextField('field_name')], (new CreateArguments())->noFreqs()],
['index', 'NOFREQS', 'SCHEMA', 'field_name', 'TEXT'],
],
'with STOPWORDS' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->stopWords(['word1', 'word2'])],
['index', [new TextField('field_name')], (new CreateArguments())->stopWords(['word1', 'word2'])],
['index', 'STOPWORDS', 2, 'word1', 'word2', 'SCHEMA', 'field_name', 'TEXT'],
],
'with SKIPINITIALSCAN' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->skipInitialScan()],
['index', [new TextField('field_name')], (new CreateArguments())->skipInitialScan()],
['index', 'SKIPINITIALSCAN', 'SCHEMA', 'field_name', 'TEXT'],
],
'with chain of arguments' => [
['index', (new Schema())->addTextField('field_name'), (new CreateArguments())->on('hash')->prefix(['prefix1:', 'prefix2:'])->filter('@age>16')],
['index', [new TextField('field_name')], (new CreateArguments())->on()->prefix(['prefix1:', 'prefix2:'])->filter('@age>16')],
['index', 'ON', 'HASH', 'PREFIX', 2, 'prefix1:', 'prefix2:', 'FILTER', '@age>16', 'SCHEMA', 'field_name', 'TEXT'],
],
'with multiple fields schema' => [
['index', (new Schema())->addTextField('field_name')->addNumericField('numeric_field')->addTagField('tag_field', 'tf'), (new CreateArguments())->on('hash')],
['index', 'ON', 'HASH', 'SCHEMA', 'field_name', 'TEXT', 'numeric_field', 'NUMERIC', 'tag_field', 'AS', 'tf', 'TAG'],
['index', [new TextField('text_field'), new NumericField('numeric_field'), new TagField('tag_field', 'tf')], (new CreateArguments())->on()],
['index', 'ON', 'HASH', 'SCHEMA', 'text_field', 'TEXT', 'numeric_field', 'NUMERIC', 'tag_field', 'AS', 'tf', 'TAG'],
],
];
}
@@ -13,7 +13,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\DropArguments;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
@@ -68,8 +68,7 @@ class FTDROPINDEX_Test extends PredisCommandTestCase
{
$redis = $this->getClient();
$schema = new Schema();
$schema->addTextField('text_field');
$schema = [new TextField('text_field')];
$this->assertEquals('OK', $redis->ftcreate('index', $schema));
$this->assertEquals('OK', $redis->ftdropindex('index'));
@@ -13,7 +13,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\CreateArguments;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
@@ -72,10 +72,9 @@ class FTINFO_Test extends PredisCommandTestCase
$arguments = new CreateArguments();
$arguments->prefix(['prefix:']);
$arguments->language('english');
$arguments->language();
$schema = new Schema();
$schema->addTextField('text_field');
$schema = [new TextField('text_field')];
$createResponse = $redis->ftcreate('index', $schema, $arguments);
$this->assertEquals('OK', $createResponse);
@@ -13,7 +13,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\ProfileArguments;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
@@ -114,11 +114,11 @@ class FTPROFILE_Test extends PredisCommandTestCase
{
return [
'with SEARCH context' => [
['index', (new Schema())->addTextField('text_field')],
['index', [new TextField('text_field')]],
['index', (new ProfileArguments())->search()->query('hello world')],
],
'with AGGREGATE context' => [
['index', (new Schema())->addTextField('text_field')],
['index', [new TextField('text_field')]],
['index', (new ProfileArguments())->aggregate()->query('hello world')],
],
];
@@ -13,7 +13,8 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\CreateArguments;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\NumericField;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Argument\Search\SearchArguments;
use Predis\Command\Redis\PredisCommandTestCase;
@@ -73,9 +74,7 @@ class FTSEARCH_Test extends PredisCommandTestCase
$createArguments->on('json');
$createArguments->prefix(['doc:']);
$schema = new Schema();
$schema->addNumericField('$..arr', 'arr');
$schema->addTextField('$..val', 'val');
$schema = [new NumericField('$..arr', 'arr'), new TextField('$..val', 'val')];
$ftCreateResponse = $redis->ftcreate('idx', $schema, $createArguments);
$this->assertEquals('OK', $ftCreateResponse);
@@ -103,9 +102,10 @@ class FTSEARCH_Test extends PredisCommandTestCase
$ftCreateArguments = new CreateArguments();
$ftCreateArguments->prefix(['doc:']);
$schema = new Schema();
$schema->addTextField('field1', 'should_return');
$schema->addTextField('field2', 'should_not_return');
$schema = [
new TextField('field1', 'should_return'),
new TextField('field2', 'should_not_return'),
];
$ftCreateResponse = $redis->ftcreate('idx', $schema, $ftCreateArguments);
$this->assertEquals('OK', $ftCreateResponse);
@@ -13,7 +13,7 @@
namespace Predis\Command\Redis\Search;
use InvalidArgumentException;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Argument\Search\SpellcheckArguments;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
@@ -72,8 +72,8 @@ class FTSPELLCHECK_Test extends PredisCommandTestCase
$this->assertEquals('OK', $redis->ftcreate(
'index',
(new Schema())->addTextField('text_field'))
);
[new TextField('text_field')]
));
$this->assertEquals(2, $redis->ftdictadd('dict', 'hello', 'help'));
@@ -12,7 +12,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
@@ -72,7 +72,7 @@ class FTSYNDUMP_Test extends PredisCommandTestCase
$this->assertEquals(
'OK',
$redis->ftcreate('index', (new Schema())->addTextField('text_field'))
$redis->ftcreate('index', [new TextField('text_field')])
);
$this->assertEquals(
@@ -12,7 +12,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\TextField;
use Predis\Command\Argument\Search\SynUpdateArguments;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
@@ -70,7 +70,7 @@ class FTSYNUPDATE_Test extends PredisCommandTestCase
$this->assertEquals(
'OK',
$redis->ftcreate('index', (new Schema())->addTextField('text'))
$redis->ftcreate('index', [new TextField('text')])
);
$this->assertEquals(
@@ -90,7 +90,7 @@ class FTSYNUPDATE_Test extends PredisCommandTestCase
$this->assertEquals(
'OK',
$redis->ftcreate('index', (new Schema())->addTextField('text'))
$redis->ftcreate('index', [new TextField('text')])
);
$this->assertEquals(
@@ -13,7 +13,7 @@
namespace Predis\Command\Redis\Search;
use Predis\Command\Argument\Search\CreateArguments;
use Predis\Command\Argument\Search\Schema;
use Predis\Command\Argument\Search\SchemaFields\TagField;
use Predis\Command\Redis\PredisCommandTestCase;
use Predis\Response\ServerException;
@@ -75,7 +75,7 @@ class FTTAGVALS_Test extends PredisCommandTestCase
'OK',
$redis->ftcreate(
'index',
(new Schema())->addTagField('tag_field'),
[new TagField('tag_field')],
(new CreateArguments())->prefix(['prefix:'])
)
);