织梦dede搜索实现标题完全精准搜索

2024-01-22 秩名 互联网
浏览

织梦搜索实现标题完全精准搜索,就是搜索文档标题必须一模一样才有搜索结果

1、在 /plus/ 新建一个 so.php 文件

<?php
require_once(dirname(__FILE__) . "/../include/common.inc.php");
require_once DEDEINC . "/arc.partview.class.php";
if ($title == '')
{
    ShowMsg('关键字不能为空!', '-1');
    exit();
}
$row = $dsql->GetOne("SELECT id FROM `dede__archives` WHERE title = '$title' ");
if (is_array($row))
{
    $chRow    = $dsql->GetOne("SELECT c.addtable FROM dede__archives AS a LEFT JOIN dede_channeltype AS c ON a.channel=c.id where a.id='{$row['id']}'");
    $addtable = trim($chRow['addtable']);
    $result   = $dsql->GetOne("SELECT arc.*,addf.* FROM `dede__archives` arc LEFT JOIN `{$addtable}` addf ON arc.id=addf.aid WHERE arc.arcrank>-1 AND arc.id = '{$row['id']}'");
    $pv       = new PartView();
    foreach ($result as $k => $v)
    {
        $pv->Fields[$k] = $v;
    }
    $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $cfg_df_style . "/so.htm");
    $pv->Display();
}
else
{
    ShowMsg('没有相关记录!', '-1');
}
exit();

2、你的模板文件夹里添加1个 so.htm 模板文件

例如 /templets/default/so.htm

<div>
    <p>标题:{dede;field.title /}</p>
    <p>缩略图:{dede;field.litpic /}</p>
    <p>品牌:{dede;field.pinpai /}</p>
    <p>货号:{dede;field.huohao /}</p>
    <p>价格:{dede;field.jiage /}</p>
    <p>内容:{dede;field.body /}</p>
</div>

可调用所有字段包括自定义字段

3、前台模板搜索框代码

 < form  method="post" action="{dedeglobal.cfg_cmspath/}/plus/so.php" >
    <div id="search_box">
        <p>标题精准搜索:<input type="text" name="title" value="" /></p>
        <input type="submit" name="submit" value="开始搜索"  />
    </div>
 < /form>

 注意:name="title"   不是 name="q"