An Example Search Results Page Utilizing a SQL-Style Query for Site Server Search (243724)



The information in this article applies to:

  • Microsoft Search, when used with:
    • Microsoft Site Server 3.0

This article was previously published under Q243724

SUMMARY

A basic search results page utilizing an SQL-style query for Site Server Search can be constructed in relatively few lines of code. The code presented in this article is a commented example of such a page.

MORE INFORMATION

<%@ Language="VBScript" %>
<HTML>
<BODY>
<%
' Create and set up the connection to Search.
Set objConn = Server.CreateObject ("ADODB.Connection")
objConn.ConnectionString =  "provider=mssearchsql;" 
objConn.Open

' Create and set up the Command object.
Set objCmd = Server.CreateObject("ADODB.Command")
Set objCmd.ActiveConnection = objConn

' Build the SQL Statement. 
strSQLText = "SELECT Title, DocAddress, Description, Rank" & _
	" FROM <Catalog Name>..Scope()" & _
	" WHERE Contains('<Query Text>')" & _
	" ORDER BY Rank DESC, Title"

' Set and execute the query entered by the user.
objCmd.CommandText = strSQLText
Set objRS = Server.CreateObject ("ADODB.Recordset")
objRS.Open objCmd

' Display the results.
Response.Write objRS.Properties ("RowCount") & " documents match the query<BR><BR>"
Response.Write "<TABLE BORDER=1>"

' Show our headers
For I = 0 To objRS.Fields.Count - 1 
	Response.Write "<TH><STRONG>" & objRS (I).Name & "</STRONG></TH>"
Next 

' We want to display information for each result in the recordset
Do While Not objRS.EOF 
    Response.Write "<TR>"

	' Display the field and associated value(s)
    For I = 0 To objRS.Fields.Count - 1 
		Response.Write "<TD>" & objRS (I) & "</TD>"
    Next
    
    Response.Write "</TR>"
    objRS.MoveNext
Loop
Response.Write "</TABLE>"

' Clean up after ourselves by closing our recordset and setting our objects equal to Nothing
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
</BODY>
</HTML>
				

Modification Type:MajorLast Reviewed:2/3/2000
Keywords:kbDSupport kbhowto KB243724