Skip to content

Commit 963d99c

Browse files
committed
Add reset method for builders
1 parent fc7d920 commit 963d99c

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased v2.x]
88

9+
### Added
10+
11+
- `reset` method for builder (`\MacFJA\RediSearch\IndexBuilder` and `\MacFJA\RediSearch\Query\Builder`)
12+
913
## [2.0.1]
1014

1115
### Fixed

src/IndexBuilder.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,30 @@ public function __call(string $name, array $arguments): self
147147
throw new BadMethodCallException(sprintf('Call undefined %s method', $name));
148148
}
149149

150+
public function reset(): self
151+
{
152+
$this->index = null;
153+
$this->structure = null;
154+
$this->prefixes = [];
155+
$this->filter = null;
156+
$this->defaultLanguage = null;
157+
$this->languageField = null;
158+
$this->defaultScore = null;
159+
$this->scoreField = null;
160+
$this->payloadField = null;
161+
$this->maxTextFields = false;
162+
$this->temporary = null;
163+
$this->noOffsets = false;
164+
$this->noHighLight = false;
165+
$this->noFields = false;
166+
$this->noFrequencies = false;
167+
$this->skipInitialScan = false;
168+
$this->stopWords = null;
169+
$this->fields = [];
170+
171+
return $this;
172+
}
173+
150174
public function setNoStopWords(): self
151175
{
152176
$this->stopWords = [];
@@ -168,6 +192,8 @@ public function create(Client $client, string $rediSearchVersion = AbstractComma
168192
{
169193
$command = $this->getCommand($rediSearchVersion);
170194

195+
$this->reset();
196+
171197
return $client->execute($command);
172198
}
173199

src/Query/Builder.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,24 @@
3030
use MacFJA\RediSearch\Query\Builder\TagFacet;
3131
use MacFJA\RediSearch\Query\Builder\TextFacet;
3232

33+
/**
34+
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
35+
*/
3336
class Builder implements QueryElement, QueryElementGroup
3437
{
3538
/** @var AndGroup */
3639
private $group;
3740

3841
public function __construct()
42+
{
43+
$this->reset();
44+
}
45+
46+
public function reset(): self
3947
{
4048
$this->group = new AndGroup();
49+
50+
return $this;
4151
}
4252

4353
public function addTextFacet(string $field, string ...$values): self
@@ -97,7 +107,10 @@ public function addElement(QueryElement $element): QueryElementGroup
97107

98108
public function render(?callable $escaper = null): string
99109
{
100-
return $this->group->render(null);
110+
$rendered = $this->group->render(null);
111+
$this->reset();
112+
113+
return $rendered;
101114
}
102115

103116
public function priority(): int

0 commit comments

Comments
 (0)