From 320589fe0768ca86f25a78dffc95e1fa384d1de8 Mon Sep 17 00:00:00 2001 From: MacFJA Date: Fri, 4 Feb 2022 20:42:54 +0100 Subject: [PATCH] Fix Summary and Highlight always active [#26] --- CHANGELOG.md | 6 ++++++ src/Redis/Command/Search.php | 2 ++ .../Command/SearchCommand/HighlightOption.php | 4 ++-- .../Command/SearchCommand/SummarizeOption.php | 4 ++-- tests/Redis/Command/SearchTest.php | 16 ++++++++++++++++ 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 695cf07..37f60ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased v2.x] +### Fixed + +- Summarize Search option enabled by default (without possibility to disable it) ([Issue#26]) +- Highlight Search option enabled by default (without possibility to disable it) ([Issue#26]) + ## [2.1.0] ### Added @@ -181,6 +186,7 @@ First version [Issue#11]: https://github.com/MacFJA/php-redisearch/issues/11 [Issue#12]: https://github.com/MacFJA/php-redisearch/issues/12 [Issue#16]: https://github.com/MacFJA/php-redisearch/issues/16 +[Issue#26]: https://github.com/MacFJA/php-redisearch/issues/26 [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 diff --git a/src/Redis/Command/Search.php b/src/Redis/Command/Search.php index 1d86c48..aeb8208 100644 --- a/src/Redis/Command/Search.php +++ b/src/Redis/Command/Search.php @@ -146,6 +146,7 @@ public function setWithSortKeys(bool $active = true): self public function setSummarize(?array $fields = null, ?int $fragmentCount = null, ?int $fragmentSize = null, ?string $separator = null): self { $this->options['summarize'] + ->setDataOfOption('type', true) ->setDataOfOption('fields', $fields) ->setDataOfOption('frags', $fragmentCount) ->setDataOfOption('len', $fragmentSize) @@ -163,6 +164,7 @@ public function setSummarize(?array $fields = null, ?int $fragmentCount = null, public function setHighlight(?array $fields, ?string $openTag, ?string $closeTag): self { $this->options['highlight'] + ->setDataOfOption('type', true) ->setDataOfOption('fields', $fields) ->setTags($openTag, $closeTag) ; diff --git a/src/Redis/Command/SearchCommand/HighlightOption.php b/src/Redis/Command/SearchCommand/HighlightOption.php index b81da3f..72f6527 100644 --- a/src/Redis/Command/SearchCommand/HighlightOption.php +++ b/src/Redis/Command/SearchCommand/HighlightOption.php @@ -32,14 +32,14 @@ class HighlightOption extends GroupedOption public function __construct() { parent::__construct([ - 'type' => new FlagOption('HIGHLIGHT', true, '>=2.0.0'), + 'type' => new FlagOption('HIGHLIGHT', false, '>=2.0.0'), 'fields' => new NotEmptyOption(new NumberedOption('FIELDS', null, '>=2.0.0')), 'tag' => new GroupedOption([ 'type' => new FlagOption('TAGS', true, '>=2.0.0'), 'open' => new NamelessOption(null, '>=2.0.0'), 'close' => new NamelessOption(null, '>=2.0.0'), ], ['type', 'open', 'close'], ['type'], '>=2.0.0'), - ], ['type'], ['type'], '>=2.0.0'); + ], ['type'], [], '>=2.0.0'); } public function setTags(?string $open, ?string $close): self diff --git a/src/Redis/Command/SearchCommand/SummarizeOption.php b/src/Redis/Command/SearchCommand/SummarizeOption.php index 6ebebba..fa8cfd4 100644 --- a/src/Redis/Command/SearchCommand/SummarizeOption.php +++ b/src/Redis/Command/SearchCommand/SummarizeOption.php @@ -33,11 +33,11 @@ class SummarizeOption extends GroupedOption public function __construct() { parent::__construct([ - 'type' => new FlagOption('SUMMARIZE', true, '>=2.0.0'), + 'type' => new FlagOption('SUMMARIZE', false, '>=2.0.0'), 'fields' => new NotEmptyOption(new NumberedOption('FIELDS', null, '>=2.0.0')), 'frags' => CV::isNumeric(new NamedOption('FRAGS', null, '>=2.0.0')), 'len' => CV::isNumeric(new NamedOption('LEN', null, '>=2.0.0')), 'separator' => new NamedOption('SEPARATOR', null, '>=2.0.0'), - ], ['type'], ['type'], '>=2.0.0'); + ], ['type'], [], '>=2.0.0'); } } diff --git a/tests/Redis/Command/SearchTest.php b/tests/Redis/Command/SearchTest.php index 47a50d3..440be97 100644 --- a/tests/Redis/Command/SearchTest.php +++ b/tests/Redis/Command/SearchTest.php @@ -126,4 +126,20 @@ public function testFullOption(): void 'LIMIT', 12, 10, ], $command->getArguments()); } + + public function testNoSummarizeAndNoHighlight(): void + { + $command = new Search(AbstractCommand::MAX_IMPLEMENTED_VERSION); + $command + ->setIndex('idx') + ->setQuery('@text1:"hello world"') + ->setLimit(12, 10) + ; + + static::assertSame([ + 'idx', + '@text1:"hello world"', + 'LIMIT', 12, 10, + ], $command->getArguments()); + } }