Using Index Server's Objects
Did you know that you can use the Index Server, the content indexing engine included with IIS4, as you would any other database? You can make ADO calls to it and search your site, providing you with an excellent search engine for your webs.
Using Index Server's
Did you know that you can use the Index Server, the
content indexing engine included with IIS4, as you would any other database? You
can make ADO calls to it and search your site, providing you with an excellent
search engine for your webs.
It's pretty simple, really. You just declare the
objects, make the calls to then engine and then reference the properties,
columns and values that you ask for. Pretty nifty, eh?
"OK, so how do I do this?" you're asking...
It's as easy as this:
- Set up the form page that will prompt the user for their input, to be
passed to the Index server engine.
- Set up the ASP page that will query the engine and show the results
- Test... (of course...)
Let's take a look at the code that's used by swynk.com in the left-column
Creating the Form
The form is quite simple. It's your basic HTML form,
with some added, hidden fields that help drive certain search engine
You can download the form by clicking here and then follow along. It's a text
file from this link, but you can cut and paste it as needed for your use.
If you compare the form setup with the search you see on
the left-side of this page, you'll see where the fields come in, and where the
Find It! button is displayed. Also, looking that the source in the file, you'll
see that the fields are briefly explained:
- mh is the Maximum number of hits you want to
return. For swynk.com, this value is 200. Making the value too
high can tax your server unnecessarily. Too low and you won't return
enough results to be meaningful. This will take some tweaking on
your part to determine the best value for your site. (for you
SQL folks out there, sounds like "Set rowcount=", doesn't
- sd is the column name that you want to use as the sort
value. In this case, we're calling out the hitcount column -
indicating that we'll display the page with the most hits on the search
first then order the results set from there, Descending (the "D" in the SD). (SQL folks - this is equivalent to the "Order
- ae simply turns on enumeration for the results set.
- ct points out where to find the catalog, or index
database, that will be used. This one's a bit tricky. When you
turn on the index server for a given web, you'll indicate where the index
database should reside. You MUST point this value to that location, or
the index server will simply return NO results. (this is the FROM
Then, of course, it calls the ASP page that will take
these values and query the server. Note that it's using a GET type of form
processing - more on this in just a minute, but it's imperitive that you use
this if you're using our example pages.
Creating the ASP Page
The ASP Page is where things get really cool. You use
the values from the form to drive the objects that will query the index server.
Here's the overall process:
- Set up the server object
- Open the recordset
- Step through the recordset, using standard ADO
You can download the basics of the ASP page by clicking here and
then follow along. Again, it's a text file from this link, but you can cut and
paste it as needed for your use.
The first thing you have to do is to set up the
reference to the index server object. You do that by using the
Set objQuery =
Add in the properties...
Now the objQuery object is set up and ready to be
configured, prior to setting up the recordset that references it. Of
course one of the fundamental things that you'll need to do is to set up the
query - what you are looking for in the database. This is done from the
incoming URL information - and there is a method to pull all of this from the
URL and put it into the object automatically:
This will pull all of the different parameters,
properties and query string information from the URL and put it where it belongs
in the object. This is how the parameters set up as hidden fields in the
form are translated into properties for the search.
Stir in the columns...
Next, indicate which columns you'll want to return from
the search. We've called out the most common, and those which will provide you
with summary and URL information. There are others, but that's a subject for a
In this case, we're asking for the filename, the number
of hits that are occuring in the source file for the search string we've
provided, the document title (between the TITLE tags in the HTML), and the
summary information for the file. This will give the user the overview of what
the page is about.
If you place the DESCRIPTION meta tag in your pages, the
characterization will include that information. If not, the characterization
will provide a look at the first portion of each page as it's shown. Index
server will ignore include and scripting text in the files, so you'll generally
only get "real" content.
You're ready to query the database - simply create the
recordset just as you would any ADO data source.
set rsQuery =
Voila! You've just queried your server. No
mess, no fuss. What you have now is a recordset, rsQuery, that you can use
MoveNext, MovePrev, etc. methods on. You'll be able to reference each of
the columns returned by the query by simply calling them out with the rsQuery
You even have the standard recordcount property
associated with the results. rsquery.recordcount will let you know the
total number of rows returned, up to the maximum value you indicated in the
properties for the query.
Give it a try - just search from the tool on the left - and you can
follow along in the code from the pages you've just downloaded. It's
really an excellent way to search your site and use the Index Server.
The frosting on this cake is how you handle the output of the search
results. Paging, formating the links, etc. It's all presentation, right?! Stay
tuned - if enough people are interested in hearing more, I'll write up
part II of this article - How to page your results, how to format