[ Close ]
Username
Password


Forgotten your password?
 
Custom Search
Computer/IT Projects
 Projects Q A, Guidance for your projects Projects Forum Computer/IT Projects
Message Icon Topic: Search engne with asp.net in vb Post Reply Post New Topic
Found this useful? Give a +1   Add to Facebook: Add to Facebook
Free Project Downloads
CS / IT Project Downloads
.Net Project Downloads
JAVA Project Downloads
PHP Project Downloads
Networking Proj Downloads
Project Topics
Computer(CS/IT) Projects
Software Mini Project Topics
Android Project Topics
Networking Project Ideas
Dot Net Project Topics
Latest IEEE Projects List
IEEE JAVA Project Topics
Project Presentation Tips
How to choose Project Topic
Tips for Final Year Project
Steps for FYP, Mini Project
Preparing a Project Report
Problems faced in Projects
 
Get Free Software CS / IT Project Downloads:

Enter your email address:  

Author Message
amtigaikwad1988
Newbie
Newbie


Joined: 26-Apr-2012
Online Status: Offline
Posts: 0
Quote amtigaikwad1988 Replybullet Topic: Search engne with asp.net in vb
    Posted: 26-Apr-2012 at 5:43am
Hi There,


I was looking if anyone could help me with some coding. I am trying to build a simple search engine website in asp.net using VB. can you please help with the coding behind the search button that will search the result either from our database or from the web.
I have to submit this project, immediate response will be appreciated.


Thank You in advance,
Amit Gaikwad

 
IP IP Logged
LokeshNash
Senior Member
Senior Member


Joined: 21-Sep-2008
Online Status: Offline
Posts: 0
Quote LokeshNash Replybullet Posted: 30-Apr-2012 at 1:24pm
The C# code for search is shown below. The important elements are

    constructing the JSON Url with the query text
    using WebClient to start an asynchronous request for the results
    using JsonArray to parse the JSON and loop through array to populate our SearchResult objects
    'bind' the SearchResults to the UI via ItemsSource - the DataTemplate takes care of the formatting for us.

(note: you need to manually Add References to System.Json, System.Runtime.Serialization, System.Runtime.Serialization.Json)

/// <summary>
/// Start async request for JSON
/// http://msdn.microsoft.com/en-us/library/cc197953(VS.95).aspx
/// </summary>
private void Search_Click(object sender, RoutedEventArgs e)
{
    string host = Application.Current.Host.Source.Host;
    if (Application.Current.Host.Source.Port != 80)
        host = host + ":" + Application.Current.Host.Source.Port;
    //host = "localhost:3359";
    Uri serviceUri = new Uri("http://"+host+"/SearchJson.aspx?searchfor=" + query.Text);
    WebClient downloader = new WebClient();
    downloader.OpenReadCompleted +=
        new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
    downloader.OpenReadAsync(serviceUri);
}
/// <summary>
/// Receive JSON stream, parse into objects and bind to ListBox
/// http://msdn.microsoft.com/en-us/library/cc197957(VS.95).aspx
/// </summary>
void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    if (e.Error == null)
    {
        using (Stream responseStream = e.Result)
        {
            JsonArray resultStream = (JsonArray)JsonArray.Load(responseStream);
            var results = from result in resultStream
                          select result;
            List<SearchResult> list = new List<SearchResult>();
            foreach (JsonObject r in results)
            {
               var result = new SearchResult
               {
                    name = r["name"] ,description = r["description"]
                    ,url = r["url"],size = r["size"],date = r["date"]
               };
               list.Add(result);
            }
            resultList.ItemsSource = list;
        }
    }
}

 
IP IP Logged
Stranger
Groupie
Groupie


Joined: 21-Sep-2008
Online Status: Offline
Posts: 0
Quote Stranger Replybullet Posted: 30-Apr-2012 at 1:27pm
Sample coding for search engine in ASP.NET ( VB.Net)

Defalault.aspx page contains the following code:

<%@ Page language="c#" Inherits="Search._Default" CodeFile="Default.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>Search</title>
<meta content="Microsoft Visual Studio 7.0" name=GENERATOR>
<meta content=C# name=CODE_LANGUAGE>
<meta content=JavaScript name=vs_defaultClientScript>
<meta content=http://schemas.microsoft.com/intellisense/ie5 name=vs_targetSchema>
</head>
<body>
<form id=Default method=post runat="server">
<p>
<asp:label id=lblQuery runat="server" Width="100px">Query:</asp:label><asp:textbox id=txtQuery accessKey=Q runat="server" Width="300px">
</asp:textbox><asp:RequiredFieldValidator id=reqValQuery runat="server" ErrorMessage="RequiredFieldValidator" Display="Dynamic" ControlToValidate="txtQuery">
You must specify a query.</asp:RequiredFieldValidator>
<br>
<asp:label id=lblQueryType runat="server" Width="100px">Query Type:</asp:label><asp:dropdownlist id=cboQueryType accessKey=T runat="server" Width="300px">
<asp:ListItem Value="All" Selected="True">All Words</asp:ListItem>
<asp:ListItem Value="Any">Any Words</asp:ListItem>
<asp:ListItem Value="Boolean">Boolean Expression</asp:ListItem>
<asp:ListItem Value="Exact">Exact Expression</asp:ListItem>
<asp:ListItem Value="Natural">Natural Language</asp:ListItem>
</asp:dropdownlist><br><asp:label id=lblDirectory runat="server" Width="100px">Directory:</asp:label><asp:dropdownlist id=cboDirectory accessKey=D runat="server" Width="300px">
<asp:ListItem Value="/" Selected="True">Entire Site</asp:ListItem>
<asp:ListItem Value="/Products">Products</asp:ListItem>
<asp:ListItem Value="/Products/App1">Products: App1</asp:ListItem>
<asp:ListItem Value="/Products/App2">Products: App2</asp:ListItem>
<asp:ListItem Value="/Services">Services</asp:ListItem>
<asp:ListItem Value="/Help">Help</asp:ListItem>
</asp:dropdownlist><br><asp:label id=lblSortOrder runat="server" Width="100px">Sort Order:</asp:label><asp:dropdownlist id=cboSortBy accessKey=S runat="server" Width="135px">
<asp:ListItem Value="Rank" Selected="True">Search Rank</asp:ListItem>
<asp:ListItem Value="DocTitle">Document Title</asp:ListItem>
<asp:ListItem Value="Write">Last Modified</asp:ListItem>
</asp:dropdownlist><asp:dropdownlist id=cboSortOrder runat="server" Width="100px">
<asp:ListItem Value="ASC" Selected="True">Ascending</asp:ListItem>
<asp:ListItem Value="DESC">Descending</asp:ListItem>
</asp:dropdownlist><asp:button id=btnSearch runat="server" Text="Search" onclick="btnSearch_Click"></asp:button></p>
<p><asp:label id=lblResultCount runat="server" Font-Italic="True" visible="False">X documents were found:</asp:label></p>
<p><asp:datagrid id=dgResultsGrid runat="server" PageSize="25" AllowPaging="True" AutoGenerateColumns="False" Visible="False" GridLines="None">
<itemstyle horizontalalign="Left" verticalalign="Top">
</ItemStyle>

<headerstyle font-bold="True">
</HeaderStyle>

<columns>
<asp:TemplateColumn HeaderText="Rank">
<headerstyle width="60px">
</HeaderStyle>

<itemtemplate>
<asp:Label id=Label1 runat="server" Text='<%# ((int)DataBinder.Eval(Container, "DataSetIndex")) + 1 %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Document Information">
<itemstyle horizontalalign="Left" verticalalign="Top">
</ItemStyle>

<itemtemplate>
<p><asp:hyperlink runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "VPath")%>'><%# GetTitle(Container.DataItem)%></asp:hyperlink><br>
<asp:label runat="server"><%# GetCharacterization(Container.DataItem)%></asp:label><br>
<i><asp:hyperlink runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "VPath")%>'>http://<%# Request.ServerVariables["SERVER_NAME"]%><%# DataBinder.Eval(Container.DataItem, "VPath")%></asp:hyperlink>
- Last Modified: <asp:label runat="server"><%# DataBinder.Eval(Container.DataItem, "Write")%></asp:label></i></p>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<pagerstyle mode="NumericPages">
</PagerStyle>
</asp:datagrid></p></form>
</body>
</html>

And Default.aspx.cs(Code Behind) File contains the following code:

using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Search
{
/// <summary>
/// Summary description for _Default.
/// </summary>
public partial class _Default : System.Web.UI.Page
{
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbDataAdapter dbAdapter;
protected System.Data.OleDb.OleDbConnection dbConnection;

protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dbAdapter = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.dbConnection = new System.Data.OleDb.OleDbConnection();
this.dgResultsGrid.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgResultsGrid_PageIndexChanged);
//
// dbAdapter
//
this.dbAdapter.SelectCommand = this.oleDbSelectCommand1;
//
// oleDbSelectCommand1
//
this.oleDbSelectCommand1.Connection = this.dbConnection;
//
// dbConnection
//
this.dbConnection.ConnectionString = "Provider=MSIDXS.1;Integrated Security .=\"\";Data Source=Web";

}
#endregion

protected void btnSearch_Click(object sender, System.EventArgs e)
{
this.Search();
}

private void dgResultsGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
// Update the current page index.
this.dgResultsGrid.CurrentPageIndex = e.NewPageIndex;
this.Search();
}

/// <summary>
/// Gets the command string for the search.
/// <seealso cref="Search"/>
/// </summary>
private string Command
{
get
{
// Construct the base query.
string query = String.Format(@"
SELECT Rank, VPath, DocTitle, Filename, Characterization, Write
FROM SCOPE('DEEP TRAVERSAL OF ""{0}""')
WHERE NOT CONTAINS(VPath, '""_vti_"" OR "".config""')",
this.cboDirectory.SelectedItem.Value);

// Conditionally construct the rest of the WHERE clause.
string type = this.cboQueryType.SelectedItem.Value.ToLower();
string fmt = @" AND (CONTAINS('{0}') OR CONTAINS(DocTitle, '{0}'))";

// Get the query string and remove all semi-colons, which should stop
// attempt to run malicious SQL code.
string text = this.txtQuery.Text.Replace(";", "");
if (type == "all" || type == "any" || type == "boolean")
{
string[] words = text.Split(' ');
int len = words.Length;
for (int i=0; i<len; i++)
{
string word = words;
if (type == "boolean")
if (String.Compare(word, "and", true) == 0 ||
String.Compare(word, "or", true) == 0 ||
String.Compare(word, "not", true) == 0 ||
String.Compare(word, "near", true) == 0)
continue;

words = String.Format(@"""{0}""", word);
if (i < len - 1)
{
if (type == "all") words += " AND";
else if (type == "any") words += " OR";
}
}

query += String.Format(fmt, String.Join(" ", words));
}
else if (type == "exact")
{
query += String.Format(fmt, text);
}
else if (type == "natural")
{
query += String.Format(" AND FREETEXT('{0}')", text);
}

// Sort the results.
query += String.Format(" ORDER BY {0} {1}",
this.cboSortBy.SelectedItem.Value, this.cboSortOrder.SelectedItem.Value);

Trace.Write("Query", query);
return query;
}
}

/// <summary>
/// Perform the search.
/// </summary>
private void Search()
{
// Create a new DataSet and fill it.
try
{
this.dbAdapter.SelectCommand.CommandText = Command;
DataSet ds = new DataSet("Results");
this.dbAdapter.Fill(ds);

this.lblResultCount.ForeColor = Color.Black;
int rows = ds.Tables[0].Rows.Count;
this.lblResultCount.Text = String.Format("{0} document{1} found{2}",
rows, rows == 1 ? " was" : "s were", rows == 0 ? "." : ":");

// Bind the resulting DataSet.
this.dgResultsGrid.DataSource = ds;
this.dgResultsGrid.DataBind();

// If all was bound well, display the DataGrid.
this.dgResultsGrid.Visible = (rows > 0);
}
catch (Exception ex)
{
this.lblResultCount.ForeColor = Color.Red;
this.lblResultCount.Text = String.Format("Unable to retreive a list " +
"of documents for the specified query: {0}", ex.Message);

this.dgResultsGrid.Visible = false;
}
finally
{
this.lblResultCount.Visible = true;
}
}

/// <summary>
/// Get the appropriate title from the <see cref="DataGridItem.DataItem"/>
/// bound to the <see cref="DataGrid"/>.
/// </summary>
/// <param name="value">A <see cref="DataGridItem.DataItem"/> for the current record.</param>
/// <returns>Either the "DocTitle" or "Filename" respectively.</returns>
protected object GetTitle(object value)
{
string title = DataBinder.Eval(value, "DocTitle") as string;
if (title != null && title.Length > 0) return title;

return DataBinder.Eval(value, "Filename");
}

/// <summary>
/// Encodes the characterization since some malformed text could cause
/// the web browser to not render the remaining elements.
/// </summary>
/// <param name="value">A <see cref="DataGridItem.DataItem"/> for the current record.</param>
/// <returns>The encoded characterization.</returns>
protected string GetCharacterization(object value)
{
return Server.HtmlEncode(DataBinder.Eval(value, "Characterization") as string);
}
}
}
IP IP Logged

 
Post Reply Post New Topic

Free Programming Courses in JAVA, .Net and PHP (Register Now!)

Java Free Online Course

.Net Free Online Course

PHP Free Online Course


 
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.
© ProjectsQA.com   |   Privacy policy