Joomla!-开源天空

2008-12-05
首页 专栏热点 Joomla! 源代码分析 让Joomla! 支持中文全文检索,搜索结果分页


让Joomla! 支持中文全文检索,搜索结果分页

E-mail

在这搜索结果分页中,使用本站开发的分页类,如有兴趣请看:发布一个自由处理分页的Joomla!类

使用这个类,其实搜索结果分页非常简单,大体代码如下:

  $limitstart = JRequest::getVar('start', 0, '', 'int');
  $limit =10;
  $pagination = null; 
  JRequest::setVar('limit', (int) $limit); 
  $items = array();
  $searchword = JRequest::getVar('searchword');
    if(! empty($searchword)) {
      Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Phpbean_Lucene_Analyzer());
        $index = new Zend_Search_Lucene('/tmp/search');
    $Query = Zend_Search_Lucene_Search_QueryParser::parse($searchword,'utf-8');
        $hits = $index->find($Query);
        $total = count($hits);
               
        $pagination = new JPagebar($total, $limitstart, $limit);
        $i = 0;
        foreach ($hits as $hit) {
          if($i>=$limitstart && $i<$limitstart+$limit){
             $items[$i]->title=JString::str_ireplace($searchword,'<font color="CC0033">'.$searchword."</font>",$hit->title);
             $items[$i]->content=JString::str_ireplace($searchword,'<font color="CC0033">'.$searchword."</font>",JString::substr($hit->content,0,200));
             $items[$i]->href=JRoute::_(ContentHelperRoute::getArticleRoute($hit->slug, $hit->catslug, $hit->sectionid));
          }           
            $i++;
        }
       
    }
 

我们看到第一部分代码主要是组织一些初始参数,$total = count($hits); 取得了记录总数,就可以生成分页对象了:

$pagination = new JPagebar($total, $limitstart, $limit);

将这个对象传递给模板文件,在模板文件中:

<?php echo $this->pagination->getPagesLinks( ); ?>

这样就实现了搜索结果的分页。

相关文章:
zend_mail使用例程
自动生成Joomla!文章的TAG标签
Zend_DB读取Joomla!文章表的例程
Zend Framework获得Jolt 大奖
修改mod_search以支持中文全文检索组件com_lsearch
Zend_Lucene中文全文检索Joomla!组件com_lsearch
看到了织梦分词算法,打算用来改进一下ZEND
让Joomla! 支持中文全文检索,中文分词的排错
让Joomla! 支持中文全文检索,搜索结果反显
让Joomla! 支持中文全文检索,利用索引查询


收藏此文章:
Digg! Reddit! Del.icio.us! JoomlaVote! Google! Live! Facebook! StumbleUpon! Yahoo! Free social bookmarking plugins and extensions for Joomla! websites!

发表您的文章评论

您的姓名 (昵称)
标题:
评分: 很差一般较好很好
评论:
验证码:
请输入验证码