1 | <?php namespace Nord\Lumen\Elasticsearch\Search\Sort; |
||
2 | |||
3 | /** |
||
4 | * Allows to add one or more sort on specific fields. Each sort can be reversed as well. The sort is defined on a per |
||
5 | * field level, with special field name for _score to sort by score, and _doc to sort by index order. |
||
6 | * |
||
7 | * The order defaults to desc when sorting on the _score, and defaults to asc when sorting on anything else. |
||
8 | * |
||
9 | * _doc has no real use-case besides being the most efficient sort order. So if you don’t care about the order in which |
||
10 | * documents are returned, then you should sort by _doc. This especially helps when scrolling. |
||
11 | * |
||
12 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html |
||
13 | */ |
||
14 | class DocSort extends AbstractSort |
||
15 | { |
||
16 | /** |
||
17 | * @inheritdoc |
||
18 | */ |
||
19 | public function toArray() |
||
20 | { |
||
21 | $options = $this->applyOptions([]); |
||
22 | |||
23 | if (empty($options)) { |
||
24 | return '_doc'; |
||
0 ignored issues
–
show
|
|||
25 | } else { |
||
26 | return ['_doc' => $options]; |
||
27 | } |
||
28 | } |
||
29 | } |
||
30 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: