Completed
Pull Request — master (#1894)
by
unknown
03:26
created

Wildcard::setCaseInsensitive()   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, bool $caseInsensitive = false)
27
    {
28
        $this->field = $field;
29
30
        $this->setParam($field, [
31
            'value' => $value,
32
            'boost' => $boost,
33
            'case_insensitive' => $caseInsensitive,
34
        ]);
35
    }
36
37
    public function getField(): string
38
    {
39
        return $this->field;
40
    }
41
42
    public function setValue(string $value): self
43
    {
44
        $data = $this->getParam($this->field);
45
        $this->setParam($this->field, \array_merge($data, ['value' => $value]));
46
47
        return $this;
48
    }
49
50
    public function setBoost(float $boost): self
51
    {
52
        $data = $this->getParam($this->field);
53
        $this->setParam($this->field, \array_merge($data, ['boost' => $boost]));
54
55
        return $this;
56
    }
57
58
    /**
59
     * Set the method used to rewrite the query.
60
     * Use one of the Wildcard::REWRITE_* constants, or provide your own.
61
     *
62
     * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-term-rewrite.html
63
     */
64
    public function setRewrite(string $rewriteMode): self
65
    {
66
        $data = $this->getParam($this->field);
67
        $this->setParam($this->field, \array_merge($data, ['rewrite' => $rewriteMode]));
68
69
        return $this;
70
    }
71
72
    public function setCaseInsensitive(bool $caseInsensitive): self
73
    {
74
        $data = $this->getParam($this->field);
75
        $this->setParam($this->field, \array_merge($data, ['case_insensitive' => $caseInsensitive]));
76
77
        return $this;
78
    }
79
}
80