Completed
Push — master ( c0d232...67b20e )
by Olivier
43:39 queued 05:10
created

DisMaxQuery::tie_breaker()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace olvlvl\ElasticsearchDSL\Query\Compound;
4
5
use olvlvl\ElasticsearchDSL\Query\Option\BoostOption;
6
use olvlvl\ElasticsearchDSL\Query\Option\HasBoostOption;
7
use olvlvl\ElasticsearchDSL\Query\QueryAbstract;
8
use olvlvl\ElasticsearchDSL\Query\QueryCollection;
9
10
/**
11
 * @property-read QueryCollection $queries
12
 */
13
class DisMaxQuery extends QueryAbstract implements HasBoostOption
14
{
15
	use BoostOption;
16
17
	const NAME = 'dis_max';
18
19
	const OPTION_TIE_BREAKER = 'tie_breaker';
20
21
	const OPTIONS = [
22
23
		self::OPTION_TIE_BREAKER,
24
		self::OPTION_BOOST,
25
26
	];
27
28
	/**
29
	 * @var QueryCollection
30
	 */
31
	private $queries;
32
33
	protected function get_queries(): QueryCollection
34
	{
35
		return $this->queries;
36
	}
37
38
	public function __construct(array $options = [])
39
	{
40
		$this->queries = new QueryCollection;
0 ignored issues
show
Bug introduced by
The property queries is declared read-only in olvlvl\ElasticsearchDSL\Query\Compound\DisMaxQuery.
Loading history...
41
42
		parent::__construct($options + [
43
44
			self::OPTION_TIE_BREAKER => 1.0
45
46
		]);
47
	}
48
49
	public function tie_breaker(float $tie_breaker)
50
	{
51
		$this->options[self::OPTION_TIE_BREAKER] = $tie_breaker;
0 ignored issues
show
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
52
53
		return $this;
54
	}
55
56
	public function jsonSerialize()
57
	{
58
		return [ self::NAME => parent::jsonSerialize() + [
59
60
			'queries' => $this->queries,
61
62
		] ];
63
	}
64
}
65