SIGN UP MEMBER LOGIN:    
ARTICLE

Using Index Server for ASP.NET Site Search

Posted by sushilsaini Articles | ASP.NET Programming January 23, 2004
This projects highlights how to add search facility to your ASP.NET page using ADO.NET to browse index server search catalogs.
Reader Level:
Download Files:
 

Description 

This is a sample project made to help ASP.net developers. This projects highlights how to add search facility to your asp.net page using ADO.net to browse index server search catalogs. To be able to understand this , developer should have knowledge of using ADO.net to show the data on the Asp.net Page.

Introduction

This code is developed to enable search facilities to ASP.net applications. This is a easy to use as only with few lines of code you will be able provide dynamism to your applications. It works like accessing a query from database. Before starting this project , you must create a catalog using the Index Server. To read more details how to create and configure catalogs

Table Format

Heading  Heading
using Index Server Search in ASP.net This is a sample project made to help ASP.net developers. This projects highlights how to add search facility to your asp.net page using ADO.net to browse index server search catalogs. To be able to understand this , developer should have knowlege of using ADO.net to show the data on the Asp.net Page.

Create Catalog :
To create a catalog
  1. In the MMC, select Index Server.
  2. From the Action menu, select Stop.

    You must stop the Content Index service before you can add a catalog.
  3. From the Action menu, select Create New and then Catalog.
  4. In the Add Catalog dialog box, type the name of the catalog.
  5. Click the Browse button and select a directory where you want this new catalog to be located.
  6. When you have selected the catalog location, click the OK button.
  7. With Index Server selected, from the Action menu, select Start.

    Restarting Index Server makes the new catalog available for the indexing process.


Note : Before you can add a new catalog, you must stop Index Server. After you create a new catalog, you must restart Index Server to bring the new catalog online. But before bringing it online, you may want to add directories and modify catalog properties.
Summary using catalog in asp.net
This project is development using following packages in the ASP.net Application with Csharp.
using
System.Data;
using System.Data.OleDb;
ASPX page contains one textbox , Button and label on the page
<
form id="search" method="post" runat="server">
<TABLE id="Table3" cellSpacing="1" cellPadding="1" width="95%" align="right" border="0">
<TR>
<TD>
<P>&nbsp;</P>
<P>
<asp:Label id="Label1" runat="server">Search Site</asp:Label>
<asp:TextBox id="txtSearch" runat="server"></asp:TextBox>
<asp:Button id="btnSearch" runat="server" Text="Search"></asp:Button><BR>
<BR>
<asp:Label id="lbl" runat="server"></asp:Label></P>
</TD>
</TR>
</TABLE>
</form>

protected
System.Web.UI.WebControls.TextBox txtSearch; protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button btnSearch;
protected System.Web.UI.WebControls.Label lbl;
public int cnt;
/// <SUMMARY>
/// On the click of button, search for the keyword in the index catalog , and show the matching result on the page /// </SUMMARY>
/// <PARAM name="sender"></PARAM>
/// <PARAM name="e"></PARAM>
private void btnSearch_Click(object sender, System.EventArgs e)
{
// connecting string for connecting index server, In this provider name is MSIDXS ; DataSource is name of the catalog name in the index server.
// create a connection object and command object, to connect the Index Server
System.Data.OleDb.OleDbConnection odbSearch = new System.Data.OleDb.OleDbConnection(); System.Data.OleDb.OleDbCommand cmdSearch = new System.Data.OleDb.OleDbCommand(); 
//assign the connecting string to the oledb connection object , replace Catalog Name with the name of index catalog created earlier
odbSearch.ConnectionString = "Provider=\"MSIDXS\";Data Source=\"[Catalog name]\";";
//assign connection to command object cmdSearch
cmdSearch.Connection = odbSearch;
//Query to search a free text string in the catalog in the contents of the indexed documents in the catalog
try
{
// Make freetext search in the contents and retreive document titles , path , rank from the index catalog
cmdSearch.CommandText = "select doctitle, filename, vpath, rank, characterization from scope() where FREETEXT(Contents, '"+txtSearch.Text +"') and filename <> 'search.aspx' order by rank desc ";
odbSearch.Open();
try
{
OleDbDataReader rdrSearch = cmdSearch.ExecuteReader();
//dg1.DataSource=rdrSearch; //dg1.DataBind(); cnt=1;
lbl.Text="";
// your databinding or display code here
while( rdrSearch.Read())
{
// Call method get pagelink to write process and show the valid link on the page , here we have used getpagelink to show the file name searched
getpagelink(rdrSearch[1].ToString());
}
}
catch(Exception ex)
{
lbl.Text=ex.Message ;
}
odbSearch.Close();
}
catch( SqlException ex)
{
lbl.Text=ex.Message.ToString();
odbSearch.Close();
}
}
/// <SUMMARY>
/// This function creates the link of the searched document in the predefined template.
/// </SUMMARY>
/// <PARAM name="srcfile">This Function is </PARAM>
public void getpagelink(string srcfile)
{
string temp= (cnt).ToString() +".) " + srcfile;
}

To customize your pages , you can put several Headers and other HTML Tags to make it familiar to your pages, In case you have already fixed your templates you can make a user control instead of making a ASPX page and then add User control to any of webforms and load them, using this technique.
To test this page  type keyword in the text box and click the button given on the page and wait for the page response.

Login to add your contents and source code to this article
Article Extensions
Contents added by Robert on May 27, 2010

I am trying to exclude filename types .pdf and .doc not shown in your article

Here is my syntax, can you shed some light on this?


string query = String.Format(@" SELECT Rank, VPath, DocTitle, Filename, Characterization, Write, ilAgency, ilCountryName, ilSummary, idcAttachmentSize FROM SCOPE('DEEP TRAVERSAL OF ""{0}""')
            WHERE NOT CONTAINS(VPath, '""_vti_"" OR "".config"" OR ""search_excluded""')", this.cboDirectory.SelectedItem.Value);


Rob

share this article :
post comment
 

i want advanced search options ,, like i give the name 'raja' it extract the result from database 'raja rajan', 'rajan', 'rajaguru' like that....

Posted by vimal prakash Jul 26, 2010

I want to do Advance Searches and be abel to query "Air Combat" and not get back "repair" results. I been to the Index Server admin and see there is a Advance radio button, but I can't find example code that I see how to turn this option on. Thanks mike

Posted by Michael Clinton Feb 09, 2009

Hello Sushilsaini, I just read your article on Index server. I really liked it. Please can you help me a list of books i can get to know more on Index server. Especially using ASP.Net. Thanks JOHN

Posted by darkestangel1980 Jun 27, 2007
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor