网站的全文检索功能!(100分)

  • 主题发起人 梦菲斯
  • 开始时间

梦菲斯

Unregistered / Unconfirmed
GUEST, unregistred user!
在一个网站中要做全文检索功能,即输入字符后,可查询出整个数据库中所有符合要求的
字符,请问这个应如何实现呢?
 
学问都在建索引上。
 
建数据库的时候可以建个索引表
 
你可以直接使用IIS的INDEX SERVER .它只能对网站目录下的文件(html,txt,inc,pdf。。。)进行查询。
而对ASP页面中从数据库取出的部分必须要对特定的字段查询实现,也可以用数据库的全文索引。
以下是ASP用IIS index server实现代码:
page1:
<form id="quick" method="post" action="netsearch1.asp" target="mainFrame" name="form1" ><td valign="top">
<input type="text" name="netqry" size="14" class="9pt-black" bgcolor="#FBFBE4">
<img onClick="document.form1.submit()" src="images/search-go.gif" width="22" height="17"> </form>
netsearch1.asp:
<html>
<head>
<%if Request.ServerVariables("REQUEST_METHOD") = "POST" then
'取出使用者输入的查询字符串
QryStr = Request.Form("netqry")
'是否按下「执行」钮
NewQuery = TRUE '为一新查询
session("showframe")=false
end if
if Request.ServerVariables("REQUEST_METHOD") = "GET" then
'取出Hidden属性的栏内容
QryStr = Request.QueryString("qu")
SearchScope = Request.QueryString("sc")
if Request.QueryString("pg") <> "" then
NextPgNo = Request.QueryString("pg")
NewQuery = FALSE
UsedQuery = TRUE
session("NextPgNo")=NextPgNo
else
NewQuery = QryStr <> ""
end if
end if
session("qrystr")=qrystr
session("newquery")=newquery
session("usedquery")=usedquery
%>
<title></title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<% if session("showframe") then
Response.Write "<frameset rows='20*,20' frameborder='NO' border='0' framespacing='0' cols='*'> "
Response.Write "<frameset cols='151,643*' frameborder='NO' border='0' framespacing='0' rows='*'> "
Response.Write " <frame name='leftFrame' scrolling='NO' noresize src='../left1.htm'> "
Response.Write "<frame name='mainFrame' src='../search/netsearchc.asp'> "
Response.Write "</frameset>"
Response.Write "<frame name='bottomFrame' scrolling='NO' noresize src=' ../botton.htm'> "
Response.Write "</frameset>"
else

Response.Redirect "netsearchc.asp"
end if
%>
</html>
netsearchc.asp:
<script language="VBScript" RunAt="Server">
Dim SearchScope, LocaleID, QryStr
Dim ASPFile, NewQuery, UsedQuery
Dim PageSize
Dim NextPgNo, NextRecNo, CurrentPage
Dim ActiveQuery
Dim RS, Q, util
Sub Initialize()
'指定搜寻范围
SearchScope = "web"
'设定LCID(Locale Identifier)
LocaleID = "ZH-TW"
'指定每一页的资料笔数
PageSize = 10
'设定其余变数
NewQuery = FALSE
UsedQuery = FALSE
QryStr = ""
ASPFile="netsearch1.asp"
End Sub
Sub Judge_Method()
qrystr=session("qrystr")
newquery=session("newquery")
usedquery=session("usedquery")
if UsedQuery then
NextPgNo=session("NextPgNo")
end if
End Sub
Sub Init_ixsso()
Dim StrLen
if NewQuery then
'若为新查询
Set Session("Query") = Nothing
Set Session("Recordset") = Nothing
NextRecNo = 1
'去除查询字符串中的左、右双引号(如果有的话)
StrLen = len(QryStr)
if left(QryStr, 1) = chr(34) then
StrLen = StrLen - 1
QryStr = right(QryStr, StrLen)
end if
if right(QryStr, 1) = chr(34) then
StrLen = StrLen - 1
QryStr = left(QryStr, StrLen)
end if

if len(QryStr)=0 then

Response.Write "<span style='font-size:9pt'>错误 - 尚无任何查询条件!</span>"
Response.End
end if
qrystr="""" &amp;
qrystr &amp;
"""*"
'建立Query对象及Utility对象的实例(Instance)
Set Q = Server.CreateObject("ixsso.Query")
Set util = Server.CreateObject("ixsso.Util")
'设定Query对象的相关属性
Q.Query = QryStr
Q.SortBy = "rank[d]"
Q.Columns = "DocTitle, vpath, filename, size, write, characterization, rank"
'指定传回的最大笔数
Q.MaxRecords = 200
Q.catalog=searchscope

if LocaleID <>"" then
Q.LocaleID = util.ISOToLocaleID(LocaleID)
end if
'以NonSequential之模式建立RecordSet
set RS = Q.CreateRecordSet("nonsequential")
'每一页固定10笔
RS.PageSize = PageSize
ActiveQuery = TRUE
else
If UsedQuery then
if IsObject( Session("Query") ) And _
IsObject( Session("RecordSet") ) then
set Q = Session("Query")
set RS = Session("RecordSet")

if RS.RecordCount <> -1 and NextPgNo <> -1 then
RS.AbsolutePage = NextPgNo
NextRecNo = RS.AbsolutePosition
end if
ActiveQuery = TRUE
else
Response.Write "错误 - 尚无任何查询条件!"
end if
End If 'NewQuery
End Sub
Sub Show_Query()
Dim LastRecordOnPage
'若为现有查询
if ActiveQuery then
'如果Record set有值,就一一取出,然后显示于前端浏览器
if not RS.EOF then
LastRecordOnPage = NextRecNo + RS.PageSize - 1
CurrentPage = RS.AbsolutePage
if RS.RecordCount <> -1 AND _
RS.RecordCount < LastRecordOnPage then
LastRecordOnPage = RS.RecordCount
end if
'显示视窗目前的资料编号
Response.Write "&amp;nbsp;&amp;nbsp;&amp;nbsp;<font style='font-size:9.5pt'>文件" &amp;
NextRecNo &amp;
" 至 "
Response.Write LastRecordOnPage &amp;
", "
'取出总笔数
if RS.RecordCount <> -1 then
Response.Write "总共有<span class=unnamed2><b><font color=red>"
Response.Write RS.RecordCount &amp;
"</font></b></span>"
end if
Response.Write "笔纪录符合查询条件:<b>"
Response.Write QryStr &amp;
"</b></font><P>"
if Not RS.EOF and NextRecNo <= LastRecordOnPage then
Response.Write "<table border=0 width=600>"
Response.Write "<colgroup width=90>"
end if
do
While Not RS.EOF and NextRecNo <= LastRecordOnPage
'一一显示文件的标题、摘要、URL、文件大小及
'最后修改日期。
Response.Write "<p>"
Response.Write "<tr class='unnamed2'>"
Response.Write "<td align=right valign=top >"
'显示编号
Response.Write NextRecNo &amp;
"."
Response.Write "</td>"
Response.Write "<td >"'BGCOLOR='#e6f2ff'>"
'Response.Write "<b class='unnamed2'>"
'如果标题属性(Title)存在的话就显示Title,
'否则显示出文件名
if VarType(RS("DocTitle")) = 1 or RS("DocTitle") = "" then
Response.Write "<font size=2>"
Response.Write "<class='unnamed2'><a href='javascript:void(null)' onClick=MM_openBrWindow('"
Response.write server.URLPathen
code(rs("vpath")) &amp;
"','','')>"
Response.Write Server.HTMLEncode(RS("filename")) &amp;
"</a> <font>"
else
Response.Write "<font size=2>"
Response.Write "<class='unnamed2'><a href='javascript:void(null)' onClick=MM_openBrWindow('"
Response.write server.URLPathen
code(rs("vpath")) &amp;
"','','')>"
Response.Write Server.HTMLEncode(RS("DocTitle")) &amp;
"</a> <font>"
end if
'Response.Write "</b>"
Response.Write "</td></tr>"
Response.Write "<tr>"
Response.Write "<td>"
Response.Write "</td>"
Response.Write "<td valign=top>"
'显示摘要
Response.Write "<span class=unnamed3>"
if VarType(RS("characterization")) = 8 and _
RS("characterization") <> "" then
Response.Write "摘要:"
Response.Write Server.HTMLEncode(RS("characterization"))
end if
Response.Write "<br>"
Response.Write "<span class='unnamed2'><a href='javascript:void(null)' onClick=MM_openBrWindow('"
Response.write server.URLPathen
code(rs("vpath")) &amp;
"','','')>"

Response.Write "http://"
Response.Write Request("server_name") &amp;
RS("vpath")
Response.Write "</span>"
Response.Write "</a><br>"
Response.Write "<span class=unnamed3>"
if RS("size") = "" then
Response.Write "(大小和时间不详)"
else
Response.Write "大小 " &amp;
RS("size") &amp;
" 个字节 - "
Response.Write RS("write") &amp;
" GMT"
end if
Response.write "</span>"
'Response.Write "</i>"
Response.Write "</td></tr>"
Response.Write "<tr><td>&amp;nbsp;&amp;nbsp;</td></tr>"
RS.MoveNext
NextRecNo = NextRecNo + 1
Response.Write "<p>"
Loop
Response.Write "</span>"
Response.Write "</table>"
Response.Write "<P><BR>"
else
' RS.EOF
if NextRecNo = 1 then
Response.Write "没有任何文件符合查询条件!<P>"
else
Response.Write "符合查询条件的文件均已显示!<P>"
end if
end if ' NOT RS.EOF
'if Q.OutOfDate then
' Response.Write "<P align='center' style='font-size:9pt'>检索即将过期"
' Response.Write "(out of date)。<BR>"
'end if
if Q.QueryIncomplete then
Response.Write "<P><I><B>查询无法完整完成"
Response.Write "(Query Incomplete)。</B></I><BR>"
end if
if Q.QueryTimedOut then
Response.Write "<P><I><B>查询时间太长"
Response.Write "(Time out)。</B></I><BR>"
end if
'
Call Show_Button()
end if 'ActiveQuery
End Sub
Sub Show_Button()
Dim SaveQuery
Response.Write "<TABLE>"
'显示「前X份文件」按钮
SaveQuery = FALSE
if CurrentPage > 1 and RS.RecordCount <> -1 then
Response.Write "<td align=left>"
Response.Write "<form action='" &amp;
ASPFile &amp;
"' method='get'>"
Response.Write "<INPUT TYPE='HIDDEN' NAME='qu' "
Response.Write "VALUE='" &amp;
QryStr &amp;
"'>"
Response.Write "<INPUT TYPE='HIDDEN' NAME='sc' "
Response.Write "VALUE='" &amp;
SearchScope &amp;
"'>"
Response.Write "<INPUT TYPE='HIDDEN' name='pg' "
Response.Write "VALUE='" &amp;
CurrentPage-1 &amp;
"'>"
Response.Write "<input style='font-size:9pt' type='submit' value='前 "
Response.Write RS.PageSize &amp;
" 份文件'>"
Response.Write "</form>"
Response.Write "</td>"
SaveQuery = TRUE
end if
'显示「後X份文件」按钮
if Not RS.EOF then
Response.Write "<td align=right>"
Response.Write "<form action='" &amp;
ASPFile &amp;
"' method='get'>"
Response.Write "<INPUT TYPE='HIDDEN' NAME='qu' "
Response.Write "VALUE='" &amp;
QryStr &amp;
"'>"
Response.Write "<INPUT TYPE='HIDDEN' NAME='sc' "
Response.Write "VALUE='" &amp;
SearchScope &amp;
"'>"
Response.Write "<INPUT TYPE='HIDDEN' name='pg' "
Response.Write "VALUE='" &amp;
CurrentPage+1 &amp;
"'>"
NextString = "后 "
if RS.RecordCount <> -1 then
NextSet = (RS.RecordCount - NextRecNo) + 1
if NextSet > RS.PageSize then
NextSet = RS.PageSize
end if
NextString = NextString &amp;
NextSet &amp;
" 份文件"
else
NextString = NextString &amp;
" 页文件"
end if
Response.Write "<input type='submit' style='font-size:9pt' "
Response.Write "value='" &amp;
NextString &amp;
"'>"
Response.Write "</form>"
Response.Write "</td>"
SaveQuery = TRUE
end if 'Not RS.EOF
Response.Write "</TABLE>"
'显示「目前页数/总页数」
Response.Write "页数 : " &amp;
CurrentPage
if RS.PageCount <> -1 then
Response.Write " / " &amp;
RS.PageCount
end if
'如果有「前十份文件」或「后X份文件」按钮存在的话,
'就将现有的Query对象及Recordset存到Session变量中,
'以备按下前两个按钮之用
if SaveQuery then
set Session("Query") = Q
set Session("RecordSet") = RS
Session("ShowFrame")=false
else
'否则关闭并清除
RS.close
Set RS = Nothing
Set Q = Nothing
set Session("Query") = Nothing
set Session("RecordSet") = Nothing
Session("ShowFrame")=true
end if
End Sub
</script>
<HTML>
<HEAD>
<title>站内搜索</title>
</HEAD>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<style type="text/css">
<!--
.unnamed1-9 { font-size: 9pt;
line-height: 16pt;
text-decoration: none}
.unnamed1 { font-size: 9pt;
line-height: 16pt;
text-decoration: none;
color: #000000}
.unnamed2 { font-size: 9.5pt;
line-height: 16pt;
color: #400900;
text-decoration: none}
.unnamed3 { font-size: 9pt;
line-height: 12pt;
color: #333333;
text-decoration: none}
a:hover { text-decoration: underline;
color: #CC3300}
a:vlink { text-decoration: underline;
color: #400900}
a:link { text-decoration: underline;
color: #400900}
body {font-size: 9pt;
line-height: 16pt;
text-decoration: none;
color: #000000}
-->
</style>
<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<body text="#000000" leftmargin="0" >

<%
Call Initialize()
Call Judge_Method()
Call Init_ixsso()
Call Show_Query()
%>
</table>
</BODY></HTML>

 
Index Server据说很强大。没用过[:D]
 
看看yysun的帖子吧http://www.delphibbs.com/delphibbs/dispq.asp?lid=755450
 
多人接受答案了。
 
顶部