TSYS1.1搜索加强(可区分标题、内容、全文)
时间:2007-05-16 来源:a010
本文只针对TSYS1.1测试有效
增加了红色部分代码,判断只搜索标题,或只搜索内容,或进行全文搜索。该页代码为图片信息代码,只有有小图的信息才会被现实出来,只要复制本页代码保存为listpic.asp即可,后面加参数可以显示相应分类,比如listpic.asp?class=25
对于普通的搜索页面,也可以采用同样的方法实现分范围搜索,这样对我们查找数据的方便性会大大增加,同时也减少不必要的系统消耗。
<!--#include file="system/Manage/Include/Config.asp" -->
<!--#include file="system/Manage/Include/ClassList_Fun.asp" -->
<!--#include file="system/Manage/Include/Tkl_StringClass.asp" -->
<html>
<head>
<title>图片新闻</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="keywords" content="图片新闻,图片信息">
<meta name="Version" content="Zhejiang Bicycle">
<style type="text/css">
<!--
-->
</style>
<%'本页为显示所有具有小图的信息,使用listpic.asp?Class=91的参数可以实现按分类显示%>
<link href="Style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<%
Dim FunClass
Set FunClass=New Tkl_StringClass
Dim sKey
sKey=Replace(Request("sKey"),"'","")
Dim Work
Work=Request("Work")
Dim Conn
Set Conn = Server.CreateObject("Adodb.Connection")
Conn.Open ConnStr
%>
<table width="100%" height="110" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
</td>
</tr>
</table>
<table width="786" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td height="90" align="center" bgcolor="#FFFFFF">
<table width="778" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#f6f6f6">
<form name="shForm" method="post" action="listpic.asp">
<tr>
<td height="45" align="center" bgcolor="#FFFFFF"> 资料搜索:
<input type="text" name="sKey" value="<%=sKey%>">
<label>
<select name="t_c" id="t_c">
<option value="1">标题</option>
<option value="2">内容</option>
<option value="3">全文</option>
</select>
</label>
<select name="Class" class="input1" id="Class">
<option value="0" selected>所有分类</option>
<OPTION value=59>协会新闻</OPTION>
<OPTION value=60>行业动态</OPTION>
<OPTION value=64>政策法规</OPTION>
<OPTION value=69>上牌目录</OPTION>
<OPTION value=96>专业英语</OPTION>
<OPTION value=72>在线杂志</OPTION>
<OPTION value=87>技术博览</OPTION>
<OPTION value=90>消费观察</OPTION>
<OPTION value=91>展会专栏</OPTION>
<OPTION value=92>会员风采</OPTION>
<OPTION value=95>关于协会</OPTION>
</select>
<input type="submit" name="Submit3" value="搜索">
</td>
</tr>
</form>
</table>
<%
If Len(sKey)<500 Then
Call InfoList()
Else
Call ErrorInfo()
End If
Sub InfoList()
Dim Rs,Sql,CurrentPage
If Request("CurrentPage")="" Then
CurrentPage=1
Else
CurrentPage=Request("CurrentPage")
End If
Set Rs=Server.CreateObject("ADODB.RecordSet")
Sql=ExeSql()
Rs.PageSize=15
Rs.CacheSize=Rs.PageSize
Rs.Open Sql,Conn,1,1
If Not(Rs.Eof And Rs.Bof) Then
Rs.AbsolutePage=CurrentPage
End If
%>
<table width="778" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f6f6f6">
<tr>
<td height="24" align="left" class="TitleBar"> <a href="/index.htm">本站首页</a>
> <a href="listpic.asp">图片中心</a> > <%=sKey%> 搜索结果<b> <font color="#0000FF"><%=Rs.RecordCount%></font></b>
条</td>
</tr>
</table>
<table width="778" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f6f6f6">
<tr>
<td align="left" valign="top" bgcolor="#FFFFFF"> <br>
<table width="100%" height="150" border="0" cellpadding="5" cellspacing="0">
<%
Dim I,J
For I=1 To 5
If Rs.Eof Then
Exit For
End If
%>
<tr align="center">
<%
For J=1 To 3
If Rs.Eof Then
%>
<td> </td>
<%
Else
%>
<td>
<table height="83" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table border="0" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"><a href="<%=Rs("FilePath")%>" target="_blank">
</a><a href="<%=Rs("FilePath")%>" target="_blank"><img src="<%=Rs("SmallImg")%>" width="200" height="200" border="0"></a> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<a href="<%=Rs("FilePath")%>" target="_blank"><%'=Rs("Title")%>
<%'截取字符串函数,由于不能对加颜色的标题进行很好的判断,故注释掉。
If Len(Rs("Title"))>12 then
Response.write Left(Rs("Title"),14)&"..."
Else
Response.write Rs("Title")
End If%>
</a>
</td>
</tr>
<tr>
<td align="center"><%=Rs("AddTime")%></td>
</tr>
</table>
</td>
<%
Rs.MoveNext
End If
Next
%>
</tr>
<%
Next
%>
</table>
<%
If Rs.Eof And Rs.Bof Then
%>
<table width="75%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f6f6f6">
<tr>
<td height="35" align="center" class="bigTitle">对不起,没有搜索到相关的信息</td>
</tr>
</table>
<%
End If
%>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td align="center" bgcolor="#f6f6f6">
</td>
</tr>
</table>
</td>
</tr>
</table>
<%
Rs.Close
Set Rs=Nothing
End Sub
Sub ErrorInfo()
%>
<table width="778" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#f6f6f6">
<tr>
<td height="24" align="center" bgcolor="#FFFFFF">
<table width="75%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f6f6f6">
<tr>
<td height="35" align="center" class="bigTitle">对不起,搜索失败,可能出现的错误原因:<br>
1.搜索关键词没有输入;2.关键词过长(<500)</td>
</tr>
</table>
</td>
</tr>
</table>
<%
End Sub
%>
<font size="4"> </font></td>
</tr>
</table>
<table width="100%" height="110" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
</td>
</tr>
</table>
</body>
</html>
<%
Function ExeSql()
Dim tSql
Select Case Work
Case Else '新闻列表
'-------------------------------------搜索分拣开始
'取得分类数值
t_c=Request("t_c")
'如果分类值为1 只对标题进行搜索
if t_c=1 then
'------------------------
tSql="SELECT Id,Title,AddTime,FilePath,SmallImg From view_NewsInfo Where (Title) Like '%"&sKey&"%' {Where01} and SmallImg<>'' Order By AddTime DESC"
'上行加入SmallImg<>''判断是否有小图,否则不显示
end if
'如果分类值为2 只对内容进行搜索
if t_c=2 then
'------------------------
tSql="SELECT Id,Title,AddTime,FilePath,SmallImg From view_NewsInfo Where (ShortContent) Like '%"&sKey&"%' {Where01} and SmallImg<>'' Order By AddTime DESC"
'上行加入SmallImg<>''判断是否有小图,否则不显示
end if
'如果分类值为3 对标题、内容、关键词进行搜索
if t_c=3 then
'------------------------
tSql="SELECT Id,Title,AddTime,FilePath,SmallImg From view_NewsInfo Where (Title+','+keyWord+','+ShortContent) Like '%"&sKey&"%' {Where01} and SmallImg<>'' Order By AddTime DESC"
'上行加入SmallImg<>''判断是否有小图,否则不显示
end if
'如果分类值为空,对标题、内容、关键词进行搜索
if t_c="" then
'------------------------
tSql="SELECT Id,Title,AddTime,FilePath,SmallImg From view_NewsInfo Where (Title+','+keyWord+','+ShortContent) Like '%"&sKey&"%' {Where01} and SmallImg<>'' Order By AddTime DESC"
'上行加入SmallImg<>''判断是否有小图,否则不显示
end if
'------------------------------------搜索分拣结束
End Select
If IsNumeric(Request("Class")) And Request("Class")<>"" Then
tSql = Replace(tSql,"{Where01}"," And Class In (" & Request("Class") & AllChildClass(Request("Class")) & ")")
Else
tSql = Replace(tSql,"{Where01}","")
End If
ExeSql=tSql
End Function
%>