弹性沙龙中的分页 [英] pagination in elasticsearch laravel

查看:160
本文介绍了弹性沙龙中的分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



搜索代码:

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

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



更新:



我使用和查询大小,但如何在视图页面中提供分页链接?以及如何通过点击页面进行更新?

解决方案

在存储库中

  $ 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和$来自控制器

  $ per_page = $ request-> get('limit',10); 
$ from =($ request-> get('page',1) - 1)* $ per_page;
$ access = $ this-> repository->索引($ 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()!!中使用render) }}


I am using shift31/laravel-elasticsearch:~1.0. I want to implement pagination on my list page.

Search code :

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

How to use pagination in above query ?

Update :

I used from and size in query but how to give pagination link in view page ? and how to update from by click on page ?

解决方案

in repository

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

i set $per_page and $from in controller

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

and now use render in in the views {{!!$admin_exceptions->render()!!}}

这篇关于弹性沙龙中的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆