C# – Searching the name of web pages according to the word entered in a textbox

asp.netc

I have a textbox and a button in one page.I want to enter a word in the textbox and click the button. After clicking the button I want to display the name of the web pages containing the word entered in the textbox. So please tell me how to do it? I am using C#.

Best Answer

So you want to create a search engine internal to your website. There are a couple of different options

  • You can use something like google custom search which requires no coding and uses the google technology which I think we all agree does a pretty good job compared to other search engines. More information at http://www.google.com/cse/
  • Or you can implement it in .net which I will try to give some pointers about below.

A search engine in general exists out of (some of) the following parts:

  • a index which is searched against
  • a query system which allows searches to be specified and results shown
  • a way to get documents into the index like a crawler or some event thats handled when the documents are created/published/updated.

These are non trivial things to create especially if you want a rich feature set like stemming (returning documents containing plural forms of search terms), highlighting results, indexing different document formats like pdf, rtf, html etc... so you want to use something already made for this purpose. This would only leave the task of connecting and orchestrating the different parts, writing the flow control logic.

You could use Lucene.net a opensource project with a lot of features. http://usoniandream.blogspot.com/2007/10/tutorial-implementing-lucenenet-search.html explains how to get started with it.

The other option is Microsoft indexing service which comes with windows but I would advice against it since it's difficult to tweak to work like you want and the results are sub-optimal in my opinion.