From 2131ed9f6b89fdfb9732a6fc7c997187d7389df7 Mon Sep 17 00:00:00 2001 From: MacFJA Date: Mon, 23 Aug 2021 20:10:06 +0200 Subject: [PATCH] Fix #12 - Fix exact match not used inside text facet --- CHANGELOG.md | 5 ++++- src/Search/QueryBuilder/ExactMatch.php | 5 +++++ src/Search/QueryBuilder/TextFacet.php | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4c178f..7f55180 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Correclty handle Search result with NoContent flag ([Issue#9], [Issue#10], [PR#13]) - Don't double % in fuzzy search ([Issue#11], [PR#14]) +- Fix exact match not used inside text facet ([Issue#12], [PR#15]) ## [1.3.0] @@ -110,8 +111,10 @@ First version [Issue#9]: https://github.com/MacFJA/php-redisearch/issues/9 [Issue#10]: https://github.com/MacFJA/php-redisearch/issues/10 [Issue#11]: https://github.com/MacFJA/php-redisearch/issues/11 +[Issue#12]: https://github.com/MacFJA/php-redisearch/issues/12 [PR#1]: https://github.com/MacFJA/php-redisearch/pull/1 [PR#3]: https://github.com/MacFJA/php-redisearch/pull/3 [PR#8]: https://github.com/MacFJA/php-redisearch/pull/8 [PR#13]: https://github.com/MacFJA/php-redisearch/pull/13 -[PR#14]: https://github.com/MacFJA/php-redisearch/pull/14 \ No newline at end of file +[PR#14]: https://github.com/MacFJA/php-redisearch/pull/14 +[PR#15]: https://github.com/MacFJA/php-redisearch/pull/15 diff --git a/src/Search/QueryBuilder/ExactMatch.php b/src/Search/QueryBuilder/ExactMatch.php index ff8a5d3..b6fa311 100644 --- a/src/Search/QueryBuilder/ExactMatch.php +++ b/src/Search/QueryBuilder/ExactMatch.php @@ -23,6 +23,7 @@ use MacFJA\RediSearch\Helper\EscapeHelper; use function sprintf; +use function strpos; class ExactMatch implements PartialQuery { @@ -36,6 +37,10 @@ public function __construct(string $match) public function render(): string { + if (false === strpos($this->match, ' ')) { + return EscapeHelper::escapeWord($this->match); + } + return sprintf('"%s"', EscapeHelper::escapeExactMatch($this->match)); } diff --git a/src/Search/QueryBuilder/TextFacet.php b/src/Search/QueryBuilder/TextFacet.php index f9895a3..71dc2cc 100644 --- a/src/Search/QueryBuilder/TextFacet.php +++ b/src/Search/QueryBuilder/TextFacet.php @@ -53,7 +53,7 @@ public function render(): string { if (count($this->orValues) > 1) { $terms = OrGroup::renderNoParentheses(...array_map(function (string $orValue) { - return new Word($orValue); + return new ExactMatch($orValue); }, $this->orValues)); return sprintf(self::WITH_SPACE_PATTERN, EscapeHelper::escapeFieldName($this->field), $terms);