新聞中心
Discuz X3.1全站文章全文檢索的實(shí)現(xiàn)方法
今天無(wú)憂主機(jī)小編分享的這個(gè)全站文章全文檢索方法是直接通過(guò)like來(lái)實(shí)現(xiàn)的,這個(gè)方法比較適用于中小型網(wǎng)站。以下操作方法discuz版本為20140101的X3.1。具體方法如下: 首先,這是通過(guò)對(duì)文件修改添加代碼來(lái)實(shí)現(xiàn)功能的,所以我們需要準(zhǔn)備FTP工具,和高級(jí)記事本(notepad++)。 第一步:連接FTP工具,到指定網(wǎng)站程序目錄下找到文件:\source\class\table\table_portal_article_content.php,找到后,郵件傳輸?shù)奖镜?,用Notepad打開(kāi)編輯; 第二步:在該文件內(nèi)添加代碼: 在這段代碼: class table_portal_article_content extends discuz_table { 下面新增如下代碼: public function fetch_all_by_sql($where, $order = '', $start = 0, $limit = 0, $count = 0, $alias = '') { $where = $where && !is_array($where) ? " WHERE $where" : ''; if(is_array($order)) { $order = ''; } if($count) { return DB::result_first('SELECT count(*) FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order)); } return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order)); } 新增完代碼以后,上面添加那個(gè)方法才能用$query = C::t(‘portal_article_content’)->fetch_all_by_sql。 第三步:把\source\module\search\search_portal.php文件下載到本地,編輯搜索一下代碼: </p> <p> foreach($query as $article) { $ids .= ','.$article['aid']; $num++; } 找到這段代碼以后,在后面添加以下代碼: if($num==0){ list($srchtxt, $srchtxtsql) = searchkey($keyword, "content LIKE '%{text}%'", true); $query = C::t('portal_article_content')->fetch_all_by_sql(' 1 '.$srchtxtsql, 'ORDER BY aid DESC ', 0, $_G['setting']['search']['portal']['maxsearchresults']); foreach($query as $article) { $ids .= ','.$article['aid']; $num++; } } 兩個(gè)文件都修改成功以后,就可以保存并上傳到空間上面去了,原來(lái)的文件,可以在文件重命名。(直接覆蓋也是可以的,但是小編不推薦。) 以上新增兩段代碼的意思是:如果搜文章標(biāo)題沒(méi)搜到,那就用like來(lái)搜文章的內(nèi)容。 兩個(gè)文件都上傳到了空間程序指定目錄下后,登陸DZ網(wǎng)站后臺(tái)更新下discuz的緩存,然后清空一下瀏覽器緩存,搜文章里的內(nèi)容試試,如果能搜到,那么無(wú)憂主機(jī)小編送你五個(gè)字:“那都不是事”。
本文地址:http://www.love62.cn/discuz/14943.html
![1](/wp-content/themes/starow_z/img/o-1.png)
![1](/wp-content/themes/starow_z/img/o-2.png)
![1](/wp-content/themes/starow_z/img/o-3.png)
![1](/wp-content/themes/starow_z/img/o-4.png)
![1](/wp-content/themes/starow_z/img/o-5.png)
![1](/wp-content/themes/starow_z/img/o-6.png)
![1](/wp-content/themes/starow_z/img/o-7.png)