Skip to content

Fix Summary and Highlight always active [#26] #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Redis/Command/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
;
Expand Down
4 changes: 2 additions & 2 deletions src/Redis/Command/SearchCommand/HighlightOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Redis/Command/SearchCommand/SummarizeOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
16 changes: 16 additions & 0 deletions tests/Redis/Command/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}