discuzx3.4文章进行全文检索的实现技巧
发布时间:2021-11-30 18:02:04 所属栏目:PHP教程 来源:互联网
导读:搜索门户中的文章,并不是按这个走的,而且利用sphinx这个啊,要么只能分中文要么只能分英文(学艺不精没细了解啊,个人测试是这样的)。 1.用notepad++或其他文本编辑器打开下述文件 网站目录sourceclasstabletable_portal_article_content.php 2.在下
搜索门户中的文章,并不是按这个走的,而且利用sphinx这个啊,要么只能分中文要么只能分英文(学艺不精没细了解啊,个人测试是这样的)。 1.用notepad++或其他文本编辑器打开下述文件 网站目录sourceclasstabletable_portal_article_content.php 2.在下面的 代码如下: class table_portal_article_content extends discuz_table { 后添加 代码如下: 01 public function fetch_all_by_sql($where, $order = '', $start = 0, $limit = 0, $count = 0, $alias = '') { 02 $where = $where && !is_array($where) ? " WHERE $where" : ''; 03 if(is_array($order)) { 04 $order = ''; 05 } 06 if($count) { 07 return DB::result_first('SELECT count(*) FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order)); 08 } 09 return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order)); 10 } 变为: 代码如下: 01 class table_portal_article_content extends discuz_table 02 { 03 public function fetch_all_by_sql($where, $order = '', $start = 0, $limit = 0, $count = 0, $alias = '') { 04 $where = $where && !is_array($where) ? " WHERE $where" : ''; 05 if(is_array($order)) { 06 $order = ''; 07 } 08 if($count) { 09 return DB::result_first('SELECT count(*) FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order)); 10 } 11 return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order)); 12 } 上面添加那个方法才能用$query = C::t(‘portal_article_content’)->fetch_all_by_sql。 3.打开 网站目录sourcemodulesearchsearch_portal.php 搜索 代码如下: 1 </p> <p> foreach($query as $article) { 2 $ids .= ','.$article['aid']; 3 $num++; 4 } 在其后添加如下代码: 代码如下: 1 if($num==0){ 2 list($srchtxt, $srchtxtsql) = searchkey($keyword, "content LIKE '%{text}%'", true); 3 $query = C::t('portal_article_content')->fetch_all_by_sql(' 1 '.$srchtxtsql, 'ORDER BY aid DESC ', 0, $_G['setting']['search']['portal']['maxsearchresults']); 4 foreach($query as $article) { 5 $ids .= ','.$article['aid']; 6 $num++; 7 } 8 } ![]() (编辑:云计算网_泰州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |