Click here to Skip to main content
12,550,593 members (43,415 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked

Microsoft Index Server class for ASP

, 12 Sep 2005
Rate this:
Please Sign up or sign in to vote.
Index Server class for ASP, easy to implement on your website


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 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


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=<span class="code-string">"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" = 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>

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>"

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>
           <a href="<%=strVPath%>"><%= objTxtSearch.getCustomTitle (strDocTitle, strFilename)%></a>
         <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"
              stars = "rankbtn1.gif"
            End If
           '-- Chr(37) = %
           '-- write correct image and percentage ranking
           <img src="<%=starslocation & stars %>">
           <%= NormRank & Chr(37) %>
          <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) - ")
              Response.Write("size " & objTxtSearch.FileSize(intSize) & " - ")
            End If
            If Trim(datWrite) = "" Or IsNull(datWrite) Then
              Response.Write("(time unknown)")
              Response.Write(objTxtSearch.myFixDate(datWrite) & " GMT")
            End If
         <tr><td colspan="3"> </td></tr>

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.


The Windows 2000 Indexing Service -
Your free search Engine - Microsoft Indexing Server -
Adding a search facility to your website -


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


About the Author

Ken Yim
Web Developer
Canada Canada
I am working as a web developer in Loblaw. 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!

You may also be interested in...


Comments and Discussions

GeneralKen Yim's Index Server Pin
timsage15-Sep-06 0:07
membertimsage15-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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161021.1 | Last Updated 12 Sep 2005
Article Copyright 2005 by Ken Yim
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid