A rchive Date
[ 09-05-2006 ]
Category
[ Information Technologies ]
sub-Categoy
[ Microsoft ]
|
[http://www.codeproject.com/useritems/clsTextSearch.asp
Microsoft Index Server class for ASP
Index Server class for ASP, easy to implement on your website
By Ken Yim
Details
The class contains 5 main functions. They are:
getArrAllData(byref msg) - return result content as an array
getFirstLink (scriptName) - return a link to return the first page. Current file name is required.
getPreviousLink (scriptName) - return a link to return previous page. Current file name is required.
getNextLink (scriptName) - return a link to the next page. Current file name is required.
getLastLink (scriptName) - return a link to the last page. Current file name is required.
To use the class, you need to instantiate the class and initialize the required value.
<!-- #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
%>
Then you can retrieve the navigation links from the class
<%
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>"
%>
Of course, you need to extract the search result through the array variable from 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
%>
That's it! All logic is in the class, there is no need to modify it. And you can just reuse the class when your next project need to add a search engine function. I have included the full source code of this project, hope you will like it.
References
The Windows 2000 Indexing Service - http://www.xefteri.com/articles/show.cfm?id=2
Your free search Engine - Microsoft Indexing Server - http://www.codeproject.com/aspnet/IndexingServer.asp
Adding a search facility to your website - http://www.codeproject.com/asp/indexserver.asp
Article content copyright Ken Yim, 2005
everything else Copyright © CodeProject, 1999-2006.
Web6 | Advertise on The Code Project | Privacy]
|