| Conditions | 8 |
| Paths | 2 |
| Total Lines | 36 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php namespace Nord\Lumen\Elasticsearch\Parsers; |
||
| 19 | public function buildSortFromString($string) |
||
| 20 | { |
||
| 21 | $sorts = []; |
||
| 22 | |||
| 23 | if (!empty($string)) { |
||
| 24 | foreach ($this->parse($string) as $item) { |
||
| 25 | |||
| 26 | /* |
||
| 27 | * Position map: |
||
| 28 | * - 0 = field name |
||
| 29 | * - 1 = order (asc/desc) |
||
| 30 | * - 2 = mode (min/max/sum/avg/median) |
||
| 31 | */ |
||
| 32 | |||
| 33 | if (isset($item[0])) { |
||
| 34 | if ($item[0] === '_score') { |
||
| 35 | $sort = new ScoreSort(); |
||
| 36 | } elseif ($item[0] === '_doc') { |
||
| 37 | $sort = new DocSort(); |
||
| 38 | } else { |
||
| 39 | $sort = (new FieldSort())->setField($item[0]); |
||
| 40 | } |
||
| 41 | |||
| 42 | if (isset($item[1])) { |
||
| 43 | $sort->setOrder($item[1]); |
||
| 44 | } |
||
| 45 | if (isset($item[2])) { |
||
| 46 | $sort->setMode($item[2]); |
||
| 47 | } |
||
| 48 | |||
| 49 | $sorts[] = $sort; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | return $sorts; |
||
| 55 | } |
||
| 57 |