Search.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: chendeben
  5. * Date: 2017/12/6
  6. * Time: 11:50
  7. */
  8. namespace PhpLife\App\Api\Controller;
  9. use PhpLife\App\Api\Package\Database\File;
  10. use PhpLife\App\Api\Package\Database\Hash;
  11. use PhpLife\App\Api\Controller;
  12. use PhpLife\Library\Sphinx;
  13. class Search extends Controller
  14. {
  15. public function main(){
  16. $keyword=$this->getRequest()->string("key");
  17. $p=$this->getRequest()->intval("page",1);
  18. $count=10;
  19. $res=Sphinx::instance()->query($keyword, ($p-1)*$count, $count);
  20. $ids=array_keys($res['matches']);
  21. $result=Hash::select(array(),array('id'=>$ids));
  22. foreach ($result as &$file) {
  23. $temp=File::getOne(array('info_hash'=>$file['info_hash']));
  24. if ($temp){
  25. $temp=json_decode($temp['file_list'],true);
  26. $new=array();
  27. foreach ($temp as $key=>$value){
  28. if (strpos($value['path'], "_____")===false){
  29. $new[]=$value;
  30. }
  31. }
  32. $file['file_list']=$new;
  33. }else{
  34. $file['file_list']=array(array('path'=>$file['name'],'length'=>$file['length']));
  35. }
  36. }
  37. echo json_encode($file);
  38. }
  39. }