Sunday, April 12, 2009

How to use Microsoft Indexing Service to make search faster...

Introduction


Microsoft Indexing service is like, it is making catalog for storing index of documents. and when we are searching from using Indexing service it will use those indexes which are stored into catalog, and will do search very much faster.

So here i will try to explain how we can use this Microsoft Indexing Service.
Using the code

First, we have to configure our Microsoft Indexing service to use it.

install Microsoft indexing service from the Add/Remove utility from control panel...

choose Add/Remove Windows Component --> and select Microsoft Indexing Service and install it.

Now write mmc in Start --> Run,

you will find one window which is said "Microsoft Management Console".

no do this procedure..

Click on File -->ADd/Remove Snap-in --> Add -- > select "Indexing Serivce" then --> ok --> finish.

you will see like following window..

now you have to create one catalog, which will keep track of you directory which you want to search in.

to create catalog click on "Indexing Service on Local Machine" then,

Action --> New - > catalog

Enter Name of catalog and path where you want to save the catalog files.

Your newly created catalog will be there in tree,

no just expand that node and you will see "Directories", now right click on it and select "New" --> "Directory"

Enter the path of irectory which holds your documents in which you want to perform searching operation.

Now Stop and then Start the Indexing Service, it"s all, your indexing service is ready to use with your application.

// first create the OleDb connection...

System.Data.OleDb.OleDbConnection odbSearch;
System.Data.OleDb.OleDbCommand cmdSearch;
//Then prepare the Connection String to connect with the

//Indexing Server database.

odbSearch = new System.Data.OleDb.OleDbConnection
("Provider="MSIDXS.1";Data Source=MyDocs;Integrated Security .=");

//Instead of "MyDocs" you have to wrtie catalog name which you have created,

//from above process.


cmdSearch = new System.Data.OleDb.OleDbCommand();
cmdSearch.Connection = odbSearch;

//Now Prepare the Command Text.

cmdSearch.CommandText =
"select doctitle, filename, vpath, rank, characterization from scope()
where FREETEXT(Contents, "" + strSearch + "") order by rank desc ";
//Now Open the Connection.

odbSearch.Open();
//Now Fire the command.

OleDbDataAdapter adpt = new OleDbDataAdapter(cmdSearch);

cmdSearch.ExecuteNonQuery();

DataSet ds = new DataSet();
DataTable dt = new DataTable();

adpt.Fill(ds, "SearchResult");
dt = ds.Tables[0];

//Thats it, DataTable "dt" will hold your Search Result you can use it now.





Future enhancement


This Process will search only .doc,.txt, .xls files only,

For making it working for .pdf, you have to download Adobe iFilter 6.0 and simply install it.

No comments:

Post a Comment

Followers

My Google Reader