home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / query.asp < prev    next >
Text File  |  1997-11-01  |  14KB  |  411 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.  
  75.  
  76. ' ********** END QUICK CUSTOMIZATION SECTIONS ***********
  77. %>
  78.  
  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.         end if
  104.     end if
  105.     if Request.ServerVariables("REQUEST_METHOD") = "GET" then
  106.         SearchString = Request.QueryString("qu")
  107.                 FreeText = Request.QueryString("FreeText")
  108.                 FormScope = Request.QueryString("sc")
  109.         if Request.QueryString("pg") <> "" then
  110.             NextPageNumber = Request.QueryString("pg")
  111.             NewQuery = FALSE
  112.             UseSavedQuery = TRUE
  113.         else
  114.             NewQuery = SearchString <> ""
  115.         end if
  116.     end if
  117. %>
  118.  
  119. </HEAD>
  120.  
  121. <BODY <%=FormBG%>>
  122.  
  123. <TABLE>
  124.     <TR><TD><A HREF="http://www.microsoft.com/ntserver/search" style="text-decoration: none" target="_top"><IMG SRC ="<%=FormLogo%>" VALIGN=MIDDLE ALIGN=LEFT></a></TD></TR>
  125.     <TR><TD ALIGN="RIGHT"><H3>Sample ASP Search Form</H3></TD></TR>
  126. </TABLE>
  127.  
  128. <p>
  129.  
  130.         <FORM ACTION="<%=QueryForm%>" METHOD=POST>
  131.                 <TABLE WIDTH=500>
  132.                         <TR>
  133.                                 <TD>Enter your query below:</TD>
  134.                         </TR>
  135.                         <TR>
  136.                                 <TD><INPUT TYPE="TEXT" NAME="SearchString" SIZE="80" MAXLENGTH="100" VALUE="<%=SearchString%>"></TD>
  137.                                 <TD><INPUT TYPE="SUBMIT" NAME="Action" VALUE="Go"></TD>
  138.                         </TR>
  139.                                 <TR>
  140.                                 <TD ALIGN="RIGHT"><A HREF="ixqlang.htm">Tips for searching</A></TD>
  141.                         </TR>
  142.                         <TR>
  143.                         </TR>
  144.                         <TR>
  145.                                 <TD>
  146.                                         <P><INPUT NAME="FreeText" TYPE=CHECKBOX
  147.                                                                 <% if FreeText = "on" then
  148.                                                                                 Response.Write(" CHECKED")
  149.                                                                 end if %>>Search for any combination of words entered above.
  150.                                 </TD>
  151.                         </TR>
  152.                 </TABLE>
  153.         </FORM>
  154.  
  155. <BR>
  156.  
  157. <%
  158.   if NewQuery then
  159.     set Session("Query") = nothing
  160.     set Session("Recordset") = nothing
  161.     NextRecordNumber = 1
  162.  
  163. ' Remove any leading and ending quotes from SearchString
  164.  
  165.         SrchStrLen = len(SearchString)
  166.  
  167.         if left(SearchString, 1) = chr(34) then
  168.                 SrchStrLen = SrchStrLen-1
  169.                 SearchString = right(SearchString, SrchStrLen)
  170.         end if
  171.  
  172.         if right(SearchString, 1) = chr(34) then
  173.                 SrchStrLen = SrchStrLen-1
  174.                 SearchString = left(SearchString, SrchStrLen)
  175.         end if
  176.  
  177.     if FreeText = "on" then
  178.       CompSearch = "$contents " & chr(34) & SearchString & chr(34)
  179.     else
  180.       CompSearch = SearchString
  181.     end if
  182.  
  183.     set Q = Server.CreateObject("ixsso.Query")
  184.         set util = Server.CreateObject("ixsso.Util")
  185.  
  186.     Q.Query = CompSearch
  187.     Q.SortBy = "rank[d]"
  188.     Q.Columns = "DocTitle, vpath, filename, size, write, characterization"
  189.  
  190.         if FormScope <> "/" then
  191.                 util.AddScopeToQuery Q, FormScope, "deep"
  192.         end if
  193.  
  194.         if SiteLocale<>"" then
  195.                 Q.LocaleID = util.ISOToLocaleID(SiteLocale)
  196.         end if
  197.  
  198.     set RS = Q.CreateRecordSet("nonsequential")
  199.  
  200.     RS.PageSize = PageSize
  201.     ActiveQuery = TRUE
  202.  
  203.   elseif UseSavedQuery then
  204.     if IsObject( Session("Query") ) And IsObject( Session("RecordSet") ) then
  205.       set Q = Session("Query")
  206.       set RS = Session("RecordSet")
  207.  
  208.       if RS.RecordCount <> -1 and NextPageNumber <> -1 then
  209.         RS.AbsolutePage = NextPageNumber
  210.         NextRecordNumber = RS.AbsolutePosition
  211.       end if
  212.  
  213.       ActiveQuery = TRUE
  214.     else
  215.       Response.Write "ERROR - No saved query"
  216.     end if
  217.   end if
  218.  
  219.   if ActiveQuery then
  220.     if not RS.EOF then
  221.  %>
  222.  
  223. <p>
  224. <HR WIDTH=80% ALIGN=center SIZE=3>
  225. <p>
  226.  
  227. <%
  228.         LastRecordOnPage = NextRecordNumber + RS.PageSize - 1
  229.         CurrentPage = RS.AbsolutePage
  230.         if RS.RecordCount <> -1 AND RS.RecordCount < LastRecordOnPage then
  231.             LastRecordOnPage = RS.RecordCount
  232.         end if
  233.  
  234.         Response.Write "Documents " & NextRecordNumber & " to " & LastRecordOnPage
  235.         if RS.RecordCount <> -1 then
  236.             Response.Write " of " & RS.RecordCount
  237.         end if
  238.         Response.Write " matching the query " & chr(34) & "<I>"
  239.         Response.Write SearchString & "</I>" & chr(34) & ".<P>"
  240.  %>
  241.  
  242. <dl>
  243. <% Do While Not RS.EOF and NextRecordNumber <= LastRecordOnPage
  244.  
  245.         ' This is the detail portion for Title, Abstract, URL, Size, and
  246.     ' Modification Date.
  247.  
  248.     ' If there is a title, display it, otherwise display the filename.
  249. %>
  250.     <p>
  251.     <dt><%= NextRecordNumber%>.
  252.         <%if VarType(RS("DocTitle")) = 1 or RS("DocTitle") = "" then%>
  253.             <b><a href="<%=RS("vpath")%>"><%= Server.HTMLEncode( RS("filename") )%></a></b>
  254.         <%else%>
  255.             <b><a href="<%=RS("vpath")%>"><%= Server.HTMLEncode(RS("DocTitle"))%></a></b>
  256.         <%end if%>
  257.     <dd>
  258.         <%if VarType(RS("characterization")) = 8 and RS("characterization") <> "" then%>
  259.             <b><i>Abstract:  </I></b><%= Server.HTMLEncode(RS("characterization"))%>
  260.             <br>
  261.         <%end if%>
  262.         <cite>
  263.             <a href="<%=RS("vpath")%>">http://<%=Request("server_name")%><%=RS("vpath")%></a>
  264.             <font size=-1> - <%if RS("size") = "" then%>(size and time unknown)<%else%>size <%=RS("size")%> bytes - <%=RS("write")%> GMT<%end if%></font>
  265.         </cite>
  266.  
  267.                 <%if SearchString <> "" then%>
  268.         <BR>
  269. <%
  270.     ' Construct the URL for hit highlighting
  271.  
  272.     WebHitsQuery = "CiWebHitsFile=" & Server.URLEncode( RS("vpath") )
  273.     WebHitsQuery = WebHitsQuery & "&CiRestriction=" & Server.URLEncode( Q.Query )
  274.     WebHitsQuery = WebHitsQuery & "&CiBeginHilite=" & Server.URLEncode( "<font color=""#FF0000""><b><em>" )
  275.     WebHitsQuery = WebHitsQuery & "&CiEndHilite=" & Server.URLEncode( "</em></b></font>" )
  276.     WebHitsQuery = WebHitsQuery & "&CiUserParam3=" & QueryForm
  277. '       WebHitsQuery = WebHitsQuery & "&CiLocale=" & Q.LocaleID
  278.  %>
  279.         <a href="/iissamples/issamples/oop/qsumrhit.htw?<%= WebHitsQuery %>"><b>Show Highlights (condensed)</b></a> /
  280.         <a href="/iissamples/issamples/oop/qfullhit.htw?<%= WebHitsQuery %>&CiHiliteType=Full"><b>Show Highlights (full text)</b></a>
  281.         <BR>
  282.         <%end if%>
  283.  
  284. <%
  285.           RS.MoveNext
  286.           NextRecordNumber = NextRecordNumber+1
  287.       Loop
  288.  %>
  289.  
  290. </dl>
  291.  
  292. <P><BR>
  293.  
  294. <%
  295.   else   ' NOT RS.EOF
  296.       if NextRecordNumber = 1 then
  297.           Response.Write "No documents matched the query<P>"
  298.       else
  299.           Response.Write "No more documents in the query<P>"
  300.       end if
  301.  
  302.   end if ' NOT RS.EOF
  303.  
  304.  
  305. if NOT Q.OutOfDate then
  306. ' If the index is current, display the fact %>
  307. <P>
  308.     <I><B>The index is up to date.</B></I><BR>
  309. <%end if
  310.  
  311.  
  312.   if Q.QueryIncomplete then
  313. '    If the query was not executed because it needed to enumerate to
  314. '    resolve the query instead of using the index, but AllowEnumeration
  315. '    was FALSE, let the user know %>
  316.  
  317.     <P>
  318.     <I><B>The query is too expensive to complete.</B></I><BR>
  319. <%end if
  320.  
  321.  
  322.   if Q.QueryTimedOut then
  323. '    If the query took too long to execute (for example, if too much work
  324. '    was required to resolve the query), let the user know %>
  325.     <P>
  326.     <I><B>The query took too long to complete.</B></I><BR>
  327. <%end if%>
  328.  
  329.  
  330. <TABLE>
  331.  
  332. <%
  333. '    This is the "previous" button.
  334. '    This retrieves the previous page of documents for the query.
  335. %>
  336.  
  337. <%SaveQuery = FALSE%>
  338. <%if CurrentPage > 1 and RS.RecordCount <> -1 then %>
  339.     <td align=left>
  340.         <form action="<%=QueryForm%>" method="get">
  341.             <INPUT TYPE="HIDDEN" NAME="qu" VALUE="<%=SearchString%>">
  342.                         <INPUT TYPE="HIDDEN" NAME="FreeText" VALUE="<%=FreeText%>">
  343.             <INPUT TYPE="HIDDEN" NAME="sc" VALUE="<%=FormScope%>">
  344.             <INPUT TYPE="HIDDEN" name="pg" VALUE="<%=CurrentPage-1%>" >
  345.             <input type="submit" value="Previous <%=RS.PageSize%> documents">
  346.         </form>
  347.     </td>
  348.         <%SaveQuery = TRUE%>
  349. <%end if%>
  350.  
  351.  
  352. <%
  353. '    This is the "next" button for unsorted queries.
  354. '    This retrieves the next page of documents for the query.
  355.  
  356.   if Not RS.EOF then%>
  357.     <td align=right>
  358.         <form action="<%=QueryForm%>" method="get">
  359.             <INPUT TYPE="HIDDEN" NAME="qu" VALUE="<%=SearchString%>">
  360.                         <INPUT TYPE="HIDDEN" NAME="FreeText" VALUE="<%=FreeText%>">
  361.             <INPUT TYPE="HIDDEN" NAME="sc" VALUE="<%=FormScope%>">
  362.             <INPUT TYPE="HIDDEN" name="pg" VALUE="<%=CurrentPage+1%>" >
  363.  
  364.             <% NextString = "Next "
  365.                if RS.RecordCount <> -1 then
  366.                    NextSet = (RS.RecordCount - NextRecordNumber) + 1
  367.                    if NextSet > RS.PageSize then
  368.                        NextSet = RS.PageSize
  369.                    end if
  370.                    NextString = NextString & NextSet & " documents"
  371.                else
  372.                    NextString = NextString & " page of documents"
  373.                end if
  374.              %>
  375.             <input type="submit" value="<%=NextString%>">
  376.         </form>
  377.     </td>
  378.     <%SaveQuery = TRUE%>
  379. <%end if%>
  380.  
  381. </TABLE>
  382.  
  383. <% ' Display the page number %>
  384.  
  385. Page <%=CurrentPage%>
  386. <%if RS.PageCount <> -1 then
  387.      Response.Write " of " & RS.PageCount
  388.   end if %>
  389.  
  390. <%
  391.     ' If either of the previous or back buttons were displayed, save the query
  392.     ' and the recordset in session variables.
  393.     if SaveQuery then
  394.         set Session("Query") = Q
  395.         set Session("RecordSet") = RS
  396.     else
  397.         RS.close
  398.         Set RS = Nothing
  399.         Set Q = Nothing
  400.         set Session("Query") = Nothing
  401.         set Session("RecordSet") = Nothing
  402.     end if
  403.  %>
  404. <% end if %>
  405.  
  406. <!--#include file ="is2foot.inc"-->
  407.  
  408. </BODY>
  409. </HTML>
  410.  
  411.