From 52bdcf0c1f1197bd4cbb7740a432645b4aa026f0 Mon Sep 17 00:00:00 2001 From: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com> Date: Thu, 21 Nov 2024 20:00:34 +0200 Subject: [PATCH] Added test case for enhanced exact matching (#1466) * Added test case for enhanced exact matching * Added version restriction for test * Updated test case to use Tag Field instead * Codestyle fix * Added edge to stack matrix * Updated test case to switch DIALECT * Updated version restriction --- .../Command/Redis/Search/FTSEARCH_Test.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php b/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php index 5ec55f7f9..06c86000d 100644 --- a/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php +++ b/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php @@ -16,6 +16,7 @@ use Predis\Command\Argument\Search\SchemaFields\AbstractField; use Predis\Command\Argument\Search\SchemaFields\GeoShapeField; use Predis\Command\Argument\Search\SchemaFields\NumericField; +use Predis\Command\Argument\Search\SchemaFields\TagField; use Predis\Command\Argument\Search\SchemaFields\TextField; use Predis\Command\Argument\Search\SearchArguments; use Predis\Command\Redis\PredisCommandTestCase; @@ -127,6 +128,65 @@ public function testSearchValuesByHashIndex(): void $this->assertSame($expectedResponse, $actualResponse); } + /** + * @group connected + * @group relay-resp3 + * @return void + * @requiresRediSearchVersion >= 2.09.00 + */ + public function testSearchWithEnhancedMatchingCapabilities(): void + { + $redis = $this->getClient(); + + $hashResponse = $redis->hmset( + 'test:1', 'uuid', '3d3586fe-0416-4572-8ce', 'email', 'adriano@acme.com.ie', 'num', 5 + ); + $this->assertEquals('OK', $hashResponse); + + $ftCreateArguments = new CreateArguments(); + $ftCreateArguments->prefix(['test:']); + + $schema = [ + new TagField('uuid'), + new TagField('email'), + new NumericField('num'), + ]; + + $ftCreateResponse = $redis->ftcreate('idx_hash', $schema, $ftCreateArguments); + $this->assertEquals('OK', $ftCreateResponse); + + $ftSearchArguments = new SearchArguments(); + $ftSearchArguments->params(['uuid', '3d3586fe-0416-4572-8ce', 'email', 'adriano@acme.com.ie']); + $ftSearchArguments->dialect(4); + + $actualResponse = $redis->ftsearch( + 'idx_hash', '@uuid:{$uuid}', $ftSearchArguments + ); + + $this->assertSame([ + 1, 'test:1', + ['uuid', '3d3586fe-0416-4572-8ce', 'email', 'adriano@acme.com.ie', 'num', '5']], $actualResponse + ); + + $actualResponse = $redis->ftsearch( + 'idx_hash', '@email:{$email}', $ftSearchArguments + ); + + $this->assertSame([ + 1, 'test:1', + ['uuid', '3d3586fe-0416-4572-8ce', 'email', 'adriano@acme.com.ie', 'num', '5']], $actualResponse + ); + + $actualResponse = $redis->ftsearch( + 'idx_hash', '@num:[5]', $ftSearchArguments + ); + + $this->assertSame([ + 1, 'test:1', + ['uuid', '3d3586fe-0416-4572-8ce', 'email', 'adriano@acme.com.ie', 'num', '5']], $actualResponse + ); + } + /** * @group connected * @group relay-resp3