在网站开发过程中,我们可能会遇到需要屏蔽某些栏目下的文章不被检索的情况。针对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表示搜索全部模型。根据需求,将最后的数字修改为对应的内容模型即可。
以上方法可以帮助开发者灵活控制DedeCMS的搜索功能,满足不同场景下的需求。