Click here to Skip to main content
15,884,099 members
Articles / Programming Languages / VBScript
Article

Microsoft Index Server class for ASP

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
12 Sep 20052 min read 36.1K   364   19   1
Index Server class for ASP, easy to implement on your website

Introduction

My company asked me to implement a search engine function to our intranet website. They don't need too fancy one, just simply allow user to search the pages. Because our website is Microsoft based, the first thing come to my mind is Index Server. I had no experience on using Index server before, so I looked for the Internet and found some articles about it. The tutorial that made me to start my fiirst test drive of using Index Server is http://www.xefteri.com/articles/show.cfm?id=2. It contained an easy-to-follow tutorial to start. As I tried to start to use the code to my the intranet website, I found that it is not very convenient to implement. So I decided to modify it to become a class.

Here are some screen shot of this project.

Sample image

Sample image

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.

<P><!-- #include file="class/cls_text_search.asp" -->
<%
 dim msg
 msg = ""</P>
<P> 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")</P>
<P> on error resume next
 arrData = objTxtSearch.getArrAllData(msg)
 if err.number <> 0 then
  msg = err.description
 end if</P>
<P>%></P>

Then you can retrieve the navigation links from the class

<P>       <%
       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"))</P>
<P>       ' 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>"
       %></P>

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Canada Canada
I am working as a IT developer in S+A. This is my favourite job that I would like to do in the rest of my life.



Nothing is perfect, but I will do my best!

Comments and Discussions

 
GeneralKen Yim's Index Server Pin
timsage15-Sep-06 0:07
timsage15-Sep-06 0:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.