Quantcast
Channel: Towards Next » C#
Viewing all articles
Browse latest Browse all 10

Search your website (Microsoft Indexing Service, C#, ASP.NET)

$
0
0

You might have seen various website providing search capabilities to search content within their website. Implementing this in our web application is also easy and for that we have to just use the indexing service to create indexes of our pages. Microsoft is providing indexing service which we can utilise for this purpose.

To understand what is indexing service click this link

Now you might wonder how to get this service in your system. For that follow the steps

1. Goto Control Panel > Add Remove Programs
2. Click “add remove windows component”
3. from the screen select “Indexing service” and install

Installing Indexing Service

Installing Indexing Service

Now you have indexing service in your system. From computer management you can see the indexing service and can manage it. We need to create new catalog which will contain the indexes. To that catalog we will add the directories which are to be indexed.

Indexing Service Management

Indexing Service Management

There are other settings too like Indexing Service usage and etc. For that right click your indexing service node and select All Task > Tune Performance

Tune Performance (Updating Indexes)

Tune Performance (Updating Indexes)

We can now implement this in our web application to search the web pages. Below sample code is written for seaching and displaying the content in the ASP.Net Page

 string connectionString ="Provider=MSIDXS;Data Source=MISSample;";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();

string query = @"SELECT Path, FileName, size, write, attrib, Characterization,
DocTitle FROM SCOPE() " +
"WHERE FREETEXT(Contents, '*" +  txtQuery.Text + "*')";
OleDbCommand command = new OleDbCommand(query, connection);
OleDbDataAdapter adapter = new OleDbDataAdapter(command);

DataSet dataSet = new DataSet();
adapter.Fill(dataSet);

GridView1.DataSource = dataSet.Tables[0];
GridView1.DataBind();
connection.Close();

Sample Output

Sample Application

Sample Application



Viewing all articles
Browse latest Browse all 10

Trending Articles