SphotoController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace manager\controllers;
  3. use yii\sphinx\Query;
  4. use yii\widgets\ActiveForm;
  5. use yii\web\Controller;
  6. use yii\web\NotFoundHttpException;
  7. use manager\models\News;
  8. //use \app\models\Sphoto;
  9. use Yii;
  10. class SphotoController extends BaseController
  11. {
  12. public function actionIndex()
  13. {
  14. // $model = new Kd();
  15. // return $this->render('/kd/list', ['model' => $model]);
  16. }
  17. public function actionShow($id)
  18. {
  19. // $post = Yii::$app->request->get();
  20. return $this->renderPartial('/default/Showphoto', ['id' => $id]);
  21. }
  22. public function actionSearch()
  23. {
  24. if( isset( $_GET['search'] ) && trim( $_GET['search'] ) != ''){
  25. $news_query = (new Query())
  26. ->from('amic_photo')
  27. ->select(['id','photo_title'])
  28. ->andWhere( ['photo_name' => ''])
  29. ->addOptions(['max_matches' => 200])
  30. ->addOptions(['field_weights'=> ['photo_title' => 10] ])
  31. ->match($_GET['search'])
  32. ->limit(200);
  33. // ->column();
  34. $news_query = new Query();
  35. $sql = "SELECT `id`, `photo_title` FROM `amic_photo` WHERE (MATCH('".$_GET['search']." amic.ru | смолихина | амител"."')) AND (`photo_name`='') LIMIT 200 OPTION max_matches = 200, field_weights = (photo_title = 10)";
  36. // $command = $news_query->createCommand($sql);
  37. $command = Yii::$app->sphinx->createCommand($sql);
  38. // echo $command->getRawSql();
  39. $items = $command->queryAll();
  40. $r = array();
  41. foreach( $items as $item ){
  42. $r[] = $item;
  43. }
  44. return json_encode(['status'=>'ok','data'=>$r]);
  45. }
  46. return json_encode(['status'=>'err']);
  47. }
  48. }