Thornton Rose
Published as "Scripting for Searching", 10/1/98, Developer.com.
Copyright © 2001, Thornton Rose.
A search engine is a necessity on any large Web site or an intranet. Most search engines, though, are not quite ready for prime-time right out of the box. In this article, I show you two methods for creating search scripts for Index Server, Microsoft's search engine for Internet Information Server (IIS).
Here are the tools you will need, whether you are starting from scratch or already have an installation of IIS and Index Server:
There are some caveats with these tools. First, if you install IIS 4.0 and Index Server 2.0, you will have more flexibility, because you can use both scripting methods that are presented in this article. However, you will need to have NT Server, because Index Server 2.0 will only work with IIS 4.0, which will only run on NT Server. Second, if you have or can get IIS 3.0 and Index Server 1.x, you can run them on NT Workstation, but you will only be able to use the old scripting method.
The first scripting method I am going to show you is what I call the old method. I call it that because Index Server 2.0 introduces a new, more flexible method. To use the old method, you have to create three files:
The Web page can be put in any Web directory, but the query parameters file and the template file have to be put in a Web directory with execute permission. A common place is "/scripts".
The Web page can be as simple or as fancy as you want, but at minimum it needs to contain a form, a field for the search text and a button to submit the form. The action of the form should be set to the URL of the
query parameters file, e.g., action = "/scripts/SimpleSearch.idq"
. My sample Web page is SimpleSearch.htm.
The query template file is used to display the search results. It contains HTML and special tags for variable substitution and basic control statements, e.g., <%target%
> and <%if CiMatchedRecordCount eq0%
>...<%endif%
>. Note that the <%begindetail%
> and <%enddetail%
> tags mark the block that will be processed once for each result record returned by the search. My sample query template file is SimpleSearch.htx. The source version is here, and output from a sample search is here.
The query parameters file is much like an INI file and is used to specify the information that Index Server needs to execute the query. These parameters include: the columns that should be returned, the scope of the query, the template file to be used, the sort order and so on. My sample query parameters file is SimpleSearch.idq.
Values for any of the query parameters can be passed in from any Web page. This is done simply by creating a field in the Web page that calls the query parameters file; then, in the query parameters file, setting the parameter equal to %{name}%
, where {name}
is the name you chose for the field. For example, in SimpleSearch.htm, I created a field called "target", like this:
<INPUT TYPE="text" NAME="target" SIZE="45" MAXLENGTH="100">
Then, because "target" gets passed into SimpleSearch.idq, I used it to set the value of the CiRestriction parameter, like this:
Additionally, all of the query parameters and all of the fields passed in from the form are passed into the query template file when it is processed by Index Server. You can see an example of this by tracing "target" from SimpleSearch.htm to %target%
in SimpleSearch.idq to <%target%
> in SimpleSearch.htx.
For more information on the query template file, the query parameters file or the Index Server query language, consult the Index Server documentation.
SimpleSearch.asp is like a combination of the three files used in the old method, with VBScript added to the mix, which provides much more flexibility. With VBScript, I was able to add VCR-style controls to the bottom of the page, instead of the simple "next" and "previous" buttons I used with the old method. (Note that JScript can also be used, but I stuck with VBScript because it's what Microsoft uses in its examples.)
When you look at SimpleSearch.asp, you will see that most of the work is done with doSearch()
and showHits()
. doSearch()
creates a Query object, sets the query parameters by setting properties of the Query object, executes the search by telling the Query object to create an ADO Recordset, then calls showHits()
, which displays the search results and the navigation controls.
For more information on Index Server Objects or Active Data Objects, consult the Windows NT Option Pack documentation.