在實現織夢站內搜索過程中,我們不想讓某些欄目下的文章被檢索出來,此時需要對織夢dedecms進行二次開發,主要實現方法有以下兩種:
一、打開include/arc.searchview.class.php,找到以下代碼(大概在第450行):
$cquery = "SELECT * FROM `{$this->AddTable}` arc WHERE ".$this->AddSql;
換成
$cquery = "Select * From `dede_archives` arc where arc.typeid not in (1,2,3...) and {$this->AddSql}";
找到以下代碼(大概在第661行):
//搜索
$query = "SELECT arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,
act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath
FROM `dede_archives` arc LEFT JOIN `dede_arctype` act ON arc.typeid=act.id
WHERE arc.id IN ($aids)";
換成
//搜索
$query = "Select arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule,
act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath
from `dede_archives` arc left join `dede_arctype` act on arc.typeid=act.id
where act.id not in (4,5,,6....) and {$this->AddSql} $ordersql limit $limitstart,$row";
這樣就可以屏蔽掉不需要被檢索的欄目了。
二、我們還可以利用另外一個思路,直接在搜索頁面里設置我們需要被檢索的欄目即可,打開plus/search.php,找到以下代碼(大概在第107行):
$sp = new SearchView($typeid,$keyword,$orderby,$channeltype,$searchtype,$starttime,$pagesize,$kwtype,$mid);
換成
$typeid=1;
$sp = new SearchView($typeid,$keyword,$orderby,$channeltype,$searchtype,$starttime,$pagesize,$kwtype,$mid);
數字即代表我們需要指定的欄目ID,這樣就可以實現搜索指定的欄目了。
如果是要搜索某個內容模型中的文章,其他模型都不參與搜索,那么只需打開plus/search.php,找到以下代碼(大概在第17行):
$channeltype = (isset($channeltype) && is_numeric($channeltype)) ? $channeltype : 0;
其中$channeltype就是指定搜索的內容模型,默認為0即搜索全部模型,我們需要將最后的數字修改為對應的內容模型即可。