Any Web site running Microsoft's Internet Information Server (IIS) can use the Index Server search engine that comes with IIS. Adding a search engine to your Web site can be easy with Index Server, if your site's content is contained in a directory on the file system. Index Server doesn't use a Web spider or crawler like Google or other search engines—instead it loads all of the content under a directory. Index Server uses the file system security that's built into the NTFS file system to restrict access to documents that have been indexed.
Index Server has several advantages: It's free, it supports multiple languages with stemming, and it can index both Microsoft Office documents and HTML files. Developers can add additional file formats to the indexer by writing a text conversion tool that implements the IFilter interface.
Two disadvantages of using Index Server are that it doesn't have built-in support for indexing dynamic content, and it can index only the contents of one machine—if your Web site includes Web servers with different content, you can't use Index Server to implement a global search facility. To support a multi-server search, use a search engine that supports spiders or crawling, such as most of the commercial search solutions. If you have any database-driven content, you will have to generate static pages for your data and index them.
Running Index Server
Index Server runs as a service on your Windows Web server. All of the following directions are given for Windows 2000, but other versions of Windows will be very similar. To begin, open Control Panel, open the Services control panel under Administrative Tools, and start the Indexing Service if it's not already running. If you don't have Index Server installed, it can be added through the Add/Remove Programs control panel as a Windows component.
Creating a catalog
Once you have the indexing service started, you can create a catalog for your Index Server. A catalog is a collection of documents that corresponds to a directory on the file system. To manage Index Server, use the Microsoft Management Console (MMC) Computer Management snap-in, which is also located in the Administrative Tools folder. The Computer Management snap-in is shown in Figure A.
|The Computer Management snap-in provides an interface for managing the indexing service.|
Under Services And Applications in the snap-in, select the Indexing Service. You'll create your catalog here. Right-click Indexing Service, and select New | Catalog. The Add Catalog dialog box will open. Give your catalog the name Example, and the search index will be C:\TEMP\SEARCH.
Index Server can work with IIS to add the virtual path to your content to the index, so you can create links right out of IIS. You need to associate the IIS Web site with your catalog so Index Server can pick up on the virtual directory being used. Right-click the Example catalog in either pane, and select Properties. Select the Tracking tab of the Example Properties dialog box that appears, as shown in Figure B. For WWW Server, choose Default Web Site, or whatever your IIS installation is called.
|Choose your IIS installation through the Tracking tab.|
When you go back to the Computer Management MMC snap-in, you'll see that the Example catalog is ready to be indexed, but it doesn't have any content assigned yet. By putting the content in C:\TEMP\CONTENT, you make it accessible through IIS as the virtual directory content. Add it to the catalog as a directory—each catalog can have multiple directories of content to index. Right-click the Directories folder under the Example catalog in the left hand pane, and select New | Directory.
Figure C shows the built-in query page that comes with the Index Server snap-in. I searched for the word "example," and got three hits, so I can tell my catalog was created properly.
|The Index Server snap-in offers this built-in query page.|
Writing a search page
Index Server comes with a component for running queries inside an ASP page. Another approach would be to use Active Data Objects (ADO) directly to access the index server in a similar manner as a database. Use the Index Server Query object, which has a ProgID of ixsso.Query.
Set up a standard ASP page (shown in Listing A), with a form that will always appear at the top, and results that show up only if the form has been submitted. Check to see if the searchPhrase variable is in the Request's QueryString. To get the results, create an instance of the Query object with Server.CreateObject("ixsso.Query") in the ASP.
Next, set up the Query object by setting its properties. The properties on the Query object you're going to use are:
- Catalog—The name of the Catalog you set up in the Index Server.
- Columns—A comma-delimited list of the columns you're going to get back, similar to a SQL query. Some available columns include: filename, vpath (virtual path on the Web server for the file), path (on the file system), DocAuthor, DocCharCount, DocTitle, DocWordCount, hitcount, rank (Index Server ranks each hit by how closely it matches the search terms), size (size of the document on disk), and write (timestamp of document's last modified time).
- MaxRecords—The maximum number of records the query will return.
- Query—The query the user searched for. It can be simple, or it can be written using the Index Server query language, which uses Boolean operators. (These operators include AND, OR, NOT, and NEAR.)
- SortBy—The column that Index Server should use to sort the results. This property takes the form columnName[a] or columnName[d] for ascending and descending. (Typically you'll use rank[d] to sort the query results by relevance, in descending order.)
You'll get the query from the form, and the other properties are going to be hard coded in the ASP. After you set the properties, create a RecordSet object from the Query, which tells IndexServer to execute the query and return a set of search results with the columns you wanted. It's very similar to executing a SELECT statement on a relational database and getting a set of results back from a table. You'll use this line of code:
Set objRecordSet = objQuery.CreateRecordSet("nonsequential")
You created the record set with the nonsequential cursorType parameter. You could have also used a sequential cursor, but that would be efficient only for forward scrolling in the results if you had a paged search results set.
Search solution on a budget
For Web sites built on IIS that don't have a large budget for a search solution, Microsoft's Index Server provides excellent functionality with a small investment of time. With its GUI catalog administration and use of ASP and ADO syntax, most Microsoft ASP developers should consider Index Server as a solution for most small and midsize projects where static content is stored on the file system.