| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 832 人关注过本帖
标题:网站搜索没有后台搜索精确!如何把前台搜索和后台搜索改成一样的!
只看楼主 加入收藏
firyafir
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2009-7-3
结帖率:90.91%
收藏
 问题点数:0 回复次数:3 
网站搜索没有后台搜索精确!如何把前台搜索和后台搜索改成一样的!


后台搜索比较精确!经常会出现同一个关键字,后台可以搜索到几十个代码,但前台可能一个都搜索不到!然后在后台找了下,发现两个所使用的搜索代码是不一样的!请问如何才能让前台使用后台的搜索代码!或者就是把前台的搜索代码改成和后台一样的搜索代码!麻烦大家给看看吧!我就是一小学教师!实在看不懂这些!先谢谢啦!
前台搜索代码:
<!--$include file="header.html"-->
<div class="leftshad"><div class="rightshad">
<div class="globalBox">
    <div class="globalMain">
        <div id="positionBody">
            <div class="crumb"><span class="crumbleft"><b>当前位置:</b><a href="{$InstallDir}">{$tag:sitename}</a> → 搜索:{$newasp:keyword}</span></div>
            <div style="clear:both"></div>
        </div>
        <div class="searchForm">
            <div id="indexSearch">
                <form name="searchform2" method="get" action="search.asp">
                <input name="word" id="words" size="50" value="{$newasp:keyword}" maxlength='60' onFocus='this.select();' />
                <select name="ChannelID" id="ChannelOption" class="alingmid">
            <option value="1">请选择频道</option>
                                                <option value="1">论文</option>
                                                <option value="2">课件</option>
                                                <option value="11">试卷</option>
                                                <option value="12">教案</option>
                                                <option value="19">素材</option>
                                                <option value="20">教学参考</option>
                                                <option value="13">教学软件</option>
                                                <option value="18">中考高考</option>
                                                <option value="16">天下教育</option>
                                                <option value="17">计划总结</option>
        </select>
                <input name="searchbtn2" type="submit" value="开始搜索" />
                </form>
            </div>
        </div>
        <div id="searchmain">
            <div class="searchResult">本次搜索共找到约 <span style="color:red">{$newasp:totalrec}</span> 条相关记录,<span style="color:red">{$newasp:keyword}</span> 结果如下</div>
            {$topiclist:begin}
            <div class="searchTopic">{$topiclist:i+}、<a href="{$topiclist:link}">{$topiclist:topic}</a></div>
            <div class="searchIntro">{$topiclist:content}</div>
            <div class="searchInfo"><span style="float:right">类别:{$topiclist:classtitle}&nbsp;&nbsp;大小:{$topiclist:size}&nbsp;&nbsp;日期:{$topiclist:date}&nbsp;&nbsp;[<a href="{$topiclist:link}" target="_blank">查看详细</a>]</span></div>
            {$topiclist:end}
        </div>
        <div class="mainPageBox" id="NextPageText"><p class="list_page">{$xml:datalist id="showpage" file="page.xslt" type="1" max="10" title="显示分页"}</p></div>
    </div><!-- End globalMain -->
</div>
</div></div>
<!--$include file="footer.html"-->


后台搜索代码
<!--#include file="const.asp"-->
<!--#include file="../../inc/cls_keyword.asp"-->
<%
Admin_header
'=====================================================================
' 软件名称:新云网站管理系统
' 当前版本:NewAsp Content Management System Version 4.0
' 文件名称:admin_search.asp
' 更新日期:2008-06-16
' 官方网站:新云网络(www. www.) QQ:94022511
'=====================================================================
' Copyright 2003-2008 - All Rights Reserved.
' newasp is a trademark of
'=====================================================================
Dim maxperpage,totalrec,Pcount,pagelinks,pagenow
Dim classid,SQLQuery,SQLField,searchTopic,searchmode,searchfield,fieldName
Dim ChildData,ischild,childstr,Keyword,searchMaxResult,ArryWords()
Keyword = Trim(Request("word"))
searchmode = NewAsp.ChkNumeric(Request("searchmode"))
searchfield = NewAsp.ChkNumeric(Request("searchfield"))
searchMaxResult = 1000
%>
<table class="table1" cellspacing="1" cellpadding="3" align="center" border="0">
    <tr>
        <td class="tableline"><form name="search_form" id="search_form" method="get" action="admin_search.asp">
            <input type="hidden" name="ChannelID" value="<%=ChannelID%>">
            <input type="text" class="alingmid" id="word" name="word" size="45" onfocus="if(this.value=='请输入关键字')this.value=''" value="<%=Server.HTMLEncode(Keyword)%>" />
            <select name="searchfield" class="alingmid">
                <option value="0">标题</option>
                <option value="1"<%If searchfield=1 Then Response.Write " selected=""selected"""%>>录入者</option>
                <option value="2"<%If searchfield=2 Then Response.Write " selected=""selected"""%>>版本</option>
                <option value="3"<%If searchfield=3 Then Response.Write " selected=""selected"""%>>主页</option>
                <option value="9"<%If searchfield=9 Then Response.Write " selected=""selected"""%>>标签</option>
            </select>
            <input type="submit" value="开始搜索" name="search_submit" class="button alingmid" />
            <input type="checkbox" id="searchmode" name="searchmode" value="1" class="alingmid"<%If searchmode=1 Then Response.Write " checked=""checked"""%> /><label for="searchmode">分词搜索</label>
        </form>
        </td>
        <td class="tableline" id="searchInfo" align="right">&nbsp;</td>
    </tr>
</table>
<%
If Not ChkAdmin("List_"&ChannelID) Then
    Call Transfer_error()
End If

If Len(Keyword)>1 Then
    Call showmain()
End If
Admin_footer
NewAsp.PageEnd

Sub showmain()
    Dim i,iCount,lCount,iIndex
    maxperpage=30
    iIndex = 0
    pagenow=NewAsp.ChkNumeric(Request("page"))
    If pagenow=0 Then pagenow=1
    classid=NewAsp.ChkNumeric(Request("classid"))

    If classid>0 Then
        ChildData=NewAsp.GetChildData(ChannelID,classid,0)
        childstr=ChildData(0)
        ischild=CLng(ChildData(2))
    End If
    SQLField = "A.softid,A.ChannelID,A.classid,A.SpecialID,A.SoftName,A.SoftVer,A.ColorMode,A.FontMode,A.username,A.SoftTime,A.AllHits,A.isTop,A.isBest,A.isAccept,A.SoftSize,C.ClassName"
%>
<form name="selform" method="post" action="admin_setting.asp?ChannelID=<%=ChannelID%>">
<input type="hidden" name="action" value="batch">
<table id="tablehovered" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
<tr>
    <th width="5%" noWrap="noWrap">选择</th>
    <th width="57%"><%=NewAsp.ModuleName%>标题</th>
    <th width="9%" noWrap="noWrap">管理操作</th>
    <th width="8%" noWrap="noWrap">文件大小</th>
    <th width="9%" noWrap="noWrap">用户&评论</th>
    <th width="12%" noWrap="noWrap">整理日期</th>
</tr>
<tr>
    <td class="tablerow1" colspan="6" align="left" id="showNextPage">&nbsp;</td>
</tr>
<%
    Call searchTopicList()
    iCount=2:lCount=2
    If IsArray(searchTopic) Then
        For i=0 To Ubound(searchTopic,2)
            If Not Response.IsClientConnected Then Response.End
            If (i mod 2) = 0 Then
                iCount=2:lCount=1
            Else
                iCount=1:lCount=2
            End If
%>
<tr align="center">
    <td class="tablerow<%=iCount%> hovered"><input type="checkbox" name="softid" value="<%=searchTopic(0,i)%>"/></td>
    <td class="tablerow<%=iCount%> hovered" align="left">[<a href="admin_list.asp?ChannelID=<%=ChannelID%>&classid=<%=searchTopic(2,i)%>"><%=searchTopic(15,i)%></a>]
    <a href="admin_list.asp?action=view&ChannelID=<%=ChannelID%>&softid=<%=searchTopic(0,i)%>"><%=HighlightWord(searchTopic(4,i)&" "&searchTopic(5,i))%></a>
    <%
    If searchTopic(11,i)>0 Then Response.Write "<font color=""red""><b>顶</b></font>"
    If searchTopic(12,i)>0 Then Response.Write "<font color=""blue""><b>精</b></font>"
    %>
    </td>
    <td class="tablerow<%=iCount%> hovered" noWrap="noWrap"><a href="admin_post.asp?action=edit&ChannelID=<%=ChannelID%>&softid=<%=searchTopic(0,i)%>">编辑</a> | <a href="admin_setting.asp?action=del&ChannelID=<%=ChannelID%>&softid=<%=searchTopic(0,i)%>" onclick="return confirm('<%=NewAsp.ModuleName%>删除后将不能恢复,您确定要删除吗?')">删除</a></td>
    <td class="tablerow<%=iCount%> hovered" noWrap="noWrap" title="人气:<%=searchTopic(10,i)%>"><%=NewAsp.BytesToString(CLng(searchTopic(14,i))*1024)%></td>
    <td class="tablerow<%=iCount%> hovered" noWrap="noWrap" title="点击查看用户评论"><a href="admin_comment.asp?ChannelID=<%=ChannelID%>&softid=<%=searchTopic(0,i)%>"><%=searchTopic(8,i)%></a></td>
    <td class="tablerow<%=iCount%> hovered" noWrap="noWrap"><%=showDateTime(searchTopic(9,i),"yyyy-MM-dd")%></td>
</tr>
<%
        Next
    End If
    searchTopic=Null
%>
<tr>
    <td class="tablerow<%=lCount%>" colspan="6"><input class="button" type="button" name="chkall" value="全选" onClick="CheckAll(this.form)"><input class="button" type="button" name="chksel" value="反选" onClick="ContraSel(this.form)">
        管理选项:
        <select name="act">
            <option value="0">请选择操作选项</option>
            <option value="批量删除">批量删除</option>
            <option value="批量置顶">批量置顶</option>
            <option value="取消置顶">取消置顶</option>
            <option value="批量推荐">批量推荐</option>
            <option value="取消推荐">取消推荐</option>
            <option value="批量审核">批量审核</option>
            <option value="取消审核">取消审核</option>
            <option value="更新时间">更新时间</option>
            <option value="生成HTML">生成HTML</option>
        </select>
        <input class="button" type="submit" name="submit_button1" value="执行操作" onclick="return confirm('您确定执行该操作吗?');">
        <input class="button" type="submit" name="submit_button2" value="批量设置" onclick="document.selform.action.value='setting';">
        <input class="button" type="submit" name="submit_button3" value="批量移动" onclick="document.selform.action.value='move';">
    </td>
</tr>
<tr>
    <td class="tablerow<%=iCount%>" align="right" colspan="6" id="NextPageText">
    <var class="morePage"><%=showlistpage(pagenow,Pcount,maxperpage,totalrec,pagelinks)%></var></td>
</tr>
</table>
</form>
<script type="text/javascript">
document.getElementById("showNextPage").innerHTML = document.getElementById("NextPageText").innerHTML;
var searchEl=document.getElementById("searchInfo");
if(searchEl)
searchEl.innerHTML = "找到相关结果约<%=totalrec%>条,用时<%=FormatNumber((Timer()-startime),3, -1)%>秒";
</script>
<%
End Sub

Sub searchTopicList()
    Dim Rs,SQL,i,iCount,ArryKeyword
    totalrec=0
    Select Case searchfield
        Case 0:fieldName="A.SoftName+' '+A.SoftVer"
        Case 1:fieldName="A.username"
        Case 2:fieldName="A.SoftVer+A.subtitle"
        Case 3:fieldName="A.HomePage"
        Case 9:fieldName="A.Taglist"
        Case Else
            fieldName="A.SoftName+' '+A.SoftVer+A.subtitle"
    End Select
    pagelinks="admin_search.asp?channelid="&ChannelID&"&classid="&classid&"&word="&Keyword&"&searchmode="&searchmode&"&searchfield="&searchfield&"&"
    If Len(Keyword)>1 Then
        If searchmode=1 Then
            iCount=0
            SQLQuery=""
            ArryKeyword = cmWords.ParseKeyword(Keyword)
            For i = 0 To UBound(ArryKeyword)
                If Len(ArryKeyword(i)) > 1 Then
                    ReDim Preserve ArryWords(iCount)
                    ArryWords(iCount)=ArryKeyword(i)
                    If iCount=0 Then
                        If IsSqlDataBase=1 Then
                            SQLQuery=""&fieldName&" like '%"&ArryKeyword(i)&"%'"
                        Else
                            SQLQuery="InStr(1,LCase("&fieldName&"),LCase('"&ArryKeyword(i)&"'),0)>0"
                        End If
                    Else
                        If IsSqlDataBase=1 Then
                            SQLQuery=SQLQuery & " Or "&fieldName&" like '%"&ArryKeyword(i)&"%'"
                        Else
                            SQLQuery=SQLQuery & " Or InStr(LCase("&fieldName&"),LCase('"&ArryKeyword(i)&"'))>0"
                        End If
                    End If
                    iCount=iCount+1
                End If
            Next
            If iCount=0 Then SQLQuery="":ReDim Preserve ArryWords(0):ArryWords(0)=""
        Else
            If cmWords.CheckKeyword(Keyword) Then
                If IsSqlDataBase=1 Then
                    SQLQuery = ""&fieldName&" like '%"&Keyword&"%'"
                Else
                    SQLQuery = "InStr(LCase("&fieldName&"),LCase('"&Keyword&"'))>0"
                End If
                ReDim Preserve ArryWords(0):ArryWords(0)=Keyword
            Else
                SQLQuery="":ReDim Preserve ArryWords(0):ArryWords(0)=""
            End If
        End If

        If Len(SQLQuery) >10 Then SQLQuery=" And ("&SQLQuery&")" Else SQLQuery=""
        If classid>0 Then
            If ischild>0 Then
                SQLQuery=" And A.isAccept=1 And A.classid in (" & childstr & ") "&SQLQuery
            Else
                SQLQuery=" And A.isAccept=1 And A.classid="&classid&" "&SQLQuery
            End If
        Else
            SQLQuery=" And A.isAccept=1 "&SQLQuery
        End If

        If Not IsObject(Conn) Then ConnectionDatabase
        Set Rs=NewAsp.CreateAXObject("ADODB.Recordset")
        SQL="SELECT TOP "&searchMaxResult&" "& SQLField &" FROM [NC_SoftList] A INNER JOIN [NC_Classify] C on A.ClassID=C.ClassID WHERE A.ChannelID=" &ChannelID& " "&SQLQuery&" ORDER BY A.SoftTime DESC"
        Rs.Open SQL,Conn,1,1
        If pagenow >1 Then
            Rs.Move (pagenow-1) * maxperpage
        End If
        If Not Rs.EOF Then
            totalrec = CLng(Rs.Recordcount) '###记录总数
            searchTopic=Rs.GetRows(maxperpage)
        Else
            searchTopic=Null
        End If
        Rs.close()
        Set Rs=Nothing
    End If
    Pcount = CLng(totalrec / maxperpage)
    If Pcount < totalrec / maxperpage Then Pcount = Pcount + 1
    If pagenow>Pcount Then pagenow=1
End Sub

Function HighlightWord(str)
    Dim i
    For i=0 To UBound(ArryWords)
        If ArryWords(i)<>"" Then str=Replace(str, ArryWords(i), "<font color=""red"">"& ArryWords(i) &"</font>")
    Next
    HighlightWord=str
End Function

%>
搜索更多相关主题的帖子: 搜索 前台 后台 
2010-03-21 21:01
elan1986
Rank: 6Rank: 6
等 级:贵宾
威 望:18
帖 子:458
专家分:407
注 册:2007-12-17
收藏
得分:0 
不管怎么样 如果要精确的话 肯定要经过后台处理的!
2010-03-31 13:25
h_uamin
Rank: 1
等 级:新手上路
帖 子:4
专家分:3
注 册:2010-4-7
收藏
得分:0 
应该是两个表单提交的处理文件的具体代码不同吧,一个是提交到search.asp的另外一个是admin_search.asp。你再好好看下这两个文件(search.asp,admin_search.asp)代码吧。或者贴出来大家看看。
2010-04-07 11:28
liang198207
Rank: 5Rank: 5
等 级:职业侠客
帖 子:70
专家分:300
注 册:2011-5-10
收藏
得分:0 
后台是需要权限的,前台没有,你把后台的权限限制代码去了,把相关的文件拿到前台就可以了,但是可能会涉及到某些文件的路径,改一下就可以了。这么弄肯定有它的理由啊,怎么还要把后台给搬出来呢?
2011-05-10 23:53
快速回复:网站搜索没有后台搜索精确!如何把前台搜索和后台搜索改成一样的!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034120 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved