在Zend Lucene中添加“PAGINATION”在codeigniter中搜索结果

时间:2011-03-16 13:15:40

标签: zend-framework codeigniter pagination zend-search-lucene

嘿,任何人,我尝试将zend lucene搜索系统与codeigniter集成。但问题是如何在Codeigniter

中格式化分页中的搜索结果

下面是搜索代码:

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

请帮帮我朋友

1 个答案:

答案 0 :(得分: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