How to implement Indexing service in the asp.net application?

Microsoft Index Service allows the contents of files on the machine to be indexed to enable free-text searching. It uses catalog to maintain the indexes. A catalog can be created or existing catalogs can be re configured.
First of all you have to create a new catalog. Following are the steps:

1. Open the Computer Management tool available in Administrative Tools.
2. In the tree view under Services And Application node click on Indexing Service.
3. You will see the list of existing catalogs in the right panel.
4. Right-click on 'Indexing Service' and select 'New' and 'Catalog' from the list that appears. You will be presented with the Dialogue box
5. Give the catalog a name like “Search” and location of the catalog
6. Press 'OK' to continue, note that the server will inform you that the 'Catalog will remain off-line until service is restarted'.
7. Add directory whose content you want to get indexed.
8. Open the properties of it
– In the tracking tab choose your site in the WWW Server dropdown.
– In the Generation tab check the Generate abstracts.

Reference - http://www.simongibson.com/intranet/indexserv/

For accessing catalog in your .net application, you have to get Interop.Cisso.dll and add its reference into your project. Following is the code sample:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Text;
using System.ComponentModel;
using Cisso;

void SearchProcess()
{

if(Request.QueryString[ "qry" ].ToString()!="")
{
string SearchString= Request.QueryString[ "qry" ].ToString();

OleDbDataAdapter DataAdapterObj =new OleDbDataAdapter();
DataSet IndexSearchDS =new DataSet("IndexServerResults");// ' give the dataset a name
CissoQueryClass Qry=new CissoQueryClass();
CissoUtilClass Util=new CissoUtilClass();
StringBuilder strbldSearch =new StringBuilder(SearchString);
strbldSearch.Append(" and not #filename *.inc");
strbldSearch.Append(" and not #filename *.css");
strbldSearch.Append(" and not #filename *.vb");
strbldSearch.Append(" and not #filename *.cs");
strbldSearch.Append(" and not #filename *.js");
strbldSearch.Append(" and not #filename *.xml");
strbldSearch.Append(" and not #filename *.ascx");
strbldSearch.Append(" and not #filename *.log");
strbldSearch.Append(" and not #filename *.config");

Qry.Query = strbldSearch.ToString();
Qry.Catalog = "Search";// ' name of your IndexServer Catalog
Qry.SortBy = "rank[a]";// ' a-ascending, d-descending
Qry.Columns = "Rank, DocTitle, vpath, Path, Filename, Size, Write, Characterization,";
Qry.MaxRecords = 250;// ' for best performance keep below 500
Util.AddScopeToQuery(Qry, "/", "deep");
DataAdapterObj.Fill(IndexSearchDS,Qry.CreateRecordset("nonsequential"),"IndexServerResults");
}
}

No comments: