| Conditions | 3 |
| Paths | 2 |
| Total Lines | 22 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | public function actionIndex() |
||
| 23 | { |
||
| 24 | $this->setJsonHeader(); |
||
| 25 | // get search query as string from request |
||
| 26 | $query = $this->request->query->get('query', null); |
||
| 27 | if (Str::likeEmpty($query) || Str::length($query) < 2) { |
||
| 28 | throw new JsonException('Short query'); |
||
| 29 | } |
||
| 30 | |||
| 31 | // initialize basic search model |
||
| 32 | $model = new EntitySearchMain($query, ['itemPerApp' => 3]); |
||
| 33 | $model->make(); |
||
| 34 | |||
| 35 | // build response by relevance as array |
||
| 36 | $response = $model->getRelevanceSortedResult(); |
||
| 37 | |||
| 38 | return json_encode([ |
||
| 39 | 'status' => 1, |
||
| 40 | 'count' => count($response), |
||
| 41 | 'data' => $response |
||
| 42 | ]); |
||
| 43 | } |
||
| 44 | } |