2016-05-02 5 views
0

Ich habe in Laravel 5 implementiert Sphinx Search Jetzt möchte ich Paginierung auf diese implementieren. Ich habe keine Hilfe bekommen und Laravel 5 paginate arbeitet nicht an Sphinx Search.So implementieren Sie die Paginierung auf Sphinx Search in Laravel 5

Hier ist mein Code:

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

mir bitte mitteilen, wie Paginieren auf Sphinx Search in Laravel 5

Antwort

0

Verwendung dieses

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

In einem Controller implementieren In einer Ansicht

<?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 } ?> 
Verwandte Themen