Web Robot View of http://www.brettb.com/SearchingIndexServerWithASP.asp

Page Item Value
Title Searching Index Server With ASP
Description Describes how to write a simple ASP script to search website content using Index Server or Indexing Service on Windows NT/2000
Keywords tutorial, example, index server, indexing service, asp, sample, example, code, indexing services
Robots Meta Tag  
Page Content   HOME | ABOUT ME | BIOTECHNOLOGY | ARTICLES | TOOLS | GALLERY | CONTACT Search: Go DEVELOPER TOOLS
ASP Doc Tool
ASP.NET Doc Tool
SQL Doc Tool
Index Server Companion
The Website Utility TECHNICAL ARTICLES
ASP
ASP.NET
JavaScript
Transact SQL

PHOTO GALLERIES
Canon EOS 300D Samples
Red Arrows 2004
Living Coasts
Web Page Backgrounds
More Galleries...

NEW STUFF
SQL Color Coder
Canon EOS 300D Samples
The Website Utility
Search Engine Optimisation
Build an ASP Search Engine
My Tropical Fishtank
Savings Other New Stuff...

POPULAR STUFF
Regular Expressions
ASP Documentation Tool
Index Server ASP
JavaScript Ad Rotator

LINKS
Business Website
ASPAlliance Articles

Home Articles

Searching Index Server With ASP Index Server makes it very straightforward to create search solutions that would cost many thousands of dollars to implement using alternative technologies.

This article describes what is required to use Index Server from within ASP. It assumes you have access to a web server running Internet Information Server 4.0 on Windows NT Server. The article is particularly suitable if, like me, you have Windows NT hosting with a company such as Alentus , who can supply Index Server support for a modest annual charge.

Note that Windows 2000 Server also has an equivalent to Index Server called Indexing Services, but there s no guarantee that these code samples will work on Windows 2000. Incidentally, the code samples described in this article are available from a link at the end of the article.

Creating a search form The first thing to do is to create a page containing a form in which the user can enter their search word or phrase. You can of course have a combined search form page and search results page, but I prefer to keep them separate. An example search form is shown below. This code should be saved as SearchForm.asp:

form method= POST action= SearchResults.asp name= frmSearch
p
input type= text maxlength= 255 name= query size= 20 value
input type= submit value= Search name= B1
/p
/form

As you can see from this HTML, it is a simple form that will post a single text field called query to the page called SearchResults.asp.

Creating a search results page The following code can be used for a basic search results page. It should be saved as SearchResults.asp.

The first part of the search results page initialises variables and constants:

%
Dim sSearchString
Dim oQuery

sSearchString = Request.Form( query )

Const SEARCH_CATALOG = catalog_name
%

The search string was posted from the SearchForm.asp search form page, and the word or phrase to be searched for are extracted from the query item in the Request.Form collection.

The SEARCH_CATALOG constant is also defined. This name will vary so you will have to change i t. If your site is hosted with a hosting company then they will usually set up a catalog on the Index Server for you, then let you know the name of your search catalog. If you are using your own web server, then you should be able to determine the catalog name from the Index Server Management Console. Describing how to set up and use Index Server catalogs is beyond the scope of this article, but further information is available in the IIS 4.0 reference guide (try http://localhost/iishelp/ ).

The next part of the search results page initialises the Index Server Query COM component which enables the search to be performed:

%
Set oQuery = Server.CreateObject( IXSSO.Query )

oQuery.Catalog = SEARCH_CATALOG
oQuery.Query = @all sSearchString AND NOT #path *_* AND NOT #path *downloads* AND NOT #path *images* AND NOT #filename *.class AND NOT #filename *.asa AND NOT #filename *.css AND NOT #filename *postinfo.html
oQuery.MaxRecords = 200
oQuery.SortBy = rank[d]
oQuery.Columns = DocAuthor, vpath, doctitle, FileName, Path, Write, Size, Rank, Create, Characterization, DocCategory

Set oRS = oQuery.CreateRecordSet( nonsequential )
%

Further details of the Query object s methods and properties are to be found in the IIS 4.0 online documentation. The properties of the object set in the sample code above are as follows: Catalog : The name of the search catalog to be searched. Query : The query to be made. Note that the query in this example is comprised of the search string, plus a list of file and folder exclusions. It is important to remember that Index Server indexes content by using the file system, and therefore is able to index files you d rather not allow users to search from the web. Examples include global.asa files, FrontPage configuration files (these folders have underscores in their names) and files such as Java class files and Cascading Style Sheets. MaxRecords : This property specifies the maximum number of search results that should be returned. SortBy : This specifies which column name the search results should sorted by. The usual setting for this is rank[d] , i.e. sort results in descending order according to their similarilty to the search string. Columns : A list of column properties that should be returned in the search results. These will be discussed in further detail later on. Finally, an ADO RecordSet is created from the records found for this search. The neat thing about Index Server is that the returned RecordSet of search results can be used in an almost identical fashion to RecordSets returned from databases. A list of results is, therefore, displayed simply by looping through this RecordSet and displaying fields from the RecordSet:

%
If oRS.EOF Then
Response.Write No pages were found for the query i sSearchString /i
Else
Do While Not oRS.EOF

Response.write b FileName: /b oRS( FileName ) br
Response.write b doctitle: /b oRS( doctitle ) br
Response.write b Size: /b oRS( Size ) br
Response.write b Create: /b oRS( Create ) br
Response.write b Write: /b oRS( Write ) br
Response.write b Characterization: /b oRS( Characterization ) hr

oRS.MoveNext
Loop
End If
%

This code loops through the records corresponding to the matching documents found and displays some of the properties of each document. This is where the columns property of the Index Server Query are used: these specify the column names that are returned for each record. In the sample code above, FileName refers to the record s name on disk.

doctitle corresponds to the document s title (i.e. title tag if the document is HTML). Size is the size in bytes of the file on disk. Create is the date and time the document was created, whereas Write is the date and time the document was modified. Finally, Characterization is a summary of the document. The summary corresponds to the Description meta tag in HTML files, so it is worthwhile putting this tag into documents. If the Description tag isn t present, Index Server will display the first one or two sentences from the document.

Unfortunately the FileName property only contains the file's name in lower case. This can lead to problems if you are building a cross-platform search solution with operating systems that use case sensitive filenames (e.g. Unix and Linux).

Finally at the bottom of the page the objects are released:

%
Set oRS = nothing
Set oQuery = nothing
%

An example screenshot of the search results page is below as described above, the page displays the FileName, doctitle, Size, Create and Characterization for each matching document:

As you can see the page is fairly basic, so a few cosmetic improvements would be required if the page was to be used on a production website. Further suggestions for improving the display of search results are in the article More about Searching Index Server With ASP .

Code samples and working ASP pages Search form and search results sample ASP files (1.12 Kb ZIP file). Fully working versions of the search form and results pages described in this article may be accessed from this website. Further reading Index Server Companion . The Index Server Companion allows Index Server to index content from remote websites and ODBC databases! ASP Documentation Tool . Creates documentation for ASP 2.0 and 3.0 web applications written in VBScript or JScript. MSDN's Indexing Services section . More about Searching Index Server With ASP . A complete list of column properties available to Index Server . The search facility on this website was built using Index Server and ASP using code similar to that described in this article. Sams Teach Yourself Web Development With ASP in 24 Hours . Start learning ASP with this introductory guide. Useful Development Tools ASP Documentation Tool Automatically creates developer documentation for ASP 2.0 and 3.0 web applications written in VBScript and JScript. Documentation for Microsoft Access, SQL Server 7/2000 databases and Visual Basic 6.0 components associated with the web application can also be incorporated into the reports. Documentation is created in HTML, HTML Help and plain text formats. View Sample Output (HTML Help format).
View Sample Output (HTML Format).
Download Trial Version (5.2Mb ZIP file).
ASP.NET Documentation Tool Automatically creates developer documentation for ASP.NET web applications written in C# or VB.NET. Documentation for SQL Server 7/2000 databases and C#/VB.NET components associated with the web application can also be incorporated into the reports. Documentation is created in HTML, HTML Help and plain text formats. View Sample Output (HTML Help format).
View Sample Output (HTML Format).
Download Trial Version (2.9Mb ZIP file).
SQL Documentation Tool The SQL Documentation Tool creates technical documentation for Microsoft SQL Server 7.0 and 2000 databases. Technical documentation is created in HTML and HTML Help formats. The HTML Help format documentation is fully searchable and cross referenced. The SQL Documentation Tool documents SQL Server Tables, Views, Stored Procedures, Triggers and Table Relationships. View Sample Output (HTML Help format).
View Sample Output (HTML Format).
Download Trial Version (10.3Mb ZIP file).
Index Server Companion The Index Server Companion is a Windows application that extends the functionality of Microsoft Index Server so that it is able to index content from remote websites and also from ODBC databases. As such it can be used as a low cost alternative to Site Server 3.0 Search. View Product Documentation (119K ZIP file).
Try Sample Search Facility .
Download Trial Version (1.7Mb ZIP file).
The Website Utility The Website Utility examines websites for errors and areas that need to be optimised for search engines by using a built in web crawling engine. Errors checked for include broken or moved hyperlinks, missing page titles and missing meta tags. It also generates HTML for use in creating website site maps (table of contents pages - like this one ), and is able to create both client-side JavaScript Search Engines and server-side ASP Search Engines for a website. View Sample Output (HTML Help format).
View Sample Output (HTML Format).
Download Trial Version (3Mb ZIP file).

Site Map

All content is © 1995 - 2006 Brett Burridge

Image Alt Tags Brettb.Com
Microsoft Certified Professional
Output from SearchResults.asp
View Sample Output (HTML Help format)
View Sample Output (HTML Format)
Download Trial Version
View Sample Output (HTML Help format)
View Sample Output (HTML Format)
Download Trial Version
View Sample Output (HTML Help format)
View Sample Output (HTML Format)
Download Trial Version
View Product Documentation
Try Sample Search Facility
Download Trial Version
View Sample Output (HTML Help format)
View Sample Output (HTML Format)
Download Trial Version
ASP Documentation Tool - Free Trial Available!
1000MB and 40GB for $7.95 a month!
Internal Links http://www.brettb.com/redirector.asp (13 links in this page) [ Robot View of this URL ]
http://www.brettb.com/Default.asp (3 links in this page) [ Robot View of this URL ]
http://www.brettb.com/ASPDocumentationTool.asp (3 links in this page) [ Robot View of this URL ]
http://www.brettb.com/SearchingIndexServerWithASP.asp (2 links in this page) [ Robot View of this URL ]
http://www.brettb.com/MoreIndexServerWithASP.asp (2 links in this page) [ Robot View of this URL ]
http://www.brettb.com/DeveloperTools.asp (2 links in this page) [ Robot View of this URL ]
http://www.brettb.com/TheWebsiteUtility.asp (2 links in this page) [ Robot View of this URL ]
http://www.brettb.com/IndexServerCompanion.asp (2 links in this page) [ Robot View of this URL ]
http://www.brettb.com/technicalwriting.asp (2 links in this page) [ Robot View of this URL ]
http://www.brettb.com/Website_Search_Engine_Optimisation.asp [ Robot View of this URL ]
http://www.brettb.com/SearchResults.asp [ Robot View of this URL ]
http://www.brettb.com/js_banner_ad_rotator.asp [ Robot View of this URL ]
http://www.brettb.com/web.asp [ Robot View of this URL ]
http://www.brettb.com/CanonEOS300D_Gallery1.asp [ Robot View of this URL ]
http://www.brettb.com/BuildingAnASPSearchEngine.asp [ Robot View of this URL ]
http://www.brettb.com/backgrounds.asp [ Robot View of this URL ]
http://www.brettb.com/VBScriptRegularExpressions.asp [ Robot View of this URL ]
http://www.brettb.com/toc.asp [ Robot View of this URL ]
http://www.brettb.com/ASP.NETArticles.asp [ Robot View of this URL ]
http://www.brettb.com/Investments_ISAs.asp [ Robot View of this URL ]
http://www.brettb.com/TransactSQLColorCoder.asp [ Robot View of this URL ]
http://www.brettb.com/MyTropicalFishtank.asp [ Robot View of this URL ]
http://www.brettb.com/CanonEOS300D_Gallery3.asp [ Robot View of this URL ]
http://www.brettb.com/ASPWatchArticles.asp [ Robot View of this URL ]
http://www.brettb.com/Red_Arrows_2004.asp [ Robot View of this URL ]
http://www.brettb.com/Living_Coasts_Photos.asp [ Robot View of this URL ]
http://www.brettb.com/SQL_Help.asp [ Robot View of this URL ]
http://www.brettb.com/contact.asp [ Robot View of this URL ]
http://www.brettb.com/Biotechnology.asp [ Robot View of this URL ]
http://www.brettb.com/Gallery.asp [ Robot View of this URL ]
http://www.brettb.com/ASPNetDocumentationTool.asp [ Robot View of this URL ]
http://www.brettb.com/gallery.asp [ Robot View of this URL ]
http://www.brettb.com/Search.asp [ Robot View of this URL ]
http://www.brettb.com/what's_new.asp [ Robot View of this URL ]
http://www.brettb.com/ASPAlliance/IndexServer1/SearchForm.asp [ Robot View of this URL ]
http://www.brettb.com/JavaScriptArticles.asp [ Robot View of this URL ]

Reporting Main Page

Report generated by The Website Utility 2.8