Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Laravel 5中实现Sphinx搜索分页_Php_Laravel_Search_Pagination_Sphinx - Fatal编程技术网

Php 如何在Laravel 5中实现Sphinx搜索分页

Php 如何在Laravel 5中实现Sphinx搜索分页,php,laravel,search,pagination,sphinx,Php,Laravel,Search,Pagination,Sphinx,我已经在Laravel 5中实现了。现在,我想对它实现分页。我没有得到任何帮助,而拉维尔5帕尼特也没有参与斯芬克斯的搜索 这是我的密码: public function index() { $sphinx = new SphinxSearch(); $results = $sphinx->search('php','jobma1')->query()->paginate(5); //geting error :( $results = $sphinx->

我已经在Laravel 5中实现了。现在,我想对它实现分页。我没有得到任何帮助,而拉维尔5帕尼特也没有参与斯芬克斯的搜索

这是我的密码:

public function index() {
   $sphinx = new SphinxSearch();
   $results = $sphinx->search('php','jobma1')->query()->paginate(5); //geting error :(
   $results = $sphinx->search('php','jobma1')->query(); //working fine :)
   dd($results); die;
}
请让我知道如何在Laravel 5中对Sphinx搜索执行分页

在控制器中

 $page = 1
    $queryString = $request->all();
    if (isset($queryString['page'])) { $page = $queryString['page']; }
    if ($page > 0) { $startFrom = ($page-1) * $numRecPerPage; }
    $startFrom = 0;
    $numRecPerPage = 6;
    $sphinx = new SphinxSearch();
    $sphinx->setMatchMode('SPH_MATCH_BOOLEAN');
    $sphinx->search('php Developer software ', 'jobma1');
    // Limit parameters (Number of records display, start from )
    // If first parameter 10 then 10 records will display
    // If second parameter is 5 then first 5 records will not display = display from 6 
    $result =  $sphinx->limit($numRecPerPage, $startFrom)->query();
看来

<?php //dd($result);?>
<?php if (isset($result['matches'])) { ?>
    <table>
        <tr style="text-align:left">
            <th style= "width:100px;">
                ID
            <th>
            <th>
                Post Name
            </th>
        </tr>
        <tbody>
        <?php
            foreach ($result['matches'] as $key => $value) {
                echo '<tr>';
                    echo '<td>'; echo $key; echo '<td>';
                    echo '<td>'; echo $value['attrs']['jobma_post_name']; echo '<td>';
                echo '<tr>';
            }
        ?>
        </tbody>
    </table>
    <?php
        // Pagination Logic start from here
        $totalRecords = $result['total_found'];
        if ($totalRecords > $numRecPerPage) {
            $totalPages = ceil($totalRecords / $numRecPerPage);
            $startLoop = 1;
             $endLoop = $totalPages;
            if ( $totalPages > 6) {
                $endLoop = 6;
            }
            $page = $_GET['page'];
            $endPage = $page+1;
            if ($page >= 4) {
                $startLoop = $page - 3;
                $endLoop = $page + 3;
                if ($endLoop > $totalPages) {
                    $startLoop = $totalPages - 6;
                    $endLoop = $totalPages;
                }
                if ($startLoop < 1) {
                    $startLoop = 1;

                }
            }
            if ($page > 1) {
                $prePage = $page - 1;
                echo "<a href='users?page=1'>".'<<'."</a> ";
                echo "<a href='users?page=$prePage'>".'<'."</a> ";
            }
            for ($i=$startLoop; $i<=$endLoop; $i++) { 
                $class ="";

                if ($i == $page) { $class ="class='activeClass'"; }

                if ($page == $i ) { echo "<a href='javascript:void(0);' $class> ".$i; } else { echo "<a href='users?page=".$i."' $class> ".$i; }

                if ($i < $endLoop) { echo  "  </a> ";  } else { echo "</a>"; }
            }
            if ($endPage <= $totalPages  ) {
                echo "<a href='users?page=$endPage'>".'>'."</a> "; // Goto last page
                echo "<a href='users?page=$totalPages'>".'>>'."</a> ";
            }
            echo '<br/>';
            echo '<br/>';
        }
        echo 'Total Number of Records: '. $totalRecords;
        // Pagination Logic end from here
    ?>
    <style>
    a { background: none repeat scroll 0 0 #FFD700; border: 1px solid #FFD700; margin: 0 3px 2px; padding: 2px 3px 0; text-decoration: none; }
    a.activeClass { color:green; font-weight: bolder; }
    </style>
<?php } else {  ?>
    No records found
<?php } ?>

身份证件
邮名
{背景:无重复滚动0 0#FFD700;边框:1px实心#FFD700;边距:0 3px 2px;填充:2px 3px 0;文本装饰:无;}
a、 activeClass{颜色:绿色;字体重量:粗体;}
没有发现任何记录

一种更简单的方法是使用
照明\Pagination\LengthAwarePaginator

public function doSearch()
{
    $template = 'search/search_results';
    $filters = Input::get('filter');
    $currentPage = Input::get('page') ? Input::get('page') : 1;
    $perPage = 5;
    // prepare $sphinxQuery using the filters received
    $results = SphinxSearch::search($sphinxQuery, 'indexname')
        ->setFieldWeights(
            array(
                    'name' => 10,
            )
        )
        ->setMatchMode(SphinxClient::SPH_MATCH_EXTENDED)
        ->setSortMode(SphinxClient::SPH_SORT_EXTENDED, "name ASC")
        ->limit(1000)
        ->get(true);
    $paginator = new LengthAwarePaginator(
        collect($results)->forPage($currentPage, $perPage), sizeof($results), $perPage, $currentPage
    );
    $paginator->setPath(route('name.of.the.route'));
    $paginator->setPageName('page');  
    $data['items'] = $paginator;  

    return View::make($template, $data);
}
在刀片模板中:

<?php echo $items->appends(['filter' => Request::get('filter')])->render(); ?>