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

发布于 2024-10-22 23:48:55 字数 324 浏览 1 评论 0原文

大家好,我尝试将 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

请帮助我朋友

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

近箐 2024-10-29 23:48:55

你的控制器应该是这样的:

$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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文