2017-04-19 9 views
0

좋아요 Laravel 4.2; MariaDB; ectLaravel 4.2 돌아 오지 않는보기 :: make

"test"SQL 문자열을 쿼리하는 중, 내가 만든 이후로 알고있다.

여기 내 SearchController.php 코드입니다 :

// Here search is ok. 
     $start = microtime(true); 
     $items = Project::processSearch('+' . implode(' +', $searchTerms), false, $this->limitPerPage, $page, $this->maxSearchResults); 
     $executionTime = microtime(true) - $start; 
     $total = $items->getTotal(); 

     if($total == 0) 
     { 
      $start = microtime(true); 
      $items = Project::processSearch(implode(' ', $searchTerms), 
       true, $this->limitPerPage, $page, $this->limitPerPage); 
      $executionTime = microtime(true) - $start; 

      $total = $items->getTotal(); 

      if($total > 0) 
      { 
       return View::make('search.results') 
        ->with('items', $items) 
        ->with('executionTime', number_format($executionTime, 4)) 
        ->with('info', "Your query didn't return any result."); 
      } 
     } 

가 여기 내 클래스 코드

public static function processSearch($query, $suggestions, $resultsPerPage, $page, $limit = null) 
{ 
    $slug = Str::slug($query) . '-general'; 
    $slug .= $suggestions ? '-suggestions' : '-exact-search'; 

    $results = Cache::remember($slug, 10, function() use($query, $limit) 
    { 
     $items = Project::whereRaw(
      "MATCH(mixed) AGAINST(? IN BOOLEAN MODE)", 
      array($query) 
     )->take(301); 

     if(Auth::check()) 
     { 
      $items = $items->with(['unlockedItemsUser' => function($query) 
      { 
       $query->where('user_id', '=', Auth::user()->id); 
      }]); 
     } 

     if($limit != null) 
     { 
      $items = $items->limit($limit); 
     } 

     $items = $items->get(); 

     if(count($items) > 0 && is_object($items)) 
     { 
      return $items->all(); 
     } 

     return null; 
    }); 

    if($results != null) 
    { 
     $pages = objectlist_chunk($results, $resultsPerPage); 
     return Paginator::make($pages[$page - 1], count($results), $resultsPerPage); 
    } 

    return Paginator::make(array(), 0, $resultsPerPage); 
} 



public function unlockedItemsUser() 
{ 
    return $this->hasMany('UnlockedItem', 'item_id', 'id'); 
} 

public function newQuery($excludeDeleted = false) 
{ 
    $query = parent::newQuery(); 
    if($excludeDeleted) 
    { 
     $query->where('deleted', '=', '0'); 
    } 
    $query->where('blacklist', '=', 0); 

    return $query; 
} 

}

여기 내 경로

Route::controller('getIndex', 'SearchController'); 
Route::controller('/search', 'SearchController'); 
Route::resource('getIndex', 'SearchController'); 
Route::controller('/user', 'UserController'); 
Route::controller('/maintenance', 'MaintenanceController'); 

내가 문자열을 생성 "테스트 "mysql에서 올바른 테이블과 데이터베이스; 모든 것이 좋습니다. 하지만 "쿼리"를 시도하면 "결과가 없습니다"와 함께 반환됩니다. 심지어 tho 나는 그것을 분명히 본다.

만약 이것이 도움이된다면; 여기 흥미로운 프로파일 러 섹션이 있습니다 : enter image description here

진보 된 감사합니다!

+0

결과가 없으면 아무런 결과가 나타나지 않을 수도 있습니다. 아마도 문제 일 수 있습니다. – Jerodev

+0

그래, 결과가 있어야합니다. "테스트"입니다. 내가 놓친 게 있니? 미안 해요, 아주 지쳐서 2 일 동안 지 냈습니다. 가서 노크. 오전에있을거야. – RayCrush

+0

MySQL의 질문 인 경우 _generated_ SQL 문과 'SHOW CREATE TABLE'을 제공하십시오. –

답변

0

처음 전화가 processSearch 일 때 값을 제공하는 경우보기를 반환하지 않습니다.

$start = microtime(true); 
$items = Project::processSearch('+' . implode(' +', $searchTerms), false, $this->limitPerPage, $page, $this->maxSearchResults); 
$executionTime = microtime(true) - $start; 
$total = $items->getTotal(); 

if($total == 0) 
{ 
    $start = microtime(true); 
    $items = Project::processSearch(implode(' ', $searchTerms), 
     true, $this->limitPerPage, $page, $this->limitPerPage); 
    $executionTime = microtime(true) - $start; 

    $total = $items->getTotal(); 

    if($total > 0) 
    { 
     return View::make('search.results') 
      ->with('items', $items) 
      ->with('executionTime', number_format($executionTime, 4)) 
      ->with('info', "Your query didn't return any result."); 
    } else { 

     return View::make('search.results') 
      ->with('items', $items) 
      ->with('executionTime', number_format($executionTime, 4)) 
      ->with('info', 'There is nothing to show'); 
    } 
} 

return View::make('search.results') 
      ->with('items', $items) 
      ->with('executionTime', number_format($executionTime, 4));