1
|
|
|
<?php |
|
|
|
|
2
|
|
|
namespace Triadev\Leopard\Business\Dsl\Query; |
|
|
|
|
3
|
|
|
|
4
|
|
|
use ONGR\ElasticsearchDSL\BuilderInterface; |
5
|
|
|
use ONGR\ElasticsearchDSL\Query\Compound\BoostingQuery; |
6
|
|
|
use ONGR\ElasticsearchDSL\Query\Compound\ConstantScoreQuery; |
7
|
|
|
use ONGR\ElasticsearchDSL\Query\Compound\DisMaxQuery; |
8
|
|
|
use Triadev\Leopard\Business\Dsl\FunctionScore; |
9
|
|
|
use Triadev\Leopard\Business\Dsl\Search; |
10
|
|
|
use Triadev\Leopard\Business\Dsl\AbstractQuery; |
11
|
|
|
|
12
|
|
|
class Compound extends AbstractQuery |
|
|
|
|
13
|
|
|
{ |
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Function score |
16
|
|
|
* |
17
|
|
|
* @param \Closure $search |
|
|
|
|
18
|
|
|
* @param \Closure $functionScore |
|
|
|
|
19
|
|
|
* @param array $params |
|
|
|
|
20
|
|
|
* @return Compound |
|
|
|
|
21
|
|
|
*/ |
22
|
6 |
|
public function functionScore(\Closure $search, \Closure $functionScore, array $params = []) : Compound |
|
|
|
|
23
|
|
|
{ |
24
|
6 |
|
$searchBuilder = app()->make(Search::class); |
25
|
6 |
|
$search($searchBuilder); |
26
|
|
|
|
27
|
6 |
|
$functionScoreBuilder = new FunctionScore($searchBuilder->getQuery(), $params); |
28
|
6 |
|
$functionScore($functionScoreBuilder); |
29
|
|
|
|
30
|
6 |
|
$this->append($functionScoreBuilder->getQuery()); |
31
|
6 |
|
return $this; |
32
|
|
|
} |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constant score |
36
|
|
|
* |
37
|
|
|
* @param \Closure $search |
|
|
|
|
38
|
|
|
* @param array $params |
|
|
|
|
39
|
|
|
* @return Compound |
|
|
|
|
40
|
|
|
*/ |
41
|
1 |
|
public function constantScore(\Closure $search, array $params = []) : Compound |
|
|
|
|
42
|
|
|
{ |
43
|
1 |
|
$searchBuilder = app()->make(Search::class); |
44
|
1 |
|
$search($searchBuilder); |
45
|
|
|
|
46
|
1 |
|
$this->append(new ConstantScoreQuery($searchBuilder->getQuery(), $params)); |
47
|
1 |
|
return $this; |
48
|
|
|
} |
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Boosting |
52
|
|
|
* |
53
|
|
|
* @param BuilderInterface $positive |
|
|
|
|
54
|
|
|
* @param BuilderInterface $negative |
|
|
|
|
55
|
|
|
* @param float $negativeBoost |
|
|
|
|
56
|
|
|
* @return Compound |
|
|
|
|
57
|
|
|
*/ |
58
|
2 |
|
public function boosting( |
59
|
|
|
BuilderInterface $positive, |
60
|
|
|
BuilderInterface $negative, |
61
|
|
|
float $negativeBoost |
62
|
|
|
) : Compound { |
|
|
|
|
63
|
2 |
|
$this->append(new BoostingQuery($positive, $negative, $negativeBoost)); |
64
|
2 |
|
return $this; |
65
|
|
|
} |
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Dis max |
69
|
|
|
* |
70
|
|
|
* @param BuilderInterface[] $queries |
|
|
|
|
71
|
|
|
* @param array $params |
|
|
|
|
72
|
|
|
* @return Compound |
|
|
|
|
73
|
|
|
*/ |
74
|
1 |
|
public function disMax(array $queries, array $params = []) : Compound |
|
|
|
|
75
|
|
|
{ |
76
|
1 |
|
$disMaxQuery = new DisMaxQuery($params); |
77
|
|
|
|
78
|
1 |
|
foreach ($queries as $query) { |
79
|
1 |
|
if ($query instanceof BuilderInterface) { |
80
|
1 |
|
$disMaxQuery->addQuery($query); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
$this->append($disMaxQuery); |
85
|
1 |
|
return $this; |
86
|
|
|
} |
|
|
|
|
87
|
|
|
} |
|
|
|
|
88
|
|
|
|