0

嘿,任何人,我尝试将zend lucene搜索系统与codeigniter集成。但问题是我如何能在笨在Zend Lucene中添加“PAGINATION”在codeigniter中搜索结果

下面

格式化搜索结果分页是搜索代码:

$query//keyword to search     
$index = Zend_Search_Lucene::open(DOCROOT . 'data/index'); //opening index 
$hits['post']= $index->find($query); //getting the search result 

请帮我的朋友

+0

这与kohana有什么关系? – zombor 2011-03-16 13:27:05

回答

4

你的控制器看起来应该是这样:

$this->load->library('pagination'); 
$query_result = $index->find($query); 

$offset = $this->uri->segment(3,0); 
$limit = 10; 

// this is the cool part, which you don't know 
    $set= array();          
    for($i=$offset; $i< $limit + $offset; $i++) 
    { 
     if(array_key_exists($i, $query_result)){ 
      $set[]= $query_result[$i]; 
     }else{ 
      break; 
     } 
    } 
//end of cool part 

$config['base_url'] = base_url().'search/index/'; 
$config['total_rows'] = count($query_result); 
$config['uri_segment'] = 3; 
$config['per_page'] = $limit; 
$config['num_links'] =10; 
$this->pagination->initialize($config); 
$data['links'] = $this->pagination->create_links(); 
$data['results'] = $set;// pass the paginated resulted to the view 
$this->load->view('myview',$data); 

而你的看法应该是这样的

<?php foreach($results as $result):?> 
<?=$result->title?> 
<?=$result->detail?> 
<?=$result->post_date?> 
<?php endforeach;?> 

<?=$links?>//the pagination links