Conditions | 1 |
Paths | 1 |
Total Lines | 4 |
Code Lines | 2 |
Lines | 0 |
Ratio | 0 % |
Tests | 3 |
CRAP Score | 1 |
Changes | 0 |
Metric | Value |
---|---|
cc | 1 |
eloc | 2 |
nc | 1 |
nop | 1 |
dl | 0 |
loc | 4 |
ccs | 3 |
cts | 3 |
cp | 1 |
crap | 1 |
rs | 10 |
c | 0 |
b | 0 |
f | 0 |
1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | namespace Triadev\Leopard\Business\Dsl; |
||
0 ignored issues
–
show
|
|||
3 | |||
4 | use ONGR\ElasticsearchDSL\BuilderInterface; |
||
5 | use ONGR\ElasticsearchDSL\Query\Compound\FunctionScoreQuery; |
||
6 | |||
7 | class FunctionScore |
||
0 ignored issues
–
show
|
|||
8 | { |
||
0 ignored issues
–
show
|
|||
9 | /** @var FunctionScoreQuery */ |
||
0 ignored issues
–
show
|
|||
10 | private $query; |
||
1 ignored issue
–
show
|
|||
11 | |||
12 | /** |
||
13 | * FunctionScore constructor. |
||
14 | * @param BuilderInterface $query |
||
0 ignored issues
–
show
|
|||
15 | * @param array $params |
||
0 ignored issues
–
show
|
|||
16 | */ |
||
17 | 6 | public function __construct(BuilderInterface $query, array $params = []) |
|
0 ignored issues
–
show
|
|||
18 | { |
||
0 ignored issues
–
show
|
|||
19 | 6 | $this->query = new FunctionScoreQuery($query, $params); |
|
20 | 6 | } |
|
0 ignored issues
–
show
|
|||
21 | |||
22 | /** |
||
23 | * Get query |
||
24 | * |
||
25 | * @return BuilderInterface |
||
26 | */ |
||
27 | 6 | public function getQuery() : BuilderInterface |
|
28 | { |
||
0 ignored issues
–
show
|
|||
29 | 6 | return $this->query; |
|
30 | } |
||
0 ignored issues
–
show
|
|||
31 | |||
32 | /** |
||
33 | * Field |
||
34 | * |
||
35 | * @param string $field |
||
0 ignored issues
–
show
|
|||
36 | * @param float $factor |
||
0 ignored issues
–
show
|
|||
37 | * @param string $modifier |
||
0 ignored issues
–
show
|
|||
38 | * @param \Closure|null $search |
||
0 ignored issues
–
show
|
|||
39 | * @return FunctionScore |
||
0 ignored issues
–
show
|
|||
40 | */ |
||
41 | 1 | public function field( |
|
42 | string $field, |
||
43 | float $factor, |
||
44 | string $modifier = 'none', |
||
0 ignored issues
–
show
|
|||
45 | ?\Closure $search = null |
||
0 ignored issues
–
show
|
|||
46 | ) : FunctionScore { |
||
0 ignored issues
–
show
|
|||
47 | 1 | $this->query->addFieldValueFactorFunction( |
|
48 | 1 | $field, |
|
49 | 1 | $factor, |
|
50 | 1 | $modifier, |
|
51 | 1 | $this->buildQueryFromSearchClosure($search) |
|
52 | ); |
||
53 | |||
54 | 1 | return $this; |
|
55 | } |
||
0 ignored issues
–
show
|
|||
56 | |||
57 | /** |
||
58 | * Decay |
||
59 | * |
||
60 | * @param string $type |
||
0 ignored issues
–
show
|
|||
61 | * @param string $field |
||
0 ignored issues
–
show
|
|||
62 | * @param array $function |
||
0 ignored issues
–
show
|
|||
63 | * @param array $options |
||
0 ignored issues
–
show
|
|||
64 | * @param \Closure|null $search |
||
0 ignored issues
–
show
|
|||
65 | * @param int|null $weight |
||
0 ignored issues
–
show
|
|||
66 | * @return FunctionScore |
||
0 ignored issues
–
show
|
|||
67 | */ |
||
68 | 1 | public function decay( |
|
69 | string $type, |
||
70 | string $field, |
||
71 | array $function, |
||
72 | array $options = [], |
||
0 ignored issues
–
show
|
|||
73 | ?\Closure $search = null, |
||
0 ignored issues
–
show
|
|||
74 | int $weight = null |
||
0 ignored issues
–
show
|
|||
75 | ) : FunctionScore { |
||
0 ignored issues
–
show
|
|||
76 | 1 | $this->query->addDecayFunction( |
|
77 | 1 | $type, |
|
78 | 1 | $field, |
|
79 | 1 | $function, |
|
80 | 1 | $options, |
|
81 | 1 | $this->buildQueryFromSearchClosure($search), |
|
82 | 1 | $weight |
|
83 | ); |
||
84 | |||
85 | 1 | return $this; |
|
86 | } |
||
0 ignored issues
–
show
|
|||
87 | |||
88 | /** |
||
89 | * Weight |
||
90 | * |
||
91 | * @param float $weight |
||
0 ignored issues
–
show
|
|||
92 | * @param \Closure|null $search |
||
0 ignored issues
–
show
|
|||
93 | * @return FunctionScore |
||
0 ignored issues
–
show
|
|||
94 | */ |
||
95 | 1 | public function weight(float $weight, ?\Closure $search = null) : FunctionScore |
|
0 ignored issues
–
show
|
|||
96 | { |
||
0 ignored issues
–
show
|
|||
97 | 1 | $this->query->addWeightFunction($weight, $this->buildQueryFromSearchClosure($search)); |
|
98 | 1 | return $this; |
|
99 | } |
||
0 ignored issues
–
show
|
|||
100 | |||
101 | /** |
||
102 | * Random |
||
103 | * |
||
104 | * @param int|null $seed |
||
0 ignored issues
–
show
|
|||
105 | * @param \Closure|null $search |
||
0 ignored issues
–
show
|
|||
106 | * @return FunctionScore |
||
0 ignored issues
–
show
|
|||
107 | */ |
||
108 | 1 | public function random(?int $seed = null, ?\Closure $search = null) : FunctionScore |
|
0 ignored issues
–
show
|
|||
109 | { |
||
0 ignored issues
–
show
|
|||
110 | 1 | $this->query->addRandomFunction($seed, $this->buildQueryFromSearchClosure($search)); |
|
111 | 1 | return $this; |
|
112 | } |
||
0 ignored issues
–
show
|
|||
113 | |||
114 | /** |
||
115 | * Script |
||
116 | * |
||
117 | * @param string $inline |
||
0 ignored issues
–
show
|
|||
118 | * @param array $params |
||
0 ignored issues
–
show
|
|||
119 | * @param array $options |
||
0 ignored issues
–
show
|
|||
120 | * @param \Closure|null $search |
||
0 ignored issues
–
show
|
|||
121 | * @return FunctionScore |
||
0 ignored issues
–
show
|
|||
122 | */ |
||
123 | 1 | public function script( |
|
124 | string $inline, |
||
125 | array $params = [], |
||
0 ignored issues
–
show
|
|||
126 | array $options = [], |
||
0 ignored issues
–
show
|
|||
127 | ?\Closure $search = null |
||
0 ignored issues
–
show
|
|||
128 | ) : FunctionScore { |
||
0 ignored issues
–
show
|
|||
129 | 1 | $this->query->addScriptScoreFunction( |
|
130 | 1 | $inline, |
|
131 | 1 | $params, |
|
132 | 1 | $options, |
|
133 | 1 | $this->buildQueryFromSearchClosure($search) |
|
134 | ); |
||
135 | |||
136 | 1 | return $this; |
|
137 | } |
||
0 ignored issues
–
show
|
|||
138 | |||
139 | /** |
||
140 | * Simple |
||
141 | * |
||
142 | * @param array $functions |
||
0 ignored issues
–
show
|
|||
143 | * @return FunctionScore |
||
0 ignored issues
–
show
|
|||
144 | */ |
||
145 | 1 | public function simple(array $functions) : FunctionScore |
|
146 | { |
||
0 ignored issues
–
show
|
|||
147 | 1 | $this->query->addSimpleFunction($functions); |
|
148 | 1 | return $this; |
|
149 | } |
||
0 ignored issues
–
show
|
|||
150 | |||
151 | /** |
||
152 | * Build query from search closure |
||
153 | * |
||
154 | * @param \Closure|null $search |
||
0 ignored issues
–
show
|
|||
155 | * @return BuilderInterface|null |
||
0 ignored issues
–
show
|
|||
156 | */ |
||
157 | 5 | private function buildQueryFromSearchClosure(?\Closure $search) : ?BuilderInterface |
|
0 ignored issues
–
show
|
|||
158 | { |
||
0 ignored issues
–
show
|
|||
159 | 5 | $query = null; |
|
0 ignored issues
–
show
|
|||
160 | |||
161 | 5 | if ($search) { |
|
162 | 3 | $searchBuilder = app()->make(Search::class); |
|
163 | 3 | $search($searchBuilder); |
|
164 | |||
165 | 3 | $query = $searchBuilder->getQuery(); |
|
166 | } |
||
167 | |||
168 | 5 | return $query; |
|
169 | } |
||
0 ignored issues
–
show
|
|||
170 | } |
||
0 ignored issues
–
show
|
|||
171 |