Including Search for your website documents -Part 2

If you have come to this article without reading the Part 1, please check Part 1

Once you have created the Catalog for your Search, you can use the Catalog for searching.

Using the Catalog in your Application

1. In your Search Page, have a Textbox (TextBox1) and a Button (Button1).

2. In the click event of the Button, put the following code.

string strCatalog = <Put the Name of the Catalog here>;

strQuery = "Select Filename from Scope() where FREETEXT('" + TextBox1.Text + "')";

string connstring = "Provider=MSIDXS.1;Integrated Security .='';Data Source="+ strCatalog;

OleDbConnection objconn = new OleDbConnection(connstring);

OleDbCommand objcmd = new OleDbCommand(strQuery, objconn);

OleDbDataReader objRdr=null;
objconn.Open();
objRdr=objcmd.ExecuteReader();

if(objRdr.HasRows)
{
while(objRdr.Read())
{
docname += objRdr["Filename"].ToString() + ",";
}
docname=docname.Remove(docname.Length-1,1);
}
}


Now "docname" has a comma separated list of file names containing the search text.

You can have an XML File or a Database table with Nodes/Fields - FileName, a Heading and a Description, which you can use to look up for the document name and get the desired results for displaying in your Page.

This way, you can implement search for your website without writing the logic for search.

This article applies to Windows 2000, Windows XP and Windows 2003

Note:
If you would like to search for PDF Files, you need to install the PDF Filter for Indexing Service which helps the Indexing Service in searching within PDF Files. Its a freeware download and can be downloaded from
Here

Print | posted on Monday, April 25, 2005 7:55 AM

Comments on this post

# re: Including Search for your website documents -Part 2

Requesting Gravatar...
This is really a helpful resources. Thanks for sharing this one. I will try to code this at home.
Left by Jennifer Smith on Feb 16, 2012 8:37 PM

# re: Including Search for your website documents -Part 2

Requesting Gravatar...
This is really a helpful resources. I will try this code at home. Thanks for posting. - Kyle Thomas Glasser
Left by Jennifer Smith on Feb 16, 2012 8:47 PM

Your comment:

 (will show your gravatar)