【问题标题】:How to paginate in elasticsearch with Laravel 5如何使用 Laravel 5 在弹性搜索中进行分页
【发布时间】:2016-06-24 19:14:12
【问题描述】:

我是 elasticsearch 新手,我想在其中使用分页。

我正在使用 from 和 size。我现在总共有 10 条记录,我正在调整 0 到 from 和 5 到 size。我得到 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);

这是我现在的查询在哪里提供分页链接?

【问题讨论】:

  • 你试过{!!$variable->links()!!}吗?
  • 是的,先生,我已经尝试过了,但它显示的错误如下:“调用数组上的成员函数链接()”
  • 我把 {!!$item['hits']->links()!!} 放对了吗?
  • 在这里查看我的答案:stackoverflow.com/questions/35571056/…
  • 谢谢先生,但是如何在视图页面中显示分页链接?

标签: laravel elasticsearch laravel-5 pagination


【解决方案1】:

在仓库中

        $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;

在控制器中我设置了 $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()!!}}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-26
    • 1970-01-01
    • 2017-01-27
    • 2021-08-21
    • 2020-11-28
    相关资源
    最近更新 更多