Skip to content
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

Add terms boost param #2035

Merged
merged 3 commits into from
Dec 3, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added `allow_duplicates` option to `append` processor [#2004](https://github.com/ruflin/Elastica/pull/2004)
* Added `bytes` processor [#2008](https://github.com/ruflin/Elastica/pull/2008)
* Added `indices_boost` option to `Elastica\Query` [#2018](https://github.com/ruflin/Elastica/pull/2018)
* Added `Elastica\Query\Terms::setBoost()` method to configure boost [#2035](https://github.com/ruflin/Elastica/pull/2035)
### Changed
* Triggered deprecation in `Elastica\Result::getType()` method [#2016](https://github.com/ruflin/Elastica/pull/2016)
* Updated `php-cs-fixer` to `3.3.2` [#2022](https://github.com/ruflin/Elastica/pull/2022)
Expand Down
5 changes: 5 additions & 0 deletions src/Query/Terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ public function setTermsLookup(string $index, string $id, string $path): self
'path' => $path,
]);
}

public function setBoost(float $boost): self
{
return $this->setParam('boost', $boost);
}
}
19 changes: 19 additions & 0 deletions tests/Query/TermsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ public function testSetTermsLookup(): void
$this->assertSame($expected, $query->toArray());
}

/**
* @group unit
*/
public function testSetBoost(): void
{
$expected = [
'terms' => [
'name' => ['foo', 'bar'],
'boost' => 2.0,
],
];

$query = (new Terms('name', ['foo', 'bar']))
->setBoost(2.0)
;

$this->assertSame($expected, $query->toArray());
}

/**
* @group unit
*/
Expand Down