Click here to Skip to main content
6,629,885 members and growing! (24,995 online)
Email Password   helpLost your password?
General Reading » Hardware & System » System     Beginner License: The Code Project Open License (CPOL)

Windows Indexing Service Basics

By Nirmal Singh Bhary

This article describes how to manage and use the Windows Indexing Service.
VBScript, Windows, Visual Studio, Dev
Version:8 (See All)
Posted:18 Feb 2009
Views:4,815
Bookmarked:8 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
2 votes for this article.
Popularity: 1.30 Rating: 4.33 out of 5

1

2

3
1 vote, 50.0%
4
1 vote, 50.0%
5

Introduction

When I was creating a virus scanner for my antivirus, I came across a situation where searching for files on the local drives became difficult and time consuming. So I started to search for a better technique for file searching, over the Internet. Then, I came to know about the Windows Indexing Service. Indexing Service can also be used for providing search capabilities on websites.

What is Windows Indexing Service

Windows Indexing Service is a wonderful utility in Windows NT, Windows 2000, and other Windows NT family of Operating Systems. As described in MSDN, “Indexing Service is a base service for Microsoft® Windows® 2000 or later that extracts content from files and constructs an indexed catalog to facilitate efficient and rapid searching.” With the help of Indexing Service, we can search files for contents, and properties on local host and on remote, networked hosts. Indexing Service uses filters for extracting contents from the files. Every file format has its different filter. Fortunately, Microsoft supplies filters for Microsoft Office files, Hypertext Markup Language (HTML) files, Multipurpose Internet Mail Extension (MIME) messages, and plain-text files. If we want to extraction information from any other format, then we need a filter for that; for example, for PDF files, we need Adobe PDF Ifilter (if you really need it, you can download the Ifilter from here).

What is a Catalog

Indexing Service stores all the indexing information about files in catalogs. By default, only one catalog, called System catalog, is created automatically when we install Indexing Service. There is another catalog called Web catalog, if Internet Information Services (IIS) is installed. The System catalog contains an index for all documents, on all permanently attached disk drives, except certain system and temporary files. Web catalog contains the index of Internet Information Services (IIS).

What is a Scope

After creating a catalog, we add directories to the catalog - this is called scope. Indexing Service will create an index of only those directories and drives which we add to the catalog.

How to Manage Indexing Service

With the release of Indexing Service 3.0, we can perform file system related tasks with several programming languages and several scripting languages. The .NET developer should note that .NET natively doesn’t support access to Indexing Service. So, they need to extend their .NET application to interact with either WMI or COM to manage/access Indexing Service. In this article, we will use VBS for managing and querying Indexing Service. For this, we will use these types of APIs:

  1. Admin Helper
  2. Query Helper

These APIs are available in three classes: AdminIndexServer, CatAdm, and ScopeAdm, declared in the CIODMLib library, so we will use the CreateObject function to access these classes.

Set objISAdm = CreateObject("Microsoft.ISAdm") 

Starting/Stopping Indexing Service

To start Indexing Service, we use the Start method, and to stop, we use the Stop method of AdminIndexServer. We can also pause the service by using the Pause method.

Set objISAdm = CreateObject("Microsoft.ISAdm")
objISAdm.start()

To check if the service is running or paused, use the IsRunning and IsPaused methods:

Set objISAdm = CreateObject("Microsoft.ISAdm")
If objISAdm.IsRunning= False then
    objISAdm.start()
end if

Adding a Catalog

If you want to create a new catalog, use the AddCatalog method:

Function AddCatalog(bstrCatName As String, bstrCatLocation As String) As Object

We have to pass two string arguments: the name of the catalog and the path where the catalog will be saved. Please note that the catalog will remain off-line until Indexing Service is restarted. So, the best method is to first stop Indexing Service, add the catalog, and start Indexing Service again. As shown below:

Set objISAdm = CreateObject("Microsoft.ISAdm")
objISAdm.stop()
Set objCatalog = objISAdm.AddCatalog("MyCatalog","c:\Mycatalog”)
objISAdm.start()

Adding an Indexing Service Scope

As I mentioned above, Indexing Service will create an index of only those directories and drives which we add to the catalog. So here, we will add a scope to our “My_Catalog” catalog using the AddScope method of the Catalog object. For getting the Catalog object, we use the GetCatalogByName method of the AdminIndexServer object as show below:

Set objISAdm = CreateObject("Microsoft.ISAdm")
Set objCatalog = objISAdm. GetCatalogByName(“MyCatatlog”)
Set objScope= objCatalog.AddScope(“C:\myfiles”,False)
objScope.Alias = "MyCatalogScope"

The AddScope method takes four parameters:

  • strScopePath - Required. The scope path to create.
  • blnExclude - Required. If TRUE, excludes this scope from indexing. If FALSE, enables indexing for this scope.
  • vtLogon - Optional. The string that represents the logon name.
  • vtPassword - Optional. The string that represents the logon password.

vtLogon and vtPassword are both required if the scope path is a UNC path. The Alias property is the case-insensitive name of the alias or friendly name for this scope. This property is read/write.

Querying an Indexing Server Catalog

Using queries, we can find files with words and phrases in their contents, or their properties such as the document's name or author. The simplest kind of query is a single word. For example, if you search for “programs”, Indexing Service returns all documents that contain the word “programs” in their contents. There are five kinds of queries:

Free-text and Phrase queries

With free-text and Phrase queries, we can search files for a group of words or a complete sentence. Indexing Service finds pages that best match the words and phrases in the Free-text and Phrase query.

Pattern-matching queries

In Pattern-matching queries, we can use wildcards and Regular Expressions. For example, “@filename=*.doc” will search all files with a “doc” extension.

Vector-space queries

In Vector-space queries, we assign weighting factors to control the relative importance of terms.

Example Querying an Indexing Server Catalog

set q = WScript.CreateObject( "ixsso.Query" )
q.Query = "@filename= *.vbs"
q.Catalog = "query://./SYSTEM"

q.AllowEnumeration =False
q.Dialect = 2
q.Columns = "FileName"
set rs = q.CreateRecordSet( "sequential" )

Do Until rs.EOF
    msgbox(rs("FileName"))
    rs.MoveNext
Loop

In this example, we search all files that have a “vbs” extension. We used the “SYSTEM” catalog here.

Summary

Indexing service is a powerful feature in the Windows Operating System. Moreover, it is free, easy to use, and very flexible. It can be used for both web and desktop applications. I hope this article helps you to understand Indexing Service and to better use it.

References

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Nirmal Singh Bhary


Member
I like computer programming and mostly like to develop system softwares such as antivirus, firewalls,scripting languages etc.
Occupation: Software Developer
Company: ION solutions Chandigarh
Location: India India

Other popular Hardware & System articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 18 Feb 2009
Editor: Smitha Vijayan
Copyright 2009 by Nirmal Singh Bhary
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project