MoreLikeThisQuery   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getType() 0 4 1
A toArray() 0 12 3
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
namespace ONGR\ElasticsearchDSL\Query\Specialized;
13
14
use ONGR\ElasticsearchDSL\BuilderInterface;
15
use ONGR\ElasticsearchDSL\ParametersTrait;
16
17
/**
18
 * Represents Elasticsearch "more_like_this" query.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html
21
 */
22
class MoreLikeThisQuery implements BuilderInterface
23
{
24
    use ParametersTrait;
25
26
    /**
27
     * @var string The text to find documents like it, required if ids or docs are not specified.
28
     */
29
    private $like;
30
31
    /**
32
     * @param string $like
33
     * @param array  $parameters
34
     */
35
    public function __construct($like, array $parameters = [])
36
    {
37
        $this->like = $like;
38
        $this->setParameters($parameters);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getType()
45
    {
46
        return 'more_like_this';
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function toArray()
53
    {
54
        $query = [];
55
56
        if (($this->hasParameter('ids') === false) || ($this->hasParameter('docs') === false)) {
57
            $query['like'] = $this->like;
58
        }
59
60
        $output = $this->processArray($query);
61
62
        return [$this->getType() => $output];
63
    }
64
}
65