This step-by-step article describes how to create a customized Index Server search page by using Active Server Pages (ASP) in Microsoft Office FrontPage 2003.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
Note You may receive an error message if you copy the examples directly from this article and then paste them into FrontPage. FrontPage may misinterpret the angle brackets (< and >). To work around this behavior, paste the script into a blank Notepad document, and then copy it from Notepad and paste it into FrontPage.
To add the sample ASP code to the page, follow these steps:
At the bottom of the right pane, click Code to switch to the HTML view.
Type or paste the following code before the opening HTML tag:
<%
' Force variable declaration.
Option Explicit
' Declare all our variables.
Dim strQueryText
Dim strQueryField
Dim strSQL
Dim strName
Dim strValue
Dim objRS
Dim objField
' This is the list of Index Server variables that will appear.
' You can customize the list of fields. For more information,
' see Microsoft Knowledge Base article 318387.
Const strDisplayFields = "Rank, DocAuthor, DocAppName, DocTitle, FileName, Create, Access, Characterization, VPath"
' This is the default Index Server catalog for all Web content.
' For information about how to customize this, see Microsoft
' Knowledge Base article 318387.
Const strDataSource = "WEB"
' Get the value of the user-submitted search query.
strQueryText = Request("QUERYTEXT")
' Set a default value if the user has not submitted anything.
If Len(strQueryText) = 0 Then strQueryText = "%%"
' Get the field that the user wants to query against.
strQueryField = Request("QUERYFIELD")
' Set a default value if the user has not specified a field.
If Len(strQueryField) = 0 Then strQueryField = "DocTitle"
%>
Type or paste the following code after the closing </FORM> tag:
<%
' Check if the user has entered a value in the form
If strQueryText <> "%%" Then
' Build the SQL statement from the user-specified options.
strSQL = "SELECT " & strDisplayFields & " FROM SCOPE() " & _
"WHERE ((" & strQueryField & " LIKE '%" & strQueryText & "%') AND " & _
"((VPath NOT LIKE '%/_vti%') AND (VPath NOT LIKE '%/_private%')))"
' Create a recordset object.
Set objRS = Server.CreateObject("ADODB.Recordset")
' Open the recordset by using the SQL string with the Index Server provider.
objRS.Open strSQL,"PROVIDER=MSIDXS;DATA SOURCE=" & strDataSource
' Are there any records to show?
If objRS.EOF Then
' Show a default message if nothing is found.
Response.Write "No Documents were Found." & vbCrLf
' Otherwise...
Else
' Start a table.
Response.Write "<table border=""1"">" & vbCrLf
' Start the row for the header section.
Response.Write "<tr>" & vbCrLf
' Loop through the fields collection.
For Each objField in objRS.Fields
' Get the field's name.
strName = objField.Name
' If the field has a name, escape it for HTML.
If Len(strName) > 0 Then strName = Server.HTMLEncode(strName)
' Output the field name as a table header.
Response.Write "<th>" & strName & "</th>" & vbCrLf
Next
' End the row for the header section.
Response.Write "</tr>" & vbCrLf
' Loop through all the records.
While Not objRS.EOF
' Start a row in the data section.
Response.Write "<tr>" & vbCrLf
' Loop through the fields collection.
For Each objField in objRS.Fields
' Get the field's value.
strValue = objField.Value
' Look for null values.
If Len(strValue) > 0 Then
' If the value is not null, escape it for HTML.
strValue = Server.HTMLEncode(strValue)
Else
' Otherwise, make it a non-breaking space character.
strValue = " "
End If
' Output the field value as table data.
Response.Write "<td>" & strValue & "</td>" & vbCrLf
Next
' End a row in the data section.
Response.Write "</tr>" & vbCrLf
' Move on to the next record.
objRS.MoveNext
Wend
Response.Write "</table>" & vbCrLf
End If
Else
' User has not entered any value in search form
Response.Write "Please enter a Search Term before submitting the form" & vbCrLf
End if%>
If multiple Index Server catalogs are defined on your Web server, you can specify that the sample page use a different catalog. To do this, follow these steps:
Start FrontPage, and then open the sample Web page that you created earlier in this article.
Click Code to switch to HTML view.
Locate the following line of code:
Const strDataSource = "WEB"
Change the value of strDataSource to the name of your catalog, so that the line is similar to the following code: Const strDataSource = My_Custom_Catalog
On the File menu, click Save, and then close the file.
Modify the Field list
Start FrontPage, and then open the sample Web page that you created earlier in this article.
Click Code to switch to HTML view.
Locate the line of code that looks similar to the following code:
On the File menu, click Save, and then close the file.
The following table lists the values that you can use for the strDisplayFields variable.
Collapse this tableExpand this table
Field Name
Field Type
Description
Access
Date/Time
Last time when the file was accessed.
Characterization
Text/String
Characterization, or abstract, of
document. Computed by Index Server.
Create
Date/Time
Time when the file was created.
Directory
Text/String
Physical path of the file, not
including the file name.
DocAppName
Text/String
Name of the application that created the
file.
DocAuthor
Text/String
Author of the document.
DocByteCount
Numeric
Number of bytes in the document.
DocCategory
Text/String
Type of document, such as a memo,
schedule, or white paper.
DocChar
Count Numeric
Number of characters in the document.
DocComments
Text/String
Comments about the document.
DocCompany
Text/String
Name of the company that the
document was written for.
DocCreatedTm
Date/Time
Time when the document was created.
DocEditTime
Date/Time
Total time spent editing the document.
DocHiddenCount
Numeric
Number of hidden slides in a
Microsoft PowerPoint presentation.
DocKeywords
Text/String
Document keywords.
DocLastAuthor
Text/String
Most recent user who edited the
document.
DocLastPrinted
Date/Time
Time document was last printed.
DocLastSavedTm
Date/Time
Time document was last saved.
DocLineCount
Numeric
Number of lines contained in a
document.
DocManager
Text/String
Name of the manager of the document's
author.
DocNoteCount
Numeric
Number of pages with notes in a
PowerPoint presentation.
DocPageCount
Numeric
Number of pages in th document.
DocParaCount
Numeric
Number of paragraphs in the document.
DocPartTitles
Text/String
Names of document parts. For example,
in Microsoft Excel, a spreadsheet is
a document part. In PowerPoint, a
slide is a document part. And, in
Word, the file names of the documents
contained in a master document are
document parts.
DocPresentationTarget
Text/String
Target format (such as 35mm, printer, video) for a PowerPoint
presentation.
DocRevNumber
Text/String
Current version number of a document.
DocSlideCount
Numeric
Number of slides in a PowerPoint presentation.
DocSubject
Text/String
Subject of the document.
DocTemplate
Text/String
Name of the template for the
document.
DocTitle
Text/String
Title of document.
DocWordCount
Numeric
Number of words in the document.
FileIndex
Numeric
Unique ID of the file.
FileName
Text/String
Name of the file.
HitCount
Numeric
Number of hits (words matching query)
in the file.
Path
Text/String
Full physical path of the file,
including file name.
Rank
Numeric
Rank of row. Ranges from 0 to 1000.
Larger numbers indicate better
matches.
ShortFileName
Text/String
Short (8.3) file name.
Size
Numeric
Size of file, in bytes.
VPath
Text/String
Full virtual path of file, including
file name. If more than one possible
path, the best match for the
specific query is chosen.
For more information about how to work with the Microsoft Windows 2000 Indexing Service, click the following article numbers to view the articles in the Microsoft Knowledge Base:
185985
(http://support.microsoft.com/kb/185985/
)
Using Index Server to query and display META TAG information
256276
(http://support.microsoft.com/kb/256276/
)
Error message: There is no catalog
229282
(http://support.microsoft.com/kb/229282/
)
ASP code is visible when you view source of an Index Server results page