Skip to content

Commit

Permalink
Added test case for enhanced exact matching (#1466)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vladvildanov authored Nov 21, 2024
1 parent 1726db0 commit 52bdcf0
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/Predis/Command/Redis/Search/FTSEARCH_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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', '[email protected]', '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', '[email protected]']);
$ftSearchArguments->dialect(4);

$actualResponse = $redis->ftsearch(
'idx_hash', '@uuid:{$uuid}', $ftSearchArguments
);

$this->assertSame([
1, 'test:1',
['uuid', '3d3586fe-0416-4572-8ce', 'email', '[email protected]', 'num', '5']], $actualResponse
);

$actualResponse = $redis->ftsearch(
'idx_hash', '@email:{$email}', $ftSearchArguments
);

$this->assertSame([
1, 'test:1',
['uuid', '3d3586fe-0416-4572-8ce', 'email', '[email protected]', 'num', '5']], $actualResponse
);

$actualResponse = $redis->ftsearch(
'idx_hash', '@num:[5]', $ftSearchArguments
);

$this->assertSame([
1, 'test:1',
['uuid', '3d3586fe-0416-4572-8ce', 'email', '[email protected]', 'num', '5']], $actualResponse
);
}

/**
* @group connected
* @group relay-resp3
Expand Down

0 comments on commit 52bdcf0

Please sign in to comment.