Letting visitors search your site with Index Server
By Bob Dombroski
If you want to let visitors to your site find content quickly, you should seriously considering giving them some sort of "search" functionality. If you're running IIS 4.0, you can use Index Server to make that a pretty simple job.
What is Index Server? Index Server has been around since IIS 2.0. Basically, it was developed as an engine that would be able to index any content stored in any location. Index Server is capable at looking at the content of HTML files, Microsoft Office files, as well as searching inside databases. Like most Microsoft technologies, Index Server is "extensibile", meaning you can develop and plug-in handlers to manage other resources you want to index.
In this example, we're going to see how we can use Index Server to index, and search, a collection of HTML and ASP pages on our Web server. In fact, we're going to look at how the ASPWatch Search form works.
Using Index Server with ASP
Although strictly speaking Index Server doesn't predate ASP, it certainly predates the *popularity* of ASP. When you look at documentation and example for Index Server, you'll see plenty of references to .HTX and .IDX files. Nowadays, we don't have to worry about those, we can use ASP.
Index Server fits into Microsoft's Universal Data Access paradigm. Microsoft's strategy for data access and use is to provide a common way of considering all data, and providing a common way of accessing that data. In the case of Index Server, Microsoft decided that they would expose results from the search as an ADO Recordset - i.e. moving through search results is exactly the same as moving through a database query.
Catalogs In this example, we want to index files on the database server, rather than look inside a database itself. In the case of ASPWatch, this works nicely, because although ASPWatch is totally database driven, cached .ASP pages are generated whenever an author or editor changes content. This means we can index (and therefore search) upon any of the articles on the site just by creating a "catalog" of those .ASP pages.
To create a catalog, you need to have the Index Server service started. Usually it will be, but you can check the status by looking in the Services applet on the control panel. Once you're sure it's running, open the Microsoft Management Console and add the Index Server snap-in if it's not already there.
When Index Server is installed, a default catalog will be created that points to the folder containing IIS's Default Web Site. If the site you want to index is in an alternate folder, you'll have to create a new catalog.
Creating a Search Form The way you create the search form is indicitive of how "old school" the Index Server API is. Basically, when you want to perform the search, rather than setting properties on an ActiveX component, you have to pass the Index Server a copy of the query string, which it then passes to find out what it's supposed to do.
Index Server only requires two fields to be present in that form. It needs a search query, as you would expect, and it also requires the *physical* path to the catalog is based on.
Here's what the ASPWatch Search form looks like:
<FORM ACTION="/SEARCH.ASP" METHOD=GET>
<!-- the field containing the query must be called "QU" --> <INPUT TYPE=TEXT NAME=QU>
<!-- the field referencing the catalog must be called "CT" --> <INPUT TYPE=HIDDEN NAME=CT VALUE="e:\inetpub\indexes\aspwatch">
<!-- finally, we need a "Submit" button --> <INPUT TYPE=SUBMIT VALUE="Search!">
</FORM>
Performing the Search In the search.asp page, we need to create an instance of the Index Server query object and pass it the form data:
' create the Index Server query... Dim Index Set Index = Server.CreateObject("IXSSO.Query")
' tell the query object what was passed through the form... Index.SetQueryFromURL Request.QueryString
The next step is to tell the query object what columns we want returned in the results Recordset. (Note: the column names are case-sensitive.)
Else Response.Write "No results were found." End If
Summary There's a lot more to Index Server's capabilities than this but, as you can see, developing a simple Search function is reasonably straightforward.
The Author Bob Dombroski is a ASP junkie, who is always looking for new and exciting ways to do things with ASP and a browser. When he isnt playin with ASP he can be found cruisin' one of many Central Florida lakes.