2016-03-10 102 views
0

我是elasticsearch中的新成員,我想在其中使用分頁。如何在彈性搜索中使用Laravel進行分頁5

我正在使用和大小。我現在總共有10條記錄,並且我從0到5和5到大小。我得到5個結果。但如何給鏈接查看頁面,以及如何增加第二頁的記錄?

我的查詢:

 $params = [ 
       'index' => 'my_index', 
       'type' => 'product', 
       'body' => [ 
        "sort" =>[ 
           ["default_product_low_price.sale_price" => ["order" => $sort]] 
          ], 
        "from" => 0, "size" =>5, 
        'query'=> $query, 
        ] 
       ]; 
      $response = \Es::Search($params); 

這是我的查詢現在哪裏給分頁鏈接?

+0

你試過了嗎?{!! $ variable-> links()!!}? –

+0

是的,先生我已經嘗試過,但它顯示如下錯誤:「調用成員函數鏈接()陣列」 –

+0

我把{!! $ item ['hits'] - > links()!!}是不是? –

回答

0

在儲存庫

 $params['size'] = $per_page; 
$params['from'] = $from; 
$params['index'] = config('elastic.Admin_Logs'); 
$params['type'] = config('elastic.Admin_Type'); 
$params['body']['sort']['default_product_low_price.sale_price']['order'] = "desc"; 
$params['body']['query']['filtered']['filter']['bool']['must'][]['match_all'] = []; 

$response = \Es::Search($params); 
$access = $response['hits']; 
     return $access; 

在控制器I設置$ per_page和$從

$per_page = $request->get('limit', 10); 
    $from = ($request->get('page', 1) - 1) * $per_page; 
    $access = $this->repository->Index($per_page, $from); 

    $admin_exceptions = new LengthAwarePaginator(
      $access['hits'], 
      $access['total'], 
      $per_page, 
      Paginator::resolveCurrentPage(), 
      ['path' => Paginator::resolveCurrentPath()]); 
return view('adminexception.index', compact('admin_exceptions'))->withInput($request->all()); 

和現在使用渲染在視圖{{!! $ admin_exceptions->渲染()! }}