Reputation: 197
Hey anyone, i try integrating zend lucene search system with codeigniter. But the problem is how i can formatting the search result in pagination in Codeigniter
below is the search code :
$query//keyword to search
$index = Zend_Search_Lucene::open(DOCROOT . 'data/index'); //opening index
$hits['post']= $index->find($query); //getting the search result
Please help me friends
Upvotes: 0
Views: 1958
Reputation: 11445
Your controller should look like this:
$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);
And your view should look like this
<?php foreach($results as $result):?>
<?=$result->title?>
<?=$result->detail?>
<?=$result->post_date?>
<?php endforeach;?>
<?=$links?>//the pagination links
Upvotes: 4