
Introduction
Once a site starts growing a search facility is a necessity. There are a number of third
party search engines that can be installed in your site, but for many purposes the Index
Server that comes with IIS is more than adequate. What is the Index server? The online docs
put it succinctly as follows:
Indexing Service is a Microsoft� Windows� 2000 service that indexes files on
your disks and their properties as well as your Internet Information Services
(IIS) Web files and properties. Indexing Service stores the resulting
information in catalogs that you can efficiently search using a variety of
queries.
The Index Server allows you to run queries against the service using ADO and OLE DB. This
provides ease of use and flexibility in providing a search facility.
The Index Server Object
The index server is created like any other COM object on your server:
dim ixQuery ' Index Server query object.
set ixQuery = Server.CreateObject("ixsso.Query")
The object has a number of properties that can be set before running the query. The
most useful are the Columns, SortBy, MaxRecords and Query properties.
Columns
The Columns property allows you to specify which fields are returned by
the query. For a full list you should consult the online docs, but for the current example
we will return the following:
- doctitle
- The page title (as specified in the <TITLE>...</TITLE> element)
- vpath
- The Virtual path to the page
- size
- The size of the page
- characterization
- A description of the page
- rank
- A value specifying how well the page matches the search criteria
ixQuery.Columns = "doctitle, vpath, size, characterization, rank"
SortBy
SortBy specifies how the matches will be sorted. List the fields in relevant
sort order, and use "[d]" to specify that the field should be sorted in descending order.
ixQuery.SortBy = "rank[d], doctitle"
MaxRecords
You should limit the number of matches the query returns - chances are the user will only
browse the first couple of dozen in any case
ixQuery.MaxRecords = 300
Catalog
A Catalog represents the indexing results for a particular directory (or directories). If
you don't specify a catalog then the Index Server will use the default 'web' catalog that
indexes /inetpub/wwwroot. Sometimes you may want to specify a catalog (eg. if your
site is in a different directory or you want to have multiple catalogs for different search
pages).
Adding a catalog
To set up a catalog, go to the Indexing Services branch of the Services and Applications
branch in the Computer Management console (under Start -> Programs -> Admin Tools). Right click
on Indexing Services and select New -> Catalog. Enter in the name of your new catalog and
a location where the index files should be stored. Hit OK, then right click on the newly
created catalog and select New -> Directory. Add a directory that you wish to have indexed,
and repeat as necessary. Subdirectories will automatically be indexed too. You can also
specify directories within the directory tree that should not be indexed. To do this, add
the directory that you wish to be ignored, and click No in the Index this resource box).
Typically you would add a directory tree to be indexed, and then you may want to specify
certain subdirectories under that directory's heirachy that you don't want indexed. This
gives you some coarse grain control over what gets indexed.

Ensuring that the Catalog generates abstracts for your searches
If you want your catalog to contain abstracts of the files indexed then you need to
right click on the catalog and select properties. Click on the Generation tab
and ensure that the Generate Abstracts checkbox is ticked. If it's disabled, then
uncheck the Inherit above settings from Service box. You can then set the size
of the abstract to be generated.

Ensuring that the search generates correct vpath's for your search
To ensure that the index search generates correct virtual paths (vpaths) for the search you
should associate the catalog with the web server. In the computer management console under
'Indexing Service' right click on your catalog and select properties. Click on the Tracking tab
and choose your server from the 'WWW Server' dropdown

Specifying a Catalog to use in your search
Specify the catalog to use in your search by adding the following:
ixQuery.Catalog = "CodeProject"
Fire up the Internet Service Manager, open up the properties dialog for your site, select the 'Home Directory'
tab and ensure that the "Index this resource" check box is ticked.

You also need to ensure that the folder properties in Explorer are set to
allow the folder to be indexed. Navigate to the folder containing the folder
with your site's files, right click on your site's folder and choose properties,
click 'Advanced' and check the 'For fast searching, allow Indexing Service to
index this folder'.
Thanks to Kurt and Izidor Gams for updates on this.
Query
The actual query. This is the guts of the entire operation. The Index Server supports
3 query languages: Dialect 1 (Index Server 1.0), Dialect 2 (Index Server 3.0) and SQL
(Index Server 2.0 and above). See the topic "Query Languages for Indexing Service" in MSDN
for a full explanation of these different languages.
In our case we'll work with the simple dialect 1 - though it would be just as easy
to use the familiar SQL syntax if you wished.
At the simplest, you can simply set the Query propery of you Index Server object
as the search target. For example, if you were looking for all pages with the word
"Apples", the use
ixQuery.Query = "Apples"
We can refine this somewhat by specifying which files will and will not be searched,
the way in which you target query is interpretted (as a phrase, as a free text search,
as an exact match etc) and also the types of pages that will be searched (eg only pages
written after a certain date, or less than a certain size).
For example, to specify a free text search for the phrase "Apples are green", use
$contents Apples are green
To specify field restrictions, use the "@" prefix on a predefined field name, and
an expression. For instance:
@size < 1000000 ' size must be less than 1,000,000 bytes
@contents apple tree ' Contents must contain the phrase "apple tree"
@write > 70/10/24 ' Page must have been written after October 24, 1970
Filename restrictions can be specified by using the "#" prefix to specify a
regular expression search, and a wild card;
#filename *.asp ' search only ASP files
#vpath *\articles* ' search in the \articles subdirectory
All these expressions can be combined using the boolean operators AND, NOT, OR etc. Thus
if you search target expression is "Apples", you only want to search in ASP files, and
you want to ignore the \_vti directory, use the following:
ixQuery.Query = "(#filename *.asp) AND (NOT #vpath *\_vti*) AND (Apples)"
The Index Server Utility object
A related object to the Index Server object is the Index Server Utility object. This allows
you to specify to specify the depth of the search - either "shallow" (for the named directory
only) or "deep" (for a recursive search through all sub-directories).
dim util
set util = Server.CreateObject("ixsso.Util")
util.AddScopeToQuery ixQuery, Server.MapPath("/"), "deep"
The first parameter specifies the Index server object to associate the utility with; the second specifies the physical path to start the search (in our case the root folder); and the third specifies the type of search.
Performing the search
To run the actual query, simply call Query.CreateRecordset
dim queryRS
set queryRS = ixQuery.CreateRecordSet("nonsequential")
Displaying the results
To display the results simply loop through the recordset.
Response.Write "<table width='100%'>"
do while not queryRS.EOF
dim docTitle
docTitle = queryRS("doctitle")
if docTitle = "" then docTitle = "Untitled"
Response.Write "<tr>"
Response.Write "<td valign=top>"
Response.Write recordNumber & ".</td>"
Response.Write "<td valign=top>"
Response.Write "<a href='" & queryRS("vpath")
Response.Write "'>" & docTitle & "</a><br>"
Response.Write "<b>URL: </b> http://"
Response.Write Request.ServerVariables("server_name")
Response.Write queryRS("vpath") & "<br>"
Response.Write Server.HTMLEncode(queryRS("characterization"))
Response.Write "</td>"
Response.Write "</tr>"
recordNumber = recordNumber + 1
queryRS.MoveNext()
loop
Response.Write "</table>"
The demonstration script
The sample script ties all this together and also demonstrates how to provide the user with a facility to view the results page by page. Feel free to use and customise this script on your own sites.
History
16 Jun 2000 - posted
23 Apr 2001 - update to fix paging problem (thanks to Khaled)
29 Jul 2001 - update to include information on generating abstracts
31 Oct 2001 - update to include information on generating vpaths and ensuring indexing is working
| You must Sign In to use this message board. |
|
|
 |
|
 |
Hello there,
I am trying to return all my documents that have a DocTitle or null value.
This is my current code and my problem is that I do no know what the syntax would be for returning a null or empty value for $DocTitle. My code keeps returning the actuall string value. I need to check for all files that contain no DocTitle.
set objQuery =Server.CreateObject("ixsso.Query") objQuery.Catalog = "HSS_Web_Content" objQuery.Columns = "Characterization, DocTitle, Filename, Path, Rank, Size, Vpath, Write" objQuery.SortBy = "Rank[d], size" querystring="Health" doctitlestring="" 'response.Write "Query String=" & querystring Set objUtil = Server.CreateObject("ixsso.Util") objUtil.AddScopeToQuery objQuery, "D:\websites\hss\htdocs\", "deep" 'objUtil.AddScopeToQuery objQuery, "DocTitle=""" 'objQuery.Query = "(@contents " & querystring & ")" & " & (@write > -1y)" & "& (DocTitle Is Null)" 'objQuery.Query = "(@contents " & querystring & ")" & " & (@size > 1)" 'myquery="(@size > 1)& (DocTitle = Null)" tempstring="" myquery="(@size > 1)" myquery=myquery & " and not #filename *.|(js|,wbt|,vbs|,xml|,cfm|,gif|,jpg|,inc|,bat|,ashx|,css|,scc|,ldb|,log|,tpl|,mso|,png|,wmz|,cs|,ascx|,config|,class|,bak|,exe|,vb|)" myquery=myquery & " And ($DocTitle = Null )" objQuery.Query=myquery
response.Write "objQuery.Query=<b>" & objQuery.Query & "</b><br>"
objQuery.MaxRecords = 500 set RecSet = objQuery.CreateRecordset("nonsequential") response.Write "Number of Records=" & RecSet.RecordCount & "<br><br>"
while not RecSet.EOF stringDocTitle=RecSet("DocTitle") 'replace physical path with virtual path strHREF = Replace(RecSet("Path"),"d:\websites\hss\htdocs\","http://10.23.97.91/") strHREF = Replace(strHREF, "\", "/")
if IsNull(stringDocTitle) then DocTitle="No DocTitle" Else DocTitle=stringDocTitle end if Response.Write "<A HREF=" & strHREF & " target=_blank>" & DocTitle & "</a><BR>" & vbCrLf 'Response.Write "<A HREF=" & stringDocTitle &"</a><BR>" & vbCrLf 'Response.Write "<b>Summary: </b>" & RecSet("Characterization") & "<BR>" & vbCrLf Response.Write "<b>Rank: </b>" & RecSet("Rank") & "<BR>" & vbCrLf Response.Write "<b>File Name: </b>" & RecSet("FileName") & "<BR>" & vbCrLf Response.Write "<b>Size: </b>" & RecSet("Size") & "<BR>" & vbCrLf Response.Write "<b>Path: </b>" & RecSet("Path") & "<BR>" & vbCrLf Response.Write "<b>Last Update: </b>" & RecSet("Write") & "<HR>" & vbCrLf RecSet.MoveNext wend Thanks in advance, Steve
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hi This code works perfect for me as of now, untill i realized that i am not able to search .docx, .pptx. (i would say 2007 version files of all extentions) and pdf files. What is the alternative to fix this issue.
Any help is greatly appreciated
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I just wanted to let you know (as if you didn't know) that The Code Project is a significant website that has made a major positive difference in my capabilities by providing a great volume of technical support, assistance and guidance to me over the years. Most recently I researched your site on how to query remote index servers and you and your colleagues have come through once again. TCP is a premier source of good technical information. My friend: YOU have made a difference in this world !
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
Hi A very good article.But can you explain how to query the directory that are added as scope to the catalog on the local index server? I have 3 directory under "intranet" catalog. Right now, I am able to query from scope to the indexing server but still not able to query the directory added to my catalog.
<select name="Scope" size="1" class="tbox"> <option value="/" selected>All Database</option> <option value="/articles/">Articles</option> <option value="/journals/">Journals</option> </select>
Thank you
Agung Prasetyo W. STIKOM Library http://library.stikom.edu
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Can anyone explain how to incorporate hit highlighting in my results page?
Thanks,
Ellen
_________________ http://thedesignspace.net
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
No, I gave up: there seems to be no way to do it in one step using this system.
_________________ http://thedesignspace.net
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi.
I read the whole article, I set my catalog many times but the search only works on the Web catalog or in the Default (nothing set in sample script).
When I point to my catalog, nothing happens.
The catalog is ready and created, many parameters tested, now the catalog folder is in 80mg, so something is filling it, but no results from there, testing with simpler strings such as "body" or "html".
File extension filter works, many other setups too, but nothing with my catalog. I created it yesterday and until now, nothing is found.
Some ideas? Thanks!
Marcelo - LordKaos kaosinc@yahoo.com
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
I had this problem also. Try changing util.AddScopeToQuery ixQuery, Server.MapPath("/"), "deep"
to the actual virtual path to your directory. Like this:
util.AddScopeToQuery ixQuery, Server.MapPath("/content/modules/"), "deep"
_________________ http://thedesignspace.net
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This was setup at my current job and working great. The person who originally set this up has now left the company.
We upgraded the server to win 2003 server.
Now all we are getting is No results found, but when query on the server from the indexing service, all the results are returned.
Any help on what we could do to get this working again or anywhere to look?
Thanks.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
Does somebody get this scripts running with W2K Server and IIS 5? I was reading all posts in this forum, but still get the message „No matches found“.
I’m using the default Web catalog, but added a directory c:\initpub\wwwroot_1\documents. I have around 900 ducuments in it and I’m getting results using MMC.
I added the script (I called it ixsearch.asp) to the scipt directory in the default server and chanched the search string to:
strQuery = "(#filename *.doc) and (#filename *.ppt) and (#filename *.htm)"
Could somebody please point me in the right direction. I would relay like to see this script running.
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
|
 |
|
 |
Let me first just say that this little bit of code is exellent. One functionality i was hoping to be able to dow was to display the results differently by sorting them in different ways e.g. by author, by last modified through having a links on the result page that just displays it differently. Another thing i wish to do is to display all the results but only 10 or 20 at a time and have a next results page feature built in. Any help on how to do this would be greatly appreciated even if it's to point me in the right direction to guides or tech notes. All help is welcome. Thanks
Stereoscreamer
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
|
 |
|
 |
What kind of error checking is on error resume next? You cannot use this in the professional development world. Using this type of error checking could get you the sack.
Don't get me wrong, this is quite a useful article and I'm not discrediting the work, only the error checking.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
The code is meant to demonstrate a technique, not be the epitome of tight, secure code.
cheers, Chris Maunder CodeProject.com : C++ MVP
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
On error resume next will run the asp page atleast any code error occure. so will get atleast some result by exicuting the pafe complete
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I have indexed all the directories on c:/ drive. I am making a search web page in ASP which returns the filename with its source path. For some queries the query takes so much time that iis responds with timeout error while the query is executed instantly on the default query form for the catalog in MMC. What is the reason of this kind of delay? Even, I tried with commenting the extra lines. Recordset is not created in time
Manish Tanwar
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
It worked well.Only for where it was supposed to display the characterisation. I guess the indexing hasnt finished, so i put a condition to check if it was blank it should ignore printing the part, the vpath too hasnt come up so i just presume when the indexing finishes it will all work perfect.
Thanks.
Web Programmer Mindcraft Ltd, Lagos Nigeria B. Sc. Computer Science, MCP, MCDBA
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi, I added to the result search a button to delete de file. The problem is that after deleting the index keeps showing the file under the same search...aldo it only shows the information that was stored in the index server...
I even did a "FULL Rescan" and it´s still showing.
Is there a way of programatically calling a "remove from index" or something!? Thanks!!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I had the same problem. Thanks to Hilary Cotter's post[^] : Open up your catalog, Right-click and select “Generation”, ensure that Generate Abstracts is ticked. Open up the properties folder, sort by property sets until the characterization property bubbles to the top. Right click on it and ensure that cached is ticked. Stop and start indexing service. Re-start Full Scan.
Michael Freidgeim. Blog: http://geekswithblogs.net/mnf/
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
|