站内搜索关键词排序与英文字母大小写不区分问题
输入多个关键词,搜索结果按关键词出现个数或者次数多的排前面;和输入英文字母不管大写小写都高亮。
需要添加哪些代码才能实现呢?
请各位指教指教,感谢!虽然分不多,但这是我目前全部身家了。
<!--#include file="utf-8.asp"-->
<!--#include file="conn.asp"-->
<!--#include file="config.asp" -->
<!--#include file="page.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%=request("key")%></title>
<meta name="description" content="<%=config("description")%>" />
<meta name="keywords" content="<%=config("keywords")%>" />
<link href="images/style.css" type="text/css" rel="stylesheet" />
</head>
<body bgcolor="<%=config("bg")%>">
<!--#include file="header.asp" -->
<!--#include file="search_so.asp" -->
<table width="920" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td colspan="2"><table width="100%" border="0" cellpadding="6" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#EBEBEB"><table width="98%" border="0" cellpadding="0" cellspacing="2">
<tr>
<td> <b>关于“<font color="#FF0000"><%=request("key")%></font>”的搜索结果:</b></td>
<td><div align="right"></div></td>
</tr>
</table></td>
</tr>
<td bgcolor="#FFFFFF">
</body>
</html>
<%
key=Trim(Request("key"))
if key="" then
Response.Write("<script>alert('请输入关键词!');history.back();</script>")
Response.End()
end if
key=replace(key," ",",")
keyArr=split(key,",")
sql="select * from [news] where 1=0"
for i=0 to ubound(keyArr)
sql=sql&" or title like '%"&keyArr(i)&"%'"
next
sql=sql&" order by id desc"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if rs.eof then
response.Write " 暂无内容!"
else
rs.PageSize =20 '每页记录条数
iCount=rs.RecordCount '记录总数
iPageSize=rs.PageSize
maxpage=rs.PageCount
page=request("page")
if Not IsNumeric(page) or page="" then
page=1
else
page=cint(page)
end if
if page<1 then
page=1
elseif page>maxpage then
page=maxpage
end if
rs.AbsolutePage=Page
if page=maxpage then
x=iCount-(maxpage-1)*iPageSize
else
x=iPageSize
end if
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="<%=config("bg")%>">
<%For i=1 To x%>
<div class="box14">
<ul>
<%
title=rs("title")
for j=0 to ubound(keyArr)
keyArr=split(Request("key")," ")
title=replace(title,keyArr(j),"<font color=red>"&keyArr(j)&"</font>")
next
%>
<li> <a href="shownews.asp?id=<%=rs("id")%>"><%=title%></a> <%=rs("data")%></li>
</ul>
</div>
<%
rs.movenext
next
%>
<%
end if
%>
<tr>
<td bgcolor="#FFFFFF"><%'以下显示分页
call PageControl(iCount,maxpage,page,"border=0 align=center","<p align=center>")
rs.close
set rs=nothing
%></td>
</tr>
<table></table>
<tr>
<td colspan="2"> </td>
</tr>
<table></table>
<!--#include file="foot.asp" -->
</body>
</html>
[解决办法]
给个服务器端的吧,简单些。
function gggg(str,key)
key = split(key,"分割关键字的符号")
for i = 0 to ubound(key)
str = replace(str,key(i),"<font color=red>"&key(i)&"</font>")
next
end function
大致就是这样的,很简单,你根据你自己的关键字的情况再修改修改,这只是个简单的思路。