2017-04-19 51 views
0

好吧,讓Laravel 4.2; MariaDB的; ectLaravel 4.2不回覆查看:: make

試圖查詢一個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中在正確的表和數據庫中;一切安好。但是,當我嘗試查詢「測試」它返回「找不到結果」;即使我清楚地看到它。

Idk如果這有幫助;但這裏有一個我感興趣的分析器部分: 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));