WordType Designs
Driven To Distractions©
The Sound of One Hand Clapping©


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 = "&nbsp;"
      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>&nbsp;</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">&nbsp;</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]


Some pages may require Adobe Acrobat Reader



Copyright and Fair Use Information: The contents of this web site is protected by international copyright laws and may not be reproduced in any form or manner whatsoever, if for the purpose of resale or solicitation of a donation. The essays included here, may be reproduced only if: 1)They are not altered in any way; 2) reproductions must be accompanied by this copyright page ; and 3) it is given freely and without charge.
Fair use: The fair use of copyrighted work, including such use by reproduction in copies or phonorecords or by any other means specified in above sections, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright. In determining whether the use made of a work in any particular case is fair use the factors to be considered include : (1) the purpose and character of the use, including whether the use is of a commercial nature or is for nonprofit educational purposes; (2) the nature of the copyrighted work; (3) the amount and substantiality of the portion used in relation to the copyrighted work as a whole, and; (4) the effect of the use upon the potential market value of the copyrighted work.

Home | About Narrative? |Contact
Copyright © 2025. All Rights Reserved
HAG122125 (1998 -2026)