Completed
Pull Request — master (#348)
by
unknown
10:14
created

MultiMatchQuery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 51
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ONGR\ElasticsearchDSL\Query\FullText;
15
16
use ONGR\ElasticsearchDSL\BuilderInterface;
17
use ONGR\ElasticsearchDSL\ParametersTrait;
18
19
/**
20
 * Represents Elasticsearch "multi_match" query.
21
 *
22
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html
23
 *
24
 * Allows `$fields` to be an empty array to represent 'no fields'. From the Elasticsearch documentation:
25
 *
26
 * If no fields are provided, the multi_match query defaults to the `index.query.default_field` index settings,
27
 * which in turn defaults to `*`. `*` extracts all fields in the mapping that are eligible to term queries and filters
28
 * the metadata fields. All extracted fields are then combined to build a query.
29
 */
30
class MultiMatchQuery implements BuilderInterface
31
{
32
    use ParametersTrait;
33
34
    public function __construct(
35
        private array $fields,
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_PRIVATE, expecting T_VARIABLE
Loading history...
36
        private string $query,
37
        array $parameters = []
38
    ) {
39
        $this->setParameters($parameters);
40
    }
41
42
    public function getType(): string
43
    {
44
        return 'multi_match';
45
    }
46
47
    public function toArray(): array
48
    {
49
        $query = [
50
            'query' => $this->query,
51
        ];
52
        if (count($this->fields)) {
53
            $query['fields'] = $this->fields;
54
        }
55
56
        $output = $this->processArray($query);
57
58
        return [$this->getType() => $output];
59
    }
60
}
61