Completed
Push — master ( 0d45ed...ea3502 )
by Nicolas
02:38
created

src/Rescore/Query.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Elastica\Rescore;
4
5
use Elastica\Query as BaseQuery;
6
7
/**
8
 * Query Rescore.
9
 *
10
 * @author Jason Hu <[email protected]>
11
 *
12
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-rescore.html
13
 */
14
class Query extends AbstractRescore
15
{
16
    /**
17
     * Constructor.
18
     *
19
     * @param \Elastica\Query\AbstractQuery|string $query
20
     */
21
    public function __construct($query = null)
22
    {
23
        $this->setParam('query', []);
24
        $this->setRescoreQuery($query);
0 ignored issues
show
It seems like $query defined by parameter $query on line 21 can also be of type null; however, Elastica\Rescore\Query::setRescoreQuery() does only seem to accept object<Elastica\Query>|o...y\AbstractQuery>|string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
25
    }
26
27
    /**
28
     * Override default implementation so params are in the format
29
     * expected by elasticsearch.
30
     *
31
     * @return array Rescore array
32
     */
33
    public function toArray(): array
34
    {
35
        $data = $this->getParams();
36
37
        if (!empty($this->_rawParams)) {
38
            $data = \array_merge($data, $this->_rawParams);
39
        }
40
41
        $array = $this->_convertArrayable($data);
42
43
        if (isset($array['query']['rescore_query']['query'])) {
44
            $array['query']['rescore_query'] = $array['query']['rescore_query']['query'];
45
        }
46
47
        return $array;
48
    }
49
50
    /**
51
     * Sets rescoreQuery object.
52
     *
53
     * @param \Elastica\Query|\Elastica\Query\AbstractQuery|string $rescoreQuery
54
     *
55
     * @return $this
56
     */
57
    public function setRescoreQuery($rescoreQuery): Query
58
    {
59
        $rescoreQuery = BaseQuery::create($rescoreQuery);
60
61
        $query = $this->getParam('query');
62
        $query['rescore_query'] = $rescoreQuery;
63
64
        return $this->setParam('query', $query);
65
    }
66
67
    /**
68
     * Sets query_weight.
69
     *
70
     * @return $this
71
     */
72 View Code Duplication
    public function setQueryWeight(float $weight): Query
73
    {
74
        $query = $this->getParam('query');
75
        $query['query_weight'] = $weight;
76
77
        return $this->setParam('query', $query);
78
    }
79
80
    /**
81
     * Sets rescore_query_weight.
82
     *
83
     * @return $this
84
     */
85 View Code Duplication
    public function setRescoreQueryWeight(float $weight): Query
86
    {
87
        $query = $this->getParam('query');
88
        $query['rescore_query_weight'] = $weight;
89
90
        return $this->setParam('query', $query);
91
    }
92
}
93