这是用ASP编写的利用Windows2000Server中的Index Server控件的全文搜索引擎的源代码:
Sub Initialize()
'指定搜寻范围
SearchScope = "/"
'设定LCID(Locale Identifier)
LocaleID = "ZH-CN"
'指定每一页的资料笔数
PageSize = 10
'设定其余变数
NewQuery = FALSE
UsedQuery = FALSE
QryStr = ""
'取得ASP文件的虚拟路径,包括文件名
ASPFile = Request.ServerVariables("PATH_INFO")
End Sub
Sub Judge_Method()
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
QryStr = Request.Form("QryStr")
action=Request.Form("Action")
if Request.Form("Action") = "执行" then
NewQuery = TRUE '为一新查询
end if
end if
if Request.ServerVariables("REQUEST_METHOD") = "GET" then
QryStr = Request.QueryString("qu")
SearchScope = Request.QueryString("sc")
if Request.QueryString("pg") <> "" then
NextPgNo = Request.QueryString("pg")
NewQuery = FALSE
UsedQuery = TRUE
else
NewQuery = QryStr <> ""
end if
end ifEnd Sub
Sub Show_Mainform()
Response.Write "<INPUT TYPE='TEXT' NAME='QryStr' SIZE=46 "
Response.Write "MAXLENGTH=100 VALUE='" & QryStr & "'> "
Response.Write "<INPUT TYPE='SUBMIT' NAME='Action'"
Response.Write " VALUE='执行'> "
Response.Write "<INPUT TYPE='RESET' NAME='Clear'"
Response.Write " VALUE='清除'>"
Response.Write "</div>"
Response.Write "</td>"
Response.Write "</tr>"
Response.Write "</table>"
Response.Write "<hr></FORM>"
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
Set Q = Server.CreateObject("ixsso.Query")
Set util = Server.CreateObject("ixsso.Util")
Q.Query = QryStr
Q.SortBy = "rank[d]"
Q.Columns = "DocTitle, vpath, filename, size, write, characterization, rank"
Q.MaxRecords = 200
if SearchScope <> "/" then
util.AddScopeToQuery Q, SearchScope, "deep"
end if
if LocaleID <>"" then
Q.LocaleID = util.ISOToLocaleID(LocaleID)
end if
set RS = Q.CreateRecordSet("nonsequential")
RS.PageSize = PageSize
ActiveQuery = TRUE
ElseIf 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 'NewQueryEnd 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 "文件" & NextRecNo & " 至 "
Response.Write LastRecordOnPage & ", "
'取出总笔数
if RS.RecordCount <> -1 then
Response.Write "总共有<font color='red'><b>"
Response.Write RS.RecordCount & "</b></font>"
end if
Response.Write "笔纪录符合查询条件:" & chr(34) & "<b>"
Response.Write QryStr & "</b>" & chr(34) & "。<P>"
if Not RS.EOF and NextRecNo <= LastRecordOnPage then
Response.Write "<table border=0>"
Response.Write "<colgroup width=105>"
end if
Do While Not RS.EOF and NextRecNo <= LastRecordOnPage
'一一显示文件的标题、摘要、URL、文件大小及
'最后修改日期。
Response.Write "<center>"
Response.Write "<p>"
Response.Write "<tr class='RecordTitle'>"
Response.Write "<td align=center valign=top "
Response.Write "BGCOLOR='#EEEEEE' class='RecordTitle'>"
'显示编号
Response.Write NextRecNo & "."
Response.Write "</td>"
Response.Write "<td BGCOLOR='#EEEEEE'>"
Response.Write "<b class='RecordTitle'>"
'如果标题属性(Title)存在的话就显示Title,
'否则显示出文件名
if VarType(RS("DocTitle")) = 1 or RS("DocTitle") = "" then
Response.Write "<a href='" & RS("vpath") & "' "
Response.Write "class='RecordTitle'>"
Response.Write Server.HTMLEncode(RS("filename")) & "</a>"
else
Response.Write "<a href='" & RS("vpath") & "' "
Response.Write "class='RecordTitle'>"
Response.Write Server.HTMLEncode(RS("DocTitle")) & "</a>"
end if
Response.Write "</b>"
Response.Write "</td></tr>"
Response.Write "<tr>"
Response.Write "<td>"
Response.Write "</td>"
Response.Write "<td valign=top>"
'显示摘要
if VarType(RS("characterization")) = 8 and _
RS("characterization") <> "" then
Response.Write "<b>摘要:</b>"
Response.Write Server.HTMLEncode(RS("characterization"))
end if
Response.Write "<p>"
Response.Write "<a href='"
Response.Write RS("vpath") & "' class='RecordStats' "
Response.Write "style='color:blue;'>http://"
Response.Write Request("server_name") & RS("vpath")
Response.Write "</a><br>"
if RS("size") = "" then
Response.Write "(大小和时间不详)"
else
Response.Write "大小 " & RS("size") & " 个字节 - "
Response.Write RS("write") & " GMT"
end if
Response.Write "</td></tr>"
Response.Write "<tr></tr>"
RS.MoveNext
NextRecNo = NextRecNo + 1
Loop
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><B>检索即将过期"
Response.Write "(out of date)。</B><BR>"
end if
if Q.QueryIncomplete then
Response.Write "<P><B>查询无法完整完成"
Response.Write "(Query Incomplete)。</B><BR>"
end if
if Q.QueryTimedOut then
Response.Write "<P><B>查询时间太长"
Response.Write "(Time out)。</B><BR>"
end if
'
Call Show_Button()
end if 'ActiveQueryEnd Sub
</script>
<HTML>
<HEAD>
<META NAME="MS.LOCALE" CONTENT="ZH-CN">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html">
<TITLE>站内全文检索引擎</TITLE>
<LINK REL=Stylesheet TYPE="text/css" HREF="ews.css">
<%
'搜寻范围
Call Initialize()
'判断Request_Method
Call Judge_Method()
%>
</HEAD>
<BODY background="/images/marble2c.GIF" >
<right>
<%response.write ""&action&""%>
<%
Call Show_Mainform()
Call Init_ixsso()
Call Show_Query()
%>
</right>
</BODY></HTML>