Friday, May 07, 2004

Searching Indexing Services with ASP.NET and C#

So I have a project that requires we have a mini site search. And being that I have written the whole site in ASP.NET/C#/XML/XSL I didn't want to have to go back to classic ASP for search. I did some searching online and found a really good post on using ASP.NET with Indexing Services. The article/post "Query the Indexing Service with Ixsso and ASP.NET" covered the issue really well. However it was written in VB. So of course I needed a C# version of it, so I just translated the VB stuff to C# and voila!.

private void searchIndexing(string strValue)

{

try

{

CissoQueryClass Q = new CissoQueryClass();

CissoUtilClass util = new CissoUtilClass();

OleDbDataAdapter da = new OleDbDataAdapter();

DataSet ds = new DataSet("IndexServerResults");

Q.Query = strValue;

Q.SortBy = "rank[d]";

Q.Columns = "vpath, filename, rank, characterization";

Q.Catalog = "query://contentserver/catalogname";

Q.MaxRecords = 1000;

util.AddScopeToQuery(Q,"\\","deep");

Q.LocaleID = util.ISOToLocaleID("EN-US");

da.Fill(ds, Q.CreateRecordset("nonsequential"), "IndexServerResults");

DataGrid1.DataSource = ds;

DataGrid1.DataBind();

 

}

catch(Exception f)

{

lblError.Text = f.Message.ToString();

}

}

Just make sure you add a reference to the IXSSO COM Object in your project and away it goes!

 

No comments: