The Index Server Query Object

Index Server 2.0 is the latest version of Microsoft's search engine that is integrated with IIS 4.0 and the Windows NT Server 4.0 operating system. Index Server allows you to use any Web browser to perform full text searching of HTML, text, and Microsoft Office documents. This includes documents in Microsoft Word, Microsoft Excel, and Microsoft PowerPoint. This is a powerful feature of Index Server —you don't need to convert all your content to HTML! Just place your documents out on the Web server—Index Server can do all the work for you and return detailed summaries and hyperlinks to the actual documents.

The Index Server Query object allows you to customize your interaction with Index Server through ASP scripting. This is a new feature introduced with Index Server 2.0 and IIS 4.0.

NOTE
Prior to the introduction of Index Server 2.0, developers had to use the HTML/IDQ/HTX technique to customize Index Server. This technique consists of using three separate files for the various operations that need to take place: the HTML file is used for the query form, the IDQ file is used to process the search, and the HTX file is used to format the results. It remains a good option when compared to the other techniques such as SQL and ASP scripting because of its fast performance.

The syntax to instantiate the Index Server Query object is as follows, where objQuery refers to the new object.

<OBJECT RUNAT=server PROGID=IXSSO.Query id=objQuery> </OBJECT> 

The following code in Figure 17-14, taken from the IndexServerQuery.asp file within the Components project on the CD-ROM, shows an example of how to use the Query object. First it builds a simple query using the SetQueryFromURL method. The query contains a search on the word "Sample" with the maximum number of hits to be returned specified as 25. These types of values could easily be obtained via an HTML form that allows end users to specify their own queries. There are also many other properties that can be queried, including metaproperties such as author name, filename, and file size.

Figure 17-14. Source code for the IndexServerQuery.asp file, which queries Index Server and returns a recordset to the browser.

 <%@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY> <H2>Index Server Query Sample</H2> <HR> <OBJECT RUNAT=server PROGID=IXSSO.Query id=objQuery> </OBJECT> <% If IsObject(objQuery) = False Then     Response.Write "Index Server Query object not installed." Else     ' Build the query string     ' Set the search to "Sample" and the maximum hits to 25     iRequest = "qu='Sample'&mh=25"     objQuery.SetQueryFromURL(iRequest)         ' Define the columns for the recordset     objQuery.Columns = "filename, vpath, size, write"     Set rs = objQuery.CreateRecordset("sequential") End If %> <FONT SIZE="2"> <TABLE BORDER=1> <TR> <TH>Record</TH> <TH>File name</TH> <TH>Path</TH> <TH>Size</TH> <TH>Write</TH> </TR> <% ' Loop over the recordset NextRecordNumber = 1  Do While NOT Rs.EOF %> <TR> <TD><%=NextRecordNumber %></TD> <TD><%=rs("Filename") %></TD> <TD><A HREF="<%=rs("vpath") %>"><%=rs("vpath") %></A></TD> <TD><%=rs("Size") %></TD> <TD><%=rs("Write") %></TD> </TR> <% rs.MoveNext NextRecordNumber = NextRecordNumber + 1 Loop %> </TABLE> </FONT> </BODY> </HTML> 

Next the code defines the columns that are required for the recordset using the Columns property of the Query object. These columns include the filename, the file size, the virtual path to the file, and the time stamp of the file. After defining the columns to be returned by the recordset, the CreateRecordset method is called for the Query object and the results are stored in the rs recordset.

Now that the query portion is complete, all that's left is for the code to loop over the recordset and display the results in the browser. This is done using a standard Do Loop syntax and by using an HTML table to control the formatting of the resulting output. Figure 17-15 shows an example of the resulting output in the browser.

click to view at full size.

Figure 17-15. Output from the IndexServerQuery.asp page, which performs a simple search and formats the results in an HTML table.



Programming Microsoft Visual InterDev 6. 0
Programming Microsoft Visual InterDev 6.0
ISBN: 1572318147
EAN: 2147483647
Year: 2005
Pages: 143

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net