Skip to content

Commit b3d9e06

Browse files
committed
Add documentation test for query prefix
1 parent d29e95e commit b3d9e06

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/Query/Builder/Prefix.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
namespace MacFJA\RediSearch\Query\Builder;
2323

24-
use function call_user_func;
25-
use function is_callable;
24+
use MacFJA\RediSearch\Query\Escaper;
2625

2726
class Prefix implements QueryElement
2827
{
@@ -36,11 +35,7 @@ public function __construct(string $prefix)
3635

3736
public function render(?callable $escaper = null): string
3837
{
39-
if (is_callable($escaper)) {
40-
return call_user_func($escaper, $this->prefix).'*';
41-
}
42-
43-
return $this->prefix.'*';
38+
return Escaper::escapeWord($this->prefix).'*';
4439
}
4540

4641
public function priority(): int

tests/Query/BuilderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,22 @@ public function testDocGeoExample1(): void
192192
));
193193
}
194194

195+
/**
196+
* @see https://oss.redis.com/redisearch/Query_Syntax/#prefix_matching
197+
*/
198+
public function testDocPrefixExample1(): void
199+
{
200+
$expected = 'hel* world';
201+
$builder = new Builder();
202+
203+
$builder
204+
->addElement(new Builder\Prefix('hel'))
205+
->addString('world')
206+
;
207+
208+
static::assertSame($expected, $builder->render());
209+
}
210+
195211
/**
196212
* @see https://oss.redislabs.com/redisearch/Query_Syntax/#fuzzy_matching
197213
*/

0 commit comments

Comments
 (0)