适用于 ASP 的 Microsoft Index Server 类






3.67/5 (2投票s)
2005 年 9 月 12 日
2分钟阅读

54034

364
用于 ASP 的 Index Server 类,易于在您的网站上实现
引言
我的公司要求我在我们的内网网站上实现一个搜索引擎功能。他们不需要太花哨的,只需要允许用户搜索页面即可。由于我们的网站是基于 Microsoft 的,我首先想到的是 Index Server。我之前没有使用 Index Server 的经验,所以我在互联网上搜索了一些相关文章。让我开始使用 Index Server 的教程是 http://www.xefteri.com/articles/show.cfm?id=2。它包含了一个易于遵循的教程。当我尝试将代码应用到内网网站时,我发现实现起来不太方便。所以我决定将其修改为一个类。
以下是该项目的一些截图。
详细说明
该类包含 5 个主要函数。它们是:
- getArrAllData(byref msg) - 以数组形式返回结果内容
- getFirstLink (scriptName) - 返回到第一页的链接。需要当前文件名。
- getPreviousLink (scriptName) - 返回到上一页的链接。需要当前文件名。
- getNextLink (scriptName) - 返回到下一页的链接。需要当前文件名。
- getLastLink (scriptName) - 返回到最后一页的链接。需要当前文件名。
要使用该类,您需要实例化该类并初始化所需的值。
<!-- #include file="class/cls_text_search.asp" --> <% dim msg msg = ""
dim arrData dim objTxtSearch set objTxtSearch = New cls_text_search objTxtSearch.pageTitle = "Page Title - " objTxtSearch.catalog = "catalogName" objTxtSearch.query = Request("query") objTxtSearch.fileExts = "asp,html,pdf,doc,xls,ppt,txt,htm" objTxtSearch.ignoreFileWithPaths = "/xxx.html" objTxtSearch.includeFolderWithPaths = "/,/doc,/PDFs" objTxtSearch.recordsPerPage = "5" objTxtSearch.page = Request("page") objTxtSearch.order = Request("order")
on error resume next arrData = objTxtSearch.getArrAllData(msg) if err.number <> 0 then msg = err.description end if
%>
然后您可以从该类检索导航链接
<% Dim firstLink, previousLink, nextLink, lastLink firstLink = objTxtSearch.getFirstLink (Request.ServerVariables("SCRIPT_NAME")) previousLink = objTxtSearch.getPreviousLink (Request.ServerVariables("SCRIPT_NAME")) nextLink = objTxtSearch.getNextLink (Request.ServerVariables("SCRIPT_NAME")) lastLink = objTxtSearch.getLastLink (Request.ServerVariables("SCRIPT_NAME"))
' Navigation Link if firstLink = "" then Response.Write "First | " else Response.Write "<a href='" & firstLink & "' >First</a> | " if previousLink = "" then Response.Write "Previous | " else Response.Write "<a href='" & previousLink & "' >Previous</a> | " if nextLink = "" then Response.Write "Next | " else Response.Write "<a href='" & nextLink & "' >Next</a> | " if lastLink = "" then Response.Write "Last | " else Response.Write "<a href='" & lastLink & "' >Last</a>" %>
当然,您需要通过从 Index Server 获取的数组变量提取搜索结果。
<% Dim strDocTitle, strFilename, strVPath, intSize, datWrite, strCharacterization, numRank Dim numrows, rowcounter numrows = UBound(arrData,2) '-- now loop through the records For rowcounter= 0 To numrows '-- row values held in variables for ease of use strDocTitle = arrData(0, rowcounter) strFilename = arrData(1, rowcounter) strVPath = arrData(2, rowcounter) intSize = FormatNumber(arrData(3, rowcounter)) datWrite = arrData(4, rowcounter) strCharacterization = arrData(5, rowcounter) numRank = arrData(6, rowcounter) If IsNull(strCharacterization) Or Trim(strCharacterization) = "" Then strCharacterization = " " End If %> <tr><td colspan="2"></td> <td> <a href="<%=strVPath%>"><%= objTxtSearch.getCustomTitle (strDocTitle, strFilename)%></a> </td> </tr> <tr><td valign="top"> <% Dim starslocation, NormRank, stars starslocation = "images/rank/" '-- show proper image for ranking NormRank = numRank/10 If NormRank > 80 Then stars = "rankbtn5.gif" ElseIf NormRank > 60 Then stars = "rankbtn4.gif" ElseIf NormRank > 40 Then stars = "rankbtn3.gif" ElseIf NormRank > 20 Then stars = "rankbtn2.gif" Else stars = "rankbtn1.gif" End If '-- Chr(37) = % '-- write correct image and percentage ranking %> <img src="<%=starslocation & stars %>"> <br> <%= NormRank & Chr(37) %> </td> <td> </td> <td valign="top"> <%= strCharacterization %><br><br><i> <% '-- write file size or show error in case ' we have a NULL value returned If Trim(intSize) = "" Or IsNull(intSize) Then Response.Write("(size unknown) - ") Else Response.Write("size " & objTxtSearch.FileSize(intSize) & " - ") End If If Trim(datWrite) = "" Or IsNull(datWrite) Then Response.Write("(time unknown)") Else Response.Write(objTxtSearch.myFixDate(datWrite) & " GMT") End If %> </td> </tr> <tr><td colspan="3"> </td></tr> <% Next %>
就这样!所有逻辑都在类中,无需修改。当您的下一个项目需要添加搜索引擎功能时,您可以直接重用该类。我已经包含了该项目的完整源代码,希望您会喜欢。
参考文献
Windows 2000 索引服务 - http://www.xefteri.com/articles/show.cfm?id=2
您的免费搜索引擎 - Microsoft Indexing Server -https://codeproject.org.cn/aspnet/IndexingServer.asp
为您的网站添加搜索功能 - https://codeproject.org.cn/asp/indexserver.asp