Completed
Push — master ( 5ad7ea...0c833f )
by Ema
02:22
created

Wildcard::setRewrite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Elastica\Query;
4
5
/**
6
 * Wildcard query.
7
 *
8
 * @author Nicolas Ruflin <[email protected]>
9
 *
10
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html
11
 */
12
class Wildcard extends AbstractQuery
13
{
14
    /**
15
     * Rewrite methods: @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-term-rewrite.html.
16
     */
17
    public const REWRITE_CONSTANT_SCORE = 'constant_score';
18
    public const REWRITE_CONSTANT_SCORE_BOOLEAN = 'constant_score_boolean';
19
    public const REWRITE_SCORING_BOOLEAN = 'scoring_boolean';
20
21
    /**
22
     * @var string
23
     */
24
    private $field;
25
26
    public function __construct(string $field, string $value, float $boost = 1.0)
27
    {
28
        $this->field = $field;
29
30
        $this->setParam($field, [
31
            'value' => $value,
32
            'boost' => $boost,
33
        ]);
34
    }
35
36
    public function getField(): string
37
    {
38
        return $this->field;
39
    }
40
41
    public function setValue(string $value): self
42
    {
43
        $data = $this->getParam($this->field);
44
        $this->setParam($this->field, \array_merge($data, ['value' => $value]));
45
46
        return $this;
47
    }
48
49
    public function setBoost(float $boost): self
50
    {
51
        $data = $this->getParam($this->field);
52
        $this->setParam($this->field, \array_merge($data, ['boost' => $boost]));
53
54
        return $this;
55
    }
56
57
    /**
58
     * Set the method used to rewrite the query.
59
     * Use one of the Wildcard::REWRITE_* constants, or provide your own.
60
     *
61
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-term-rewrite.html
62
     */
63
    public function setRewrite(string $rewriteMode): self
64
    {
65
        $data = $this->getParam($this->field);
66
        $this->setParam($this->field, \array_merge($data, ['rewrite' => $rewriteMode]));
67
68
        return $this;
69
    }
70
}
71