home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 9 / IOPROG_9.ISO / contrib / iis4 / is20.cab / AdvSQLQ.asp < prev    next >
Encoding:
Text File  |  1997-08-15  |  12.0 KB  |  378 lines

  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN" "html.dtd">
  2. <HTML>
  3. <HEAD>
  4. <SCRIPT LANGUAGE="VBScript" RUNAT="Server">
  5. <!--#INCLUDE FILE="adovbs.inc"-->
  6.  
  7. </SCRIPT>
  8. <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#000066" VLINK="#808080" ALINK="#FF0000" TOPMARGIN=0 >
  9. <TITLE>Advanced Index Server Search Form</TITLE>
  10. <META NAME="DESCRIPTION" CONTENT="Sample SQL query form for Microsoft Index Server">
  11. <META NAME="AUTHOR"      CONTENT="OLE DB Provider for Index Server Team">
  12. <META NAME="KEYWORDS"    CONTENT="sql, query, content, hit">
  13. <META NAME="SUBJECT"     CONTENT="sample form">
  14. <META NAME="MS.CATEGORY" CONTENT="Internet">
  15. <META NAME="MS.LOCALE"   CONTENT="EN-US">
  16. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Windows-1252">
  17. <%
  18. Const STAT_BUSY    = 0  
  19. Const STAT_ERROR = &H1 
  20. Const STAT_DONE    = &H2  
  21. Const STAT_REFRESH    = &H3  
  22. Const STAT_PARTIAL_SCOPE    = &H8  
  23. Const STAT_NOISE_WORDS    = &H10  
  24. Const STAT_CONTENT_OUT_OF_DATE    = &H20  
  25. Const STAT_REFRESH_INCOMPLETE    = &H40  
  26. Const STAT_CONTENT_QUERY_INCOMPLETE    = &H80  
  27. Const STAT_TIME_LIMIT_EXCEEDED    = &H100  
  28.  
  29. Function GetCiOutOfDate(value)
  30.     GetCiOutOfDate = value And STAT_CONTENT_OUT_OF_DATE
  31. end Function
  32.  
  33. Function GetCiQueryIncomplete(value)
  34.     GetCiQueryIncomplete = value And STAT_CONTENT_QUERY_INCOMPLETE
  35. end Function
  36.  
  37. Function GetCiQueryTimedOut(value)
  38.     GetCiQueryTimedOut = value And STAT_TIME_LIMIT_EXCEEDED
  39. end Function
  40.  
  41. DebugFlag = FALSE
  42. NewQuery = FALSE
  43. SearchString = ""
  44. CiMaxRecords = 10
  45. if Request.ServerVariables("REQUEST_METHOD") = "POST" then
  46.     SearchString = Request.Form("SearchString")
  47.     DocAuthorRestriction = Request.Form("DocAuthorRestriction")
  48.     FSRest = Request.Form("FSRest")
  49.     FSRestVal = Request.Form("FSRestVal")
  50.     FSRestOther = Request.Form("FSRestOther")
  51.     FMMod = Request.Form("FMMod")
  52.     FMModDate = Request.Form("FMModDate")
  53.     SortBy = Request.Form("SortBy")
  54.     Colset = Request.Form("ColChoice")
  55.     CiMaxRecords = Request.Form("CiMaxRecords")
  56.     NewQuery = TRUE
  57. End if
  58. %>
  59. </HEAD>
  60.  
  61. <TABLE>
  62.     <TR><TD><A HREF="http://www.microsoft.com/ntserver/search" style="text-decoration: none" target="_top"><IMG SRC ="is2logo.gif" VALIGN=MIDDLE ALIGN=LEFT></a></TD></TR>
  63.     <TR><TD ALIGN="RIGHT"><H3>Advanced SQL Sample</H3></TD></TR>
  64. </TABLE>
  65.  
  66.  
  67. <SCRIPT LANGUAGE=JavaScript>
  68. <!--
  69. function SetAll()
  70. {
  71.     document.QForm.SearchString.value = "<%=SearchString%>";
  72.     document.QForm.CiMaxRecords.Value = <%=CiMaxRecords%>;
  73.  
  74.     <%select case FSRest%>
  75.     <%case " > "%>
  76.         document.QForm.FSRest.selectedIndex = 1;
  77.     <%case else%>
  78.         document.QForm.FSRest.selectedIndex = 0;
  79.     <%end select%>
  80.  
  81.     <%select case FSRestVal%>
  82.     <%case "any"%>
  83.         document.QForm.FSRestVal.selectedIndex = 0;
  84.     <%case "100"%>
  85.         document.QForm.FSRestVal.selectedIndex = 1;
  86.     <%case "1024"%>
  87.         document.QForm.FSRestVal.selectedIndex = 2;
  88.     <%case "10240"%>
  89.         document.QForm.FSRestVal.selectedIndex = 3;
  90.     <%case "102400"%>
  91.         document.QForm.FSRestVal.selectedIndex = 4;
  92.     <%case "1048576"%>
  93.         document.QForm.FSRestVal.selectedIndex = 5;
  94.     <%case "10485760"%>
  95.         document.QForm.FSRestVal.selectedIndex = 6;
  96.     <%case "104857600"%>
  97.         document.QForm.FSRestVal.selectedIndex = 7;
  98.     <%case "other"%>
  99.         document.QForm.FSRestVal.selectedIndex = 8;
  100.     <%case else%>
  101.         document.QForm.FSRestVal.selectedIndex = 0;
  102.     <%end select%>
  103.  
  104.     document.QForm.FSRestOther.value = "<%=FSRestOther%>";
  105.  
  106.     <%select case FMMod%>
  107.     <%case "any"%>
  108.         document.QForm.FMMod.selectedIndex = 0;
  109.     <%case "-10n"%>
  110.         document.QForm.FMMod.selectedIndex = 1;
  111.     <%case "-1h"%>
  112.         document.QForm.FMMod.selectedIndex = 2;
  113.     <%case "-1d"%>
  114.         document.QForm.FMMod.selectedIndex = 3;
  115.     <%case "-1w"%>
  116.         document.QForm.FMMod.selectedIndex = 4;
  117.     <%case "-1m"%>
  118.         document.QForm.FMMod.selectedIndex = 5;
  119.     <%case "-1y"%>
  120.         document.QForm.FMMod.selectedIndex = 6;
  121.     <%case "since"%>
  122.         document.QForm.FMMod.selectedIndex = 7;
  123.     <%case else%>
  124.         document.QForm.FMMod.selectedIndex = 0;
  125.     <%end select%>
  126.  
  127.     document.QForm.FMModDate.value = "<%=FMModDate%>";
  128.  
  129.     document.QForm.DocAuthorRestriction.value = "<%=DocAuthorRestriction%>";
  130. }
  131. //-->
  132. </SCRIPT>
  133.  
  134. <FORM NAME="QForm" ACTION="advsqlq.asp" METHOD=POST>
  135.  
  136. <table width=500>
  137.  
  138.     <tr>
  139.         <td>Enter your query: </td>
  140.         <td><INPUT TYPE="TEXT" NAME="SearchString" SIZE="70" MAXLENGTH="100" VALUE=""></td>
  141.     <tr>
  142.  
  143.     <tr>
  144.         <td colspan=2 align=right>Document author: 
  145.                 <INPUT TYPE="TEXT" NAME="DocAuthorRestriction" SIZE="47" MAXLENGTH="100" VALUE="">
  146.     </tr>
  147.     
  148.     <tr>    
  149.         <td colspan=2 align="right">Where File Size is: 
  150.                    <SELECT NAME="FSRest">
  151.                    <!-- <OPTION VALUE=" < " <%if FSRest = " < " then%>SELECTED <%end if%>>Less Than
  152.                         <OPTION VALUE=" > " <%if FSRest = " > " then%>SELECTED <%end if%>>Greater Than
  153.                    -->
  154.                    <OPTION VALUE=" < " SELECTED>Less Than
  155.                    <OPTION VALUE=" > " >Greater Than
  156.                    </SELECT>
  157.  
  158.                    <SELECT NAME="FSRestVal" DEFAULT VALUE="any">
  159.                    <OPTION VALUE="any" SELECTED>any size
  160.                    <OPTION VALUE="100" >100 bytes
  161.                    <OPTION VALUE="1024" >1K bytes
  162.                    <OPTION VALUE="10240" >10K bytes
  163.                    <OPTION VALUE="102400" >100K bytes
  164.                    <OPTION VALUE="1048576" >1M byte
  165.                    <OPTION VALUE="10485760" >10M bytes
  166.                    <OPTION VALUE="104857600" >100M bytes
  167.                    <OPTION VALUE="other" >Other
  168.                    </SELECT>
  169.                    <INPUT TYPE="TEXT" NAME="FSRestOther" SIZE="12" MAXLENGTH="9" VALUE="">
  170.         </td>
  171.     </tr>
  172.  
  173.     <tr>
  174.         <td colspan=2 align="right">Modified:
  175.                 <SELECT NAME="FMMod">
  176.                 <OPTION VALUE="any" SELECTED >at any time.
  177.                 <OPTION VALUE="DATEADD(minute, -10, GETGMTDATE())">in the last 10 minutes.
  178.                 <OPTION VALUE="DATEADD(hour, -1, GETGMTDATE())">in the last hour.
  179.                 <OPTION VALUE="DATEADD(day, -1, GETGMTDATE())">in the last day.
  180.                 <OPTION VALUE="DATEADD(week, -1, GETGMTDATE())">in the last week.
  181.                 <OPTION VALUE="DATEADD(month, -1, GETGMTDATE())">in the last month.
  182.                 <OPTION VALUE="DATEADD(quarter, -1, GETGMTDATE())">in the last quarter.
  183.                 <OPTION VALUE="DATEADD(year, -1, GETGMTDATE())">in the last year.
  184.                 <OPTION VALUE="since">since GMT (yy/mm/dd)        .
  185.                 </SELECT>
  186.                 <INPUT TYPE="TEXT" NAME="FMModDate" SIZE="12" MAXLENGTH="9" VALUE="">
  187.         </td>
  188.     </tr>
  189.      
  190.      <tr>
  191.         <td colspan=2, align=right>
  192.                 <INPUT TYPE="SUBMIT" NAME="Action" VALUE="Execute">
  193.                 <INPUT TYPE="RESET"  NAME="Clear" VALUE="Clear">
  194.         </td>
  195.     </tr>
  196. </table>
  197.  
  198.         <INPUT TYPE="HIDDEN" NAME="SortBy" VALUE=" order by rank desc">
  199.         <INPUT TYPE="HIDDEN" NAME="ColChoice" VALUE="1">
  200.         <INPUT TYPE="HIDDEN" NAME="CiMaxRecords" VALUE="10"> 
  201.     
  202. </FORM>
  203.  
  204. <BR>
  205.  
  206. <%if DebugFlag then%>
  207.     <PRE>
  208.     SearchString         = <%=SearchString%>
  209.     DocAuthorRestriction = <%=DocAuthorRestriction%>
  210.     FSRest               = <%=FSRest%>
  211.     FSRestVal            = <%=FSRestVal%>
  212.     FSRestOther          = <%=FSRestOther%>
  213.     FMMod                = <%=FMMod%>
  214.     FMModDate            = <%=FMModDate%>
  215.     SortBy               = <%=SortBy%>
  216.     Colset               = <%=Colset%>
  217.     NewQuery             = <%=CStr(NewQuery)%>
  218.     Maximum Records         = <%=CiMaxRecords%>
  219.     </PRE>
  220. <%end if%>
  221.  
  222. <%
  223. SelectColumns = "DocTitle, vpath, path, filename, size, write, characterization"
  224. SelectString = "Select " + SelectColumns + " from Scope() "
  225. if NewQuery then
  226.     set AdoConnection = Server.CreateObject("ADODB.Connection")
  227.     set AdoCommand = Server.CreateObject("ADODB.Command")
  228.     AdoConnection.ConnectionString = "provider=msidxs"
  229.     AdoConnection.Open
  230.     set AdoCommand.ActiveConnection = AdoConnection
  231.  
  232.     Composer = ""
  233.     TheQuery = ""
  234.  
  235.     if SearchString <> "" then
  236.             TheQuery = "contains('""" + SearchString + """')>0"
  237.         Composer = " and "
  238.     end if
  239.  
  240.     if FSRestVal <> "any" then
  241.         if FSRestVal <> "other" then
  242.             if FSRestVal <> "" then
  243.                 TheQuery = "Size " + FSRest + FSRestVal + " " + Composer + TheQuery
  244.             end if
  245.         else    
  246.             TheQuery = "Size " + FSRest + FSRestOther + " " + Composer + TheQuery
  247.         end if
  248.  
  249.         Composer = " and "
  250.     end if
  251.  
  252.     if DocAuthorRestriction <> "" then
  253.         TheQuery = "Contains(DocAuthor,  '""" + DocAuthorRestriction + """')>0 " + Composer + TheQuery
  254.         Composer = " and "
  255.     end if
  256.  
  257.     if FMMod <> "" AND FMMod <> "any" then
  258.         if FMMod <> "since" then
  259.             TheQuery = "(Write > " + FMMod + ") " + Composer + TheQuery
  260.         else
  261.             TheQuery = "(Write > '" + FMModDate + "') " + Composer + TheQuery
  262.         end if
  263.     end if
  264.  
  265.     if TheQuery <> "" then
  266.             SelectString = SelectString +  " where " + TheQuery +" "+ SortBy
  267.     else
  268.             SelectString = SelectString + SortBy +" "
  269.     end if
  270.  
  271.     AdoCommand.CommandText = SelectString
  272.     set RS = Server.CreateObject("AdoDB.Recordset")
  273.     RS.CursorType = adOpenStatic
  274.     RS.MaxRecords = CiMaxRecords
  275.     RS.Open AdoCommand
  276.  
  277.     '    Display Recordset Contents.
  278.     if not RS.EOF then
  279.         %>
  280.  
  281.         <p>
  282.         <HR WIDTH=80% ALIGN=center SIZE=3>
  283.         <p>
  284.  
  285.         <%
  286.         Response.Write "Results matching the query " & chr(34) & "<I>"
  287.         Response.Write SelectString & "</I>" & chr(34) & ".<P>"
  288.          %>
  289.         <!-- If the index is out of date, display the fact -->
  290.         <%if GetCiOutofDate(RS.Properties("Rowset Query Status")) then%>
  291.             <P>
  292.             <I><B>The index is out of date.</B></I><BR>
  293.         <%end if%>
  294.  
  295.         <!--
  296.             If the query was not executed because it needed to enumerate to
  297.             resolve the query instead of using the index, but AllowEnumeration
  298.             was FALSE, let the user know
  299.         -->
  300.  
  301.         <%if GetCiQueryIncomplete(RS.Properties("Rowset Query Status")) then%>
  302.             <P>
  303.             <I><B>The query is too expensive to complete.</B></I><BR>
  304.         <%end if%>
  305.  
  306.         <!--
  307.             If the query took too long to execute (for example, if too much work
  308.             was required to resolve the query), let the user know
  309.         -->
  310.  
  311.         <%if GetCiQueryTimedOut(RS.Properties("Rowset Query Status")) then%>
  312.             <P>
  313.             <I><B>The query took too long to complete.</B></I><BR>
  314.         <%end if%>
  315.  
  316.         </PRE>
  317.         <!-- BEGIN column header -->
  318.  
  319.         <!-- BEGIN first row of query results table -->
  320.         <P> Printing Results.
  321.         <TABLE>
  322.         <%
  323.         Do While Not RS.EOF and NextRecordNumber < 10 %>
  324.             
  325.             <%
  326.             ' This is the detail portion for Title, Abstract, URL, Size, and
  327.             ' Modification Date.
  328.             ' If there is a title, display it, otherwise display the virtual path.
  329.             %>
  330.             <p>
  331.             <dt><%= NextRecordNumber+1%>.
  332.             <%if VarType(RS("DocTitle")) = 1 or RS("DocTitle") = "" then%>
  333.             <b><a href="<%=RS("vpath")%>"><%= Server.HTMLEncode( RS("filename") )%></a></b>
  334.             <%else%>
  335.                 <b><a href="<%=RS("vpath")%>"><%= Server.HTMLEncode(RS("DocTitle"))%></a></b>
  336.             <%end if%>
  337.             <dd>
  338.             <%if VarType(RS("characterization")) = 8 and RS("characterization") <> "" then%>
  339.                 <b><i>Abstract:  </I></b><%= Server.HTMLEncode(RS("characterization"))%>
  340.                 <br>
  341.             <%end if%>
  342.             <cite>
  343.                 <a href="<%=RS("vpath")%>">http://<%=Request("server_name")%><%=RS("vpath")%></a>
  344.                 <font size=-1> - <%if RS("size") = "" then%>(size and time unknown)<%else%>size <%=RS("size")%> bytes - <%=RS("write")%> GMT<%end if%></font>
  345.             </cite>
  346.  
  347.             <%
  348.             RS.MoveNext
  349.             NextRecordNumber = NextRecordNumber+1
  350.         Loop
  351.         %>
  352.         </TABLE>
  353.  
  354.  
  355.         <P><BR>
  356.  
  357.         <%
  358.     end if ' NOT RS.EOF
  359.     %>
  360.  
  361.  
  362.     <%
  363.     ' If either of the previous or back buttons were displayed, save the query
  364.     ' and the recordset in session variables.
  365.     RS.close
  366.     AdoConnection.Close
  367.     Set RS = Nothing
  368.     Set AdoCommand = Nothing
  369.     Set AdoConnection = Nothing
  370. end if 'New Query
  371.  %>
  372.  
  373. <!--#include file ="is2foot.inc"-->                 
  374.  
  375. </BODY>
  376. </HTML>
  377.  
  378.