Tuesday, August 14, 2007

Create a serch engine with linq

I always amazed by how search engine works and it seem so wonderful that google has created the most amazing search engine to put infomation on our finger tips. Would you like to create a simple search engine? Here you can do it pretty easy with Linq.

The techniques needed in constructing search engine are regular expression, Linq, Generic, C#, sort and ranking algorithm.

Here is the code:


using System;
using System.Collections.Generic;
using
System.Text;
using System.Text.RegularExpressions;
using
System.Query;
namespace search
{
public class Search
{
private
List _SearchRelevance = new
List();
public List
SearchRelevence
{
get
{
return
_SearchRelevance;
}
}
private List _Results =
new List();
public List
Results
{
get
{
return
_Results;
}
}


public Search(string input, string[]
text)
{
for (int i = 0; i < text.Length; i++)
{
SearchRelevance
sr = new SearchRelevance(input,
text[i]);
sr.Calculate();
_SearchRelevance.Add(sr);
}
Sort();
}
private
void Sort()
{
var relevences =
from w in _SearchRelevance
orderby
w.RelevancePoint descending
select w;
foreach (SearchRelevance sri in
relevences)
{
_Results.Add(sri);
}
}

}
public class
SearchRelevance
{
public SearchRelevance(string input, string
text)
{
_OriginalText = text;
_UserInput = input;
}
public
override string ToString()
{
return _RelevancePoint.ToString() +" "+
_OriginalText ;
}
internal void Calculate()
{
string[] splitedinput
= UserInput.Split(new char[] { ' ' });
Dictionary
relevency = new Dictionary();
//initialize the relevency
dic.
for (int i = 0; i < splitedinput.Length;
i++)
{
relevency.Add(splitedinput[i], 0);
}
for (int i = 0; i <
splitedinput.Length; i++)
{
Regex reg = new Regex(splitedinput[i],
RegexOptions.IgnoreCase);
if (reg.IsMatch(OriginalText))
{
int
point;
relevency.TryGetValue(splitedinput[i], out
point);
relevency.Remove(splitedinput[i]);
relevency.Add(splitedinput[i],
++point);
}
}
_Relevancy = relevency;
//sum the relevency
int
rpoint = 0;
foreach (KeyValuePair kv in
relevency)
{
rpoint += kv.Value;
}
_RelevancePoint =
rpoint;
}
private string _UserInput;
public string
UserInput
{
get
{
return _UserInput;
}
}
private string
_OriginalText;
public string OriginalText
{
get
{
return
_OriginalText;
}
}
private int _RelevancePoint;
public int
RelevancePoint
{
get
{
return _RelevancePoint;
}
}
private
Dictionary _Relevancy = new Dictionaryint>();
public Dictionary
Relevancy
{
get
{
return _Relevancy;
}
}
}
public class
Program
{
static void Main(string[] args)
{
string[] sb = new
string[4];
sb[0] = "Relevance cassida shell theory may be seen as an
attempt";
sb[1] = "registered by NSF (Class H1) cassida for use
where";
sb[2] = "Shell Cassida Silicone Fluid is";
sb[3] = "to work out in
detail one of Grice’s central claims";
string input = "nsf shell central h1
sillicone fluid";
Search sr = new Search(input, sb);
SearchRelevance[] res
= sr.Results.ToArray();
}
}
}

12 comments:

Uddipta said...

Dear Owen,

I am evaluating the elearning project you have build. I am very new to ASP.NET....Try to install the VAUL in my system according to your Installation instruction.



But could not able to find the "VUdatabase.sql"...is it possible to provide the database structure....Please let me know.

Waiting for your favourable reply.

Thanks
Regards
Uddipta

Anonymous said...

rich men and beautiful women dating site [url=http://loveepicentre.com/]singles weekends in the summer[/url] christian online dating http://loveepicentre.com/ dating married women

Anonymous said...

diet kazaa kazaa lite [url=http://usadrugstoretoday.com/products/azulfidine.htm]azulfidine[/url] whatsound does a heathy heart make http://usadrugstoretoday.com/discounts.htm warts vaginal canal http://usadrugstoretoday.com/products/rave--energy-and-mind-stimulator-.htm
blood in snot [url=http://usadrugstoretoday.com/products/prazosin.htm]prazosin[/url] ray foster dental [url=http://usadrugstoretoday.com/categories/antiviral.htm]injectable vitamin b12[/url]

Anonymous said...

designer lampwork beads http://topcitystyle.com/black-shorts-and-capri-color2.html iowa dog shoes [url=http://topcitystyle.com/aeronautica-militare-new-brand28.html]wd guitar designer[/url] colonial fashion
http://topcitystyle.com/galliano-long-sleeve-top-for-women-white-item297.html sidi bike shoes [url=http://topcitystyle.com/-dresses-category64.html]recycled fashion[/url]

Anonymous said...

set up mobile email http://www.orderphonetoday.com/?action=products&save_s_prm=1&pr_sort_=priority mobile theme creator [url=http://www.orderphonetoday.com/n009-quad-band-dual-cards-dual-standby--item54.html]ckr mobile electronics[/url] boost mobile phones wholesale

Anonymous said...

movie won the academy award best picture 1976 [url=http://worldmovs.co.cc/full_version-targets/5088database/]Targets[/url] latest dvd movie releases [url=http://full-length-movies.com/dvd-quality-movie-t----lt---tullaan-el--m--/28689database/]T?¤?¤lt?¤ Tullaan El?¤m?¤[/url]
simgirl ending movie [url=http://worldmovs.co.cc/full_version-amirican-pie-2/19961database/]Amirican Pie 2[/url] the champion movie review [url=http://full-length-movies.com/dvd-quality-movie-les-hackers/13558database/]Les Hackers[/url]
movie actors salary [url=http://worldmovs.co.cc/full_version-parchis-la-2-guerra-de-los-ninos/19875database/]Parchis La 2 Guerra De Los Ninos[/url] fredericksburg movie theather [url=http://full-length-movies.com/dvd-quality-movie-the-wicker-man/12212database/]The Wicker Man[/url]
songs to use in a baby movie [url=http://worldmovs.co.cc/full_version-the-cave/12116database/]The Cave[/url] movie auditions [url=http://worldmovs.co.cc/full_version-the-incredible-melting-man/18339database/]The Incredible Melting Man[/url]

Anonymous said...

breast cancer gene mastecomy [url=http://usadrugstoretoday.com/catalogue/j.htm]No prescription online pharmacy[/url] pics of the penis http://usadrugstoretoday.com/#first
extreme fat smash diet [url=http://usadrugstoretoday.com/products/phenergan.htm]phenergan[/url] urgent medical care los angeles [url=http://usadrugstoretoday.com/products/rhinocort.htm ]signs of mental distress and depression [/url] uvj kidney stones
murfreesboro tennessee depression [url=http://usadrugstoretoday.com/products/differin.htm]differin[/url] heart rate and emotions http://usadrugstoretoday.com/products/tulasi.htm
vitamin d difficiency [url=http://usadrugstoretoday.com/products/retin-a-0-05-.htm]Buy Retin-A 0.05% Low prices, side effects, interactions[/url] bubble gum crisis cd covers [url=http://usadrugstoretoday.com/products/avodart.htm ]pics of women having a orgasm [/url] alli weightloss pill

Anonymous said...

designer bathrooms http://luxefashion.us/green-purple-shirts-color35.html valentino fashion group [url=http://luxefashion.us/?action=products&product_id=1902]gilmore girls clothes[/url] colombia clothes
http://luxefashion.us/?action=products&product_id=1942 graphic designers [url=http://luxefashion.us/blue-casual-tops-color32.html]chanel contact tables[/url]

Anonymous said...

miniature tea bagging machine [url=http://usadrugstoretoday.com/categories/anti-pilz.htm]anti pilz[/url] print woman rock bare breast http://usadrugstoretoday.com/products/methotrexate.htm
lvn pharmacy ceu online [url=http://usadrugstoretoday.com/categories/anti-diabetique.htm]anti diabetique[/url] allergic reaction to medical adhesive [url=http://usadrugstoretoday.com/categories/anti-herpes.htm ]record biggest penis [/url] liquid smoke jerky recepies
bladder infection and children [url=http://usadrugstoretoday.com/products/prevacid.htm]prevacid[/url] traditonal chinese medicine glendale az http://usadrugstoretoday.com/products/french-red-wine.htm
sl drug company [url=http://usadrugstoretoday.com/products/vasotec.htm]vasotec[/url] does chi tea have caffeine in it [url=http://usadrugstoretoday.com/products/capoten.htm ]benefit of four chambered heart [/url] tips on how to make your penis thicker and longer

Anonymous said...

pennsyvania gambling casinos http://xwn.in/roulette_internet-gambling-free-casino-roulette minnesoata lottery
[url=http://xwn.in/gambling-online_effects-of-compulsive-gambling]southbridge towers two bedroom apartment lottery[/url] ms word for blackjack [url=http://xwn.in/joker_the-ciara-joker]the ciara joker[/url]
internet casino gambling keno games http://xwn.in/lottery_canadian-cancer-lottery
[url=http://xwn.in/lottery_dvgreencard-lottery-2008results]passed winners of the california lottery in san diego county[/url] download casino game [url=http://xwn.in/jokers_game-jokers]game jokers[/url]
bingo tax laws nj http://xwn.in/online-casinos_map-of-casinos-in-las-vegas most winning lottery numbers [url=http://xwn.in/roulette_roulette-game]roulette game[/url]

Anonymous said...

lexxi tyler movie [url=http://moviestrawberry.com/films/film_the_man_who_knew_too_little/]the man who knew too little[/url] jessica alba nudity movie http://moviestrawberry.com/films/film_sports_illustrated_swimsuit/ primevil movie
the settlers gameplay movie [url=http://moviestrawberry.com/films/film_i_love_you_man/]i love you man[/url] movie review stay http://moviestrawberry.com/films/film_nuts/ transformers movie stream
apocalypto movie free [url=http://moviestrawberry.com/films/film_scrooged/]scrooged[/url] hoodlum movie
movie bone collector [url=http://moviestrawberry.com/films/film_blade_ii/]blade ii[/url] movie pics with someone wearing a wire http://moviestrawberry.com/films/film_pitch_black/ pregnant movie galleries
the palace movie theater [url=http://moviestrawberry.com/films/film_bellboy_donald/]bellboy donald[/url] bible black adult movie online http://moviestrawberry.com/films/film_alien_autopsy/ famous movie actresses

Anonymous said...

free horror movie soundtracks [url=http://moviestrawberry.com/films/film_donalds_tire_trouble/]donalds tire trouble[/url] el paso movie theaters http://moviestrawberry.com/films/film_raising_the_bar/ soccercer movie
xxx movie swap blogs [url=http://moviestrawberry.com/films/film_nobody/]nobody[/url] how to download movie http://moviestrawberry.com/hqmoviesbycountry/country_usa/?page=109 new movie porn
ufo movie clips [url=http://moviestrawberry.com/films/film_jane_austens_mafia/]jane austens mafia[/url] teenburg movie clips
titanic movie music [url=http://moviestrawberry.com/films/film_pale_rider/]pale rider[/url] knocked up movie trailer http://moviestrawberry.com/films/film_wild_things/ dentists movie money
movie theatres showing hairspray the movie 10009 [url=http://moviestrawberry.com/films/film_all_quiet_on_the_western_front/]all quiet on the western front[/url] british horror movie naked dancing scene http://moviestrawberry.com/films/film_spongebob_squarepants/ stardust full movie