Newer
Older
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\DSL\Sort;
/**
* Sort based on custom scripts.
*
* Note, it is recommended, for single custom based script based sorting, to use function_score query instead.
* Sorting based on score is faster.
*/
class ScriptSort extends AbstractSort
{
/**
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
*/
private $returnType;
/**
* Associative array of custom params with values.
*
* Example: ['factor' => 1.5]
*
* @var array
*/
private $params;
/**
* Initializes script sort.
*
* @param string $script
* @param string $returnType
* @param array $params
* @param string $order
*/
public function __construct($script, $returnType, $params = null, $order = self::ORDER_DESC)
{
$this->setParams($params);
$this->setScript($script);
$this->setOrder($order);
$this->setReturnType($returnType);
}
/**
* @return string
*/
public function getReturnType()
{
return $this->returnType;
}
/**
* @param string $returnType
*/
public function setReturnType($returnType)
{
$this->returnType = $returnType;
}
/**
* @return array
*/
public function getParams()
{
return $this->params;
}
/**
* @param array $params
*/
public function setParams($params)
{
$this->params = $params;
}
/**
* @return string
*/
public function getScript()
{
return $this->script;
}
/**
* @param string $script
*/
public function setScript($script)
{
$this->script = $script;
}
/**
* @return string
*/
final public function getType()
{
return '_script';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$value = [];
if ($this->getOrder()) {
$value['order'] = $this->getOrder();
}
$value['script'] = $this->getScript();
if ($this->getParams()) {
$value['params'] = $this->getParams();
}
$value['type'] = $this->getReturnType();
return $value;
}
}