【问题标题】:pagination in elasticsearch laravelelasticsearch laravel中的分页
【发布时间】:2016-06-13 16:23:41
【问题描述】:

我正在使用 shift31/laravel-elasticsearch:~1.0。我想在我的列表页面上实现分页。

搜索代码:

   $params = [
        'index' => 'my_index',
        'type' => 'product',
        'body' =>  [
                       'query'=>[
                                 'match'=>[
                                           'category'=>$category
                                          ]
                                 ]
                   ];
   ];
  $response = \Es::Search($params);

如何在上述查询中使用分页?

更新:

我在查询中使用了 from 和 size 但如何在视图页面中提供分页链接?以及如何通过点击页面更新?

【问题讨论】:

  • 好的,谢谢詹姆斯。但是如何在查看页面上给出链接,如果我点击分页链接的第 2 3 页怎么办?如果我第一次给 0 到 10。
  • 其实你有没有试过用内置的分页器对结果进行分页。尝试使用$response = \Es::Search($params)->paginate(10);,然后使用$response->render() 将其传递给您的视图以生成分页器。
  • 不,我没有使用它。好的,谢谢,让我试试那个。
  • 告诉我进展如何

标签: laravel elasticsearch pagination


【解决方案1】:

在仓库中

 $params = [
        'index' => 'my_index',
        'type' => 'product',
          'size' = $per_page;
          'from' = $from;
        'body' =>  [
                       'query'=>[
                                 'match'=>[
                                           'category'=>$category
                                          ]
                                 ]
                   ];
   ];

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

我在控制器中设置了 $per_page 和 $from

$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->render()!!}}

【讨论】:

  • 能否分享一下LengthAwarePaginator()函数>?
  • 对不起,你能分享一下你的 LengthAwarePaginator() 函数吗?
  • 你用的是php和larvel吗?
  • 我使用的是 laravel 5.1
  • LengthAwarePaginator() 是 laravel 5.1 包中的预建函数。
猜你喜欢
  • 2021-03-24
  • 2018-06-17
  • 1970-01-01
  • 2016-03-27
  • 1970-01-01
  • 1970-01-01
  • 2016-06-23
  • 1970-01-01
  • 2015-08-12
相关资源
最近更新 更多