home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / is20.cab / query.asp < prev    next >
Text File  |  1997-10-21  |  15KB  |  459 lines

  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN" "html.dtd">
  2. <HTML>
  3. <HEAD>
  4.  
  5. <%
  6. ' ********** INSTRUCTIONS FOR QUICK CUSTOMIZATION **********
  7. '
  8. ' This form is set up for easy customization. It allows you to modify the
  9. ' page logo, the page background, the page title and simple query
  10. ' parameters by modifying a few files and form variables. The procedures
  11. ' to do this are explained below.
  12. '
  13. '
  14. ' *** Modifying the Form Logo:
  15.  
  16. ' The logo for the form is named is2logo.gif. To change the page logo, simply
  17. ' name your logo is2logo.gif and place in the same directory as this form. If
  18. ' your logo is not a GIF file, or you don't want to copy it, change the following
  19. ' line so that the logo variable contains the URL to your logo.
  20.  
  21.         FormLogo = "is2logo.gif"
  22.  
  23. '
  24. ' *** Modifying the Form's background pattern.
  25.  
  26. ' You can use either a background pattern or a background color for your
  27. ' form. If you want to use a background pattern, store the file with the name
  28. ' is2bkgnd.gif in the same directory as this file and remove the remark character
  29. ' the single quote character) from the line below. Then put the remark character on
  30. ' the second line below.
  31. '
  32. ' If you want to use a different background color than white, simply edit the
  33. ' bgcolor line below, replacing white with your color choice.
  34.  
  35. '       FormBG = "background = " & chr(34) & "is2bkgnd.gif" & chr(34)
  36.         FormBG = "bgcolor = " & chr(34) & "#FFFFFF" & chr(34)
  37.  
  38.  
  39. ' *** Modifying the Form's Title Text.
  40.  
  41. ' The Form's title text is set on the following line.
  42. %>
  43.  
  44.     <TITLE>Sample ASP Search Form</TITLE>
  45.  
  46. <%
  47. '
  48. ' *** Modifying the Form's Search Scope.
  49. '
  50. ' The form will search from the root of your web server's namespace and below
  51. ' (deep from "/" ). To search a subset of your server, for example, maybe just
  52. ' a PressReleases directory, modify the scope variable below to list the virtual path to
  53. ' search. The search will start at the directory you specify and include all sub-
  54. ' directories.
  55.  
  56.         FormScope = "/"
  57.  
  58. '
  59. ' *** Modifying the Number of Returned Query Results.
  60. '
  61. ' You can set the number of query results returned on a single page
  62. ' using the variable below.
  63.  
  64.         PageSize = 10
  65.  
  66. '
  67. ' *** Setting the Locale.
  68. '
  69. ' The following line sets the locale used for queries. In most cases, this
  70. ' should match the locale of the server. You can set the locale below.
  71.  
  72.         SiteLocale = "EN-US"
  73.  
  74. ' ********** END QUICK CUSTOMIZATION SECTIONS ***********
  75. %>
  76.  
  77.  
  78.     <LINK REL=STYLESHEET HREF="is2style.css" TYPE="text/css">
  79.  
  80.     <META NAME="DESCRIPTION" CONTENT="Sample ASP query form for Microsoft Index Server v2.0">
  81.     <META NAME="AUTHOR"      CONTENT="Index Server Team">
  82.     <META NAME="KEYWORDS"    CONTENT="query, content, hit">
  83.     <META NAME="SUBJECT"     CONTENT="sample form">
  84.     <META NAME="MS.CATEGORY" CONTENT="Internet">
  85.     <META NAME="MS.LOCALE"   CONTENT="EN-US">
  86.     <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Windows-1252">
  87.  
  88. <%
  89. ' Set Initial Conditions
  90.     NewQuery = FALSE
  91.     UseSavedQuery = FALSE
  92.     SearchString = ""
  93.  
  94.     QueryForm = Request.ServerVariables("PATH_INFO")
  95.  
  96. ' Did the user press a SUBMIT button to execute the form? If so get the form variables.
  97.     if Request.ServerVariables("REQUEST_METHOD") = "POST" then
  98.         SearchString = Request.Form("SearchString")
  99.         FreeText = Request.Form("FreeText")
  100.         ' NOTE: this will be true only if the button is actually pushed.
  101.         if Request.Form("Action") = "Go" then
  102.             NewQuery = TRUE
  103.             RankBase=1000
  104.         end if
  105.     end if
  106.     if Request.ServerVariables("REQUEST_METHOD") = "GET" then
  107.         SearchString = Request.QueryString("qu")
  108.                 FreeText = Request.QueryString("FreeText")
  109.                 FormScope = Request.QueryString("sc")
  110.                 RankBase = Request.QueryString("RankBase")
  111.         if Request.QueryString("pg") <> "" then
  112.             NextPageNumber = Request.QueryString("pg")
  113.             NewQuery = FALSE
  114.             UseSavedQuery = TRUE
  115.         else
  116.             NewQuery = SearchString <> ""
  117.         end if
  118.     end if
  119. %>
  120.  
  121. </HEAD>
  122.  
  123. <BODY <%=FormBG%>>
  124.  
  125. <TABLE>
  126.     <TR><TD><A HREF="http://www.microsoft.com/ntserver/search" target="_top"><IMG SRC ="<%=FormLogo%>" VALIGN=MIDDLE ALIGN=LEFT border=0></a></TD></TR>
  127.     <TR><TD ALIGN="RIGHT"><H3>Sample ASP Search Form</H3></TD></TR>
  128. </TABLE>
  129.  
  130. <p>
  131.  
  132.         <FORM ACTION="<%=QueryForm%>" METHOD=POST>
  133.                 <TABLE WIDTH=500>
  134.                         <TR>
  135.                                 <TD>Enter your query below:</TD>
  136.                         </TR>
  137.                         <TR>
  138.                                 <TD><INPUT TYPE="TEXT" NAME="SearchString" SIZE="65" MAXLENGTH="100" VALUE="<%=SearchString%>"></TD>
  139.                                 <TD><INPUT TYPE="SUBMIT" NAME="Action" VALUE="Go"></TD>
  140.                         </TR>
  141.                                 <TR>
  142.                                 <TD ALIGN="RIGHT"><A HREF="ixtiphlp.htm">Tips for searching</A></TD>
  143.                         </TR>
  144.                         <TR>
  145.                         </TR>
  146.                         <TR>
  147.                                 <TD>
  148.                                         <INPUT NAME="FreeText" TYPE=CHECKBOX
  149.                                                                 <% if FreeText = "on" then
  150.                                                                                 Response.Write(" CHECKED")
  151.                                                                 end if %>>Use <a href="ixtiphlp.htm#FreeTextQueries">Free-Text Query</a>.
  152.                                 </TD>
  153.                         </TR>
  154.                 </TABLE>
  155.         </FORM>
  156.  
  157. <BR>
  158.  
  159. <%
  160.   if NewQuery then
  161.     set Session("Query") = nothing
  162.     set Session("Recordset") = nothing
  163.     NextRecordNumber = 1
  164.  
  165. ' Remove any leading and ending quotes from SearchString
  166.  
  167.         SrchStrLen = len(SearchString)
  168.  
  169.         if left(SearchString, 1) = chr(34) then
  170.                 SrchStrLen = SrchStrLen-1
  171.                 SearchString = right(SearchString, SrchStrLen)
  172.         end if
  173.  
  174.         if right(SearchString, 1) = chr(34) then
  175.                 SrchStrLen = SrchStrLen-1
  176.                 SearchString = left(SearchString, SrchStrLen)
  177.         end if
  178.  
  179.     if FreeText = "on" then
  180.       CompSearch = "$contents " & chr(34) & SearchString & chr(34)
  181.     else
  182.       CompSearch = SearchString
  183.     end if
  184.  
  185.     set Q = Server.CreateObject("ixsso.Query")
  186.         set util = Server.CreateObject("ixsso.Util")
  187.  
  188.     Q.Query = CompSearch
  189.     Q.SortBy = "rank[d]"
  190.     Q.Columns = "DocTitle, vpath, filename, size, write, characterization, rank"
  191.     Q.MaxRecords = 300 
  192.  
  193.  
  194.         if FormScope <> "/" then
  195.                 util.AddScopeToQuery Q, FormScope, "deep"
  196.         end if
  197.  
  198.         if SiteLocale<>"" then
  199.                 Q.LocaleID = util.ISOToLocaleID(SiteLocale)
  200.         end if
  201.  
  202.     set RS = Q.CreateRecordSet("nonsequential")
  203.  
  204.     RS.PageSize = PageSize
  205.     ActiveQuery = TRUE
  206.  
  207.   elseif UseSavedQuery then
  208.     if IsObject( Session("Query") ) And IsObject( Session("RecordSet") ) then
  209.       set Q = Session("Query")
  210.       set RS = Session("RecordSet")
  211.  
  212.       if RS.RecordCount <> -1 and NextPageNumber <> -1 then
  213.         RS.AbsolutePage = NextPageNumber
  214.         NextRecordNumber = RS.AbsolutePosition
  215.       end if
  216.  
  217.       ActiveQuery = TRUE
  218.     else
  219.       Response.Write "ERROR - No saved query"
  220.     end if
  221.   end if
  222.  
  223.   if ActiveQuery then
  224.     if not RS.EOF then
  225.  %>
  226.  
  227. <p>
  228. <HR WIDTH=80% ALIGN=center SIZE=3>
  229. <p>
  230.  
  231. <%
  232.         LastRecordOnPage = NextRecordNumber + RS.PageSize - 1
  233.         CurrentPage = RS.AbsolutePage
  234.         if RS.RecordCount <> -1 AND RS.RecordCount < LastRecordOnPage then
  235.             LastRecordOnPage = RS.RecordCount
  236.         end if
  237.  
  238.         Response.Write "Documents " & NextRecordNumber & " to " & LastRecordOnPage
  239.         if RS.RecordCount <> -1 then
  240.             Response.Write " of " & RS.RecordCount
  241.         end if
  242.         Response.Write " matching the query " & chr(34) & "<I>"
  243.         Response.Write SearchString & "</I>" & chr(34) & ".<P>"
  244.  %>
  245.  
  246. <% if Not RS.EOF and NextRecordNumber <= LastRecordOnPage then%>
  247.         <table border=0>
  248.         <colgroup width=105>
  249. <% end if %>
  250.  
  251. <% Do While Not RS.EOF and NextRecordNumber <= LastRecordOnPage
  252.  
  253.         ' This is the detail portion for Title, Abstract, URL, Size, and
  254.     ' Modification Date.
  255.  
  256.     ' If there is a title, display it, otherwise display the filename.
  257. %>
  258.     <p>
  259.  
  260. <% ' Graphically indicate rank of document with list of stars (*'s).
  261.  
  262.     if NextRecordNumber = 1 then
  263.         RankBase=RS("rank")
  264.     end if
  265.  
  266.     if RankBase>1000 then
  267.         RankBase=1000
  268.     elseif RankBase<1 then
  269.         RankBase=1
  270.     end if
  271.  
  272.     NormRank = RS("rank")/RankBase
  273.  
  274.     if NormRank > 0.80 then
  275.         stars = "rankbtn5.gif"
  276.     elseif NormRank > 0.60 then
  277.         stars = "rankbtn4.gif"
  278.     elseif NormRank > 0.40 then
  279.         stars = "rankbtn3.gif"
  280.     elseif NormRank >.20 then
  281.         stars = "rankbtn2.gif"
  282.     else stars = "rankbtn1.gif"
  283.  
  284.     end if
  285.  
  286. %>
  287.  
  288.     <tr class="RecordTitle">
  289.         <td align="right" valign=top class="RecordTitle">
  290.             <%= NextRecordNumber%>.
  291.         </td>
  292.         <td><b class="RecordTitle"> 
  293.             <%if VarType(RS("DocTitle")) = 1 or RS("DocTitle") = "" then%>
  294.                 <a href="<%=RS("vpath")%>" class="RecordTitle"><%= Server.HTMLEncode( RS("filename") )%></a>
  295.             <%else%>
  296.                 <a href="<%=RS("vpath")%>" class="RecordTitle"><%= Server.HTMLEncode(RS("DocTitle"))%></a>
  297.             <%end if%>
  298.         </b></td>
  299.     </tr>
  300.  
  301.     <tr>
  302.         <td valign=top align=left>
  303.             <IMG SRC="<%=stars%>">
  304.             <br>
  305. <%
  306.     ' Construct the URL for hit highlighting
  307.             WebHitsQuery = "CiWebHitsFile=" & Server.URLEncode( RS("vpath") )
  308.             WebHitsQuery = WebHitsQuery & "&CiRestriction=" & Server.URLEncode( Q.Query )
  309.             WebHitsQuery = WebHitsQuery & "&CiBeginHilite=" & Server.URLEncode( "<strong class=Hit>" )
  310.             WebHitsQuery = WebHitsQuery & "&CiEndHilite=" & Server.URLEncode( "</strong>" )
  311.             WebHitsQuery = WebHitsQuery & "&CiUserParam3=" & QueryForm
  312. '            WebHitsQuery = WebHitsQuery & "&CiLocale=" & Q.LocaleID
  313.  %>
  314.             <a href="oop/qsumrhit.htw?<%= WebHitsQuery %>"><IMG src="hilight.gif" align=left alt="Highlight matching terms in document using Summary mode."> Summary</a>
  315.             <br>
  316.             <a href="oop/qfullhit.htw?<%= WebHitsQuery %>&CiHiliteType=Full"><IMG src="hilight.gif" align=left alt="Highlight matching terms in document."> Full</a>
  317.         </td>
  318.         <td valign=top>
  319.             <%if VarType(RS("characterization")) = 8 and RS("characterization") <> "" then%>
  320.                 <b><i>Abstract:  </I></b><%= Server.HTMLEncode(RS("characterization"))%>
  321.             <%end if%>
  322.             <p>
  323.             <i class="RecordStats"><a href="<%=RS("vpath")%>" class="RecordStats" style="color:blue;">http://<%=Request("server_name")%><%=RS("vpath")%></a>
  324.             <br><%if RS("size") = "" then%>(size and time unknown)<%else%>size <%=RS("size")%> bytes - <%=RS("write")%> GMT<%end if%></i>
  325.         </td>
  326.     </tr>
  327.     <tr>
  328.     </tr>
  329.  
  330. <%
  331.           RS.MoveNext
  332.           NextRecordNumber = NextRecordNumber+1
  333.       Loop
  334.  %>
  335.  
  336. </table>
  337.  
  338. <P><BR>
  339.  
  340. <%
  341.   else   ' NOT RS.EOF
  342.       if NextRecordNumber = 1 then
  343.           Response.Write "No documents matched the query<P>"
  344.       else
  345.           Response.Write "No more documents in the query<P>"
  346.       end if
  347.  
  348.   end if ' NOT RS.EOF
  349.  
  350.  
  351. if NOT Q.OutOfDate then
  352. ' If the index is current, display the fact %>
  353. <P>
  354.     <I><B>The index is up to date.</B></I><BR>
  355. <%end if
  356.  
  357.  
  358.   if Q.QueryIncomplete then
  359. '    If the query was not executed because it needed to enumerate to
  360. '    resolve the query instead of using the index, but AllowEnumeration
  361. '    was FALSE, let the user know %>
  362.  
  363.     <P>
  364.     <I><B>The query is too expensive to complete.</B></I><BR>
  365. <%end if
  366.  
  367.  
  368.   if Q.QueryTimedOut then
  369. '    If the query took too long to execute (for example, if too much work
  370. '    was required to resolve the query), let the user know %>
  371.     <P>
  372.     <I><B>The query took too long to complete.</B></I><BR>
  373. <%end if%>
  374.  
  375.  
  376. <TABLE>
  377.  
  378. <%
  379. '    This is the "previous" button.
  380. '    This retrieves the previous page of documents for the query.
  381. %>
  382.  
  383. <%SaveQuery = FALSE%>
  384. <%if CurrentPage > 1 and RS.RecordCount <> -1 then %>
  385.     <td align=left>
  386.         <form action="<%=QueryForm%>" method="get">
  387.             <INPUT TYPE="HIDDEN" NAME="qu" VALUE="<%=SearchString%>">
  388.                         <INPUT TYPE="HIDDEN" NAME="FreeText" VALUE="<%=FreeText%>">
  389.             <INPUT TYPE="HIDDEN" NAME="sc" VALUE="<%=FormScope%>">
  390.             <INPUT TYPE="HIDDEN" name="pg" VALUE="<%=CurrentPage-1%>" >
  391.             <INPUT TYPE="HIDDEN" NAME = "RankBase" VALUE="<%=RankBase%>">
  392.             <input type="submit" value="Previous <%=RS.PageSize%> documents">
  393.         </form>
  394.     </td>
  395.         <%SaveQuery = TRUE%>
  396. <%end if%>
  397.  
  398.  
  399. <%
  400. '    This is the "next" button for unsorted queries.
  401. '    This retrieves the next page of documents for the query.
  402.  
  403.   if Not RS.EOF then%>
  404.     <td align=right>
  405.         <form action="<%=QueryForm%>" method="get">
  406.             <INPUT TYPE="HIDDEN" NAME="qu" VALUE="<%=SearchString%>">
  407.                         <INPUT TYPE="HIDDEN" NAME="FreeText" VALUE="<%=FreeText%>">
  408.             <INPUT TYPE="HIDDEN" NAME="sc" VALUE="<%=FormScope%>">
  409.             <INPUT TYPE="HIDDEN" NAME = "RankBase" VALUE="<%=RankBase%>">
  410.             <INPUT TYPE="HIDDEN" name="pg" VALUE="<%=CurrentPage+1%>">
  411.  
  412.             <% NextString = "Next "
  413.                if RS.RecordCount <> -1 then
  414.                    NextSet = (RS.RecordCount - NextRecordNumber) + 1
  415.                    if NextSet > RS.PageSize then
  416.                        NextSet = RS.PageSize
  417.                    end if
  418.                    NextString = NextString & NextSet & " documents"
  419.                else
  420.                    NextString = NextString & " page of documents"
  421.                end if
  422.              %>
  423.             <input type="submit" value="<%=NextString%>">
  424.         </form>
  425.     </td>
  426.     <%SaveQuery = TRUE%>
  427. <%end if%>
  428.  
  429. </TABLE>
  430.  
  431. <% ' Display the page number %>
  432.  
  433. Page <%=CurrentPage%>
  434. <%if RS.PageCount <> -1 then
  435.      Response.Write " of " & RS.PageCount
  436.   end if %>
  437.  
  438. <%
  439.     ' If either of the previous or back buttons were displayed, save the query
  440.     ' and the recordset in session variables.
  441.     if SaveQuery then
  442.         set Session("Query") = Q
  443.         set Session("RecordSet") = RS
  444.     else
  445.         RS.close
  446.         Set RS = Nothing
  447.         Set Q = Nothing
  448.         set Session("Query") = Nothing
  449.         set Session("RecordSet") = Nothing
  450.     end if
  451.  %>
  452. <% end if %>
  453.  
  454. <!--#include file ="is2foot.inc"-->
  455.  
  456. </BODY>
  457. </HTML>
  458.  
  459.