Skip to content

Commit

Permalink
Add terms boost param (#2035)
Browse files Browse the repository at this point in the history
* Add terms boost param

* Add test

* Add changelog
  • Loading branch information
deguif authored Dec 3, 2021
1 parent 857ae36 commit 2e9b223
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
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

0 comments on commit 2e9b223

Please sign in to comment.