Click here to Skip to main content
11,932,857 members (56,888 online)
Click here to Skip to main content
Add your own
alternative version


206 bookmarked

Google Suggest like Dictionary

, 27 Dec 2004
Rate this:
Please Sign up or sign in to vote.
An implementation of Google suggest using remote scripting.



This is an implementation of Google Suggest like dictionary in ASP.NET.


After seeing Google Suggest, I was amazed and wanted to know how it worked. This project is just an experiment using the same technique that Google uses.

Using the code

The ZIP file consists of two files. One is an HTML file that uses the XMLHttpRequest object to make requests and get back data. The other one is a server script implemented in ASP.NET that connects to a SQL Server database. If you wish to implement a similar interface, just use the HTML functions provided. A proof of concept website could be accessed here.

How does it work?

The architecture could be explained as outlined below:

  • Concept
  • The database
  • ASP.NET page
  • XMLHttpRequest object in the HTML page
  • Observations


As you type a word in the textbox, a JavaScript event fires an HTTP GET request to the ASPX page. The response from the ASPX page is simply displayed in a div tag under the textbox. The page is not refreshed/reloaded for every keystroke as everything is done by the JavaScript in the page. The main JavaScript object that allows us to do this is XMLHttpRequest. You could read about it from Apple's developer site here. This is supported by IE 5.0 +, Mozilla 1.0 + and Apple's own Safari 1.2 +.


The database contains just one table. The data comes from a freely available online dictionary (a public domain English word list dictionary, based on the public domain portion of "The Project Gutenberg Etext of Webster's Unabridged Dictionary" which is in turn based on the 1913 US Webster's Unabridged Dictionary. You could download it from here). The table is called WordList:

Word varchar(255)
Type varchar (10)
Meaning text

I created an index on "Word" column for speed. There are a total of 182696 words in the database.

ASP.NET page

The ASP.NET page is pretty straight forward. Gets the top 10 matching rows from the database and spits it out. Below is the code I am using (although SqlDataReader might be more appropriate):

<%@Page Language="C#"%>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>
<%@Import Namespace="System.Configuration"%>

<script runat="server">

    public void Page_Load(object sender,EventArgs args)
        string keyword=Request["k"];
        if(keyword!=null  && keyword.Trim()!="")
            string sql="select top 10* from WordList where" + 
                   " word like '"+keyword.Trim().Replace("'","''")+"%'";
            SqlConnection conn=new 
            DataTable dt=new DataTable();
            SqlCommand command=new SqlCommand(sql,conn);
            SqlDataAdapter adapter=new SqlDataAdapter(command);

            foreach(DataRow row in dt.Rows)
                string meaning=row["Meaning"].ToString();
                Response.Write("<strong>"+row["Word"].ToString()+"</strong> <i>");

XMLHttpRequest object in the HTML page

var req;

function Initialize()
        req=new ActiveXObject("Msxml2.XMLHTTP");
            req=new ActiveXObject("Microsoft.XMLHTTP");

    if(!req&&typeof XMLHttpRequest!="undefined")
        req=new XMLHttpRequest();


function SendQuery(key)
    var url=""+key;

        req.onreadystatechange = Process;"GET", url, true);



function Process()
    if (req.readyState == 4)
        // only if "OK"
            if (req.status == 200)
                    document.getElementById("autocomplete").innerHTML = 
                    "There was a problem retrieving data:<br>" 
                    + req.statusText;

function ShowDiv(divid)
   if (document.layers) document.layers[divid].visibility="show";
   else document.getElementById(divid).style.visibility="visible";

function HideDiv(divid)
   if (document.layers) document.layers[divid].visibility="hide";
   else document.getElementById(divid).style.visibility="hidden";

function BodyLoad()

    <body onload="BodyLoad();">
        <form name="form1">
        <input name="keyword" onKeyUp="SendQuery(this.value)" 
          style="WIDTH:500px" autocomplete="off">
            <div align="left" class="box" id="autocomplete" 


The KeyUp event on the textbox triggers the SendQuery method. Note that we are disabling the auto-complete feature so it does not overlap with our div tag. The Initialize method creates the XMLHttpRequest object. In Mozilla and Safari, you could simply do this by using:

req=new XMLHttpRequest();

In IE, you could create the object based on the user's installation of MSXML libraries. The Process method acts as an event handler and displays the response text once the response is complete from the web server.


  • Google Suggest is probably running by having all the suggestion words in main memory and a custom web server that does nothing else (although this concept is very easy to implement in C#).
  • Roundtrips from the web server should be minimal (2K max) as it might eat up bandwidth pretty fast.


  • December 24, 2004
    • Initial version 1.0.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Gavi Narra
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
Farhan Ghumra11-Jul-12 22:23
memberFarhan Ghumra11-Jul-12 22:23 
Generalword dictionary Pin
mohit118-Sep-10 19:16
membermohit118-Sep-10 19:16 
GeneralSo simple yet so powerful,,, Pin
sevenlogix22-May-09 6:23
membersevenlogix22-May-09 6:23 
GeneralGoogle Suggest like Dictionary Pin
luckyroy3-May-09 21:38
memberluckyroy3-May-09 21:38 
GeneralQuery Modification Pin
Member 450581216-Dec-08 13:29
memberMember 450581216-Dec-08 13:29 
GeneralProblem in "document.getElementById("autocomplete").innerHTML=req.responseText;" Pin
Member #316566510-Jan-07 4:01
memberMember #316566510-Jan-07 4:01 
Hello Friends,
I download this project, and do some modifiations as per my requirement.
i changed only

var url=""+key;
var url=document.URL;

and in code behind i written my code to get the values..
i get the values from database, but it will not showning the result in page, it will throughs "Unknown runtime error" on the line..
when write the stmt before this as


then it will gives the actual result which is send from codebehind.
I am not able to findout the actual problem, why this code is not working..
why it will gives the error on


Please tell me as early as possible


Questionselectable values in div tag Pin
utsi12-Oct-06 3:04
memberutsi12-Oct-06 3:04 
Questionget it working with access database??? Pin
wahabm8-Aug-06 1:13
memberwahabm8-Aug-06 1:13 
Questionhow to display in listbox... Pin
kamalika_kk10-Jul-06 3:36
memberkamalika_kk10-Jul-06 3:36 
GeneralPlease I need the database of this program Pin
AMRSINAN13-Jun-06 0:38
memberAMRSINAN13-Jun-06 0:38 
Generaldatabase link died Pin
masterbkhn27-Apr-06 8:53
membermasterbkhn27-Apr-06 8:53 
GeneralRe: database link died Pin
piglet0123-Sep-07 17:09
memberpiglet0123-Sep-07 17:09 
GeneralAJAX creating problem on Local Site Pin
eshna16-Mar-06 21:41
membereshna16-Mar-06 21:41 
GeneralRe: AJAX creating problem on Local Site Pin
tejas_chonkar23-Apr-06 23:21
membertejas_chonkar23-Apr-06 23:21 
GeneralW2003K web server permissions Pin
LeighG12-Feb-06 2:28
memberLeighG12-Feb-06 2:28 
NewsConverted code in Pin
suri197130-Jan-06 22:25
membersuri197130-Jan-06 22:25 
NewsCode in Pin
suri197130-Jan-06 21:59
membersuri197130-Jan-06 21:59 
GeneralSorting a SubString Search Pin
Fabito24-Nov-05 3:14
memberFabito24-Nov-05 3:14 
QuestionCode behind does not work? Pin
peterver16-Nov-05 10:40
memberpeterver16-Nov-05 10:40 
GeneralStatus 12029 when running code from client Pin
Wegas29-Sep-05 10:24
sussWegas29-Sep-05 10:24 
GeneralRe: Status 12029 when running code from client Pin
MitchV14-Feb-06 10:22
memberMitchV14-Feb-06 10:22 
Generalproblem implementing in Pin
saggimanoj23-Sep-05 1:41
membersaggimanoj23-Sep-05 1:41 
GeneralIts really nice article..great job Pin
Surendra Sambana4-Sep-05 20:16
memberSurendra Sambana4-Sep-05 20:16 
QuestionHow to Change Source From Your Site Pin
eebb224421-Aug-05 23:01
membereebb224421-Aug-05 23:01 
GeneralMining Google Web Services: Building Applications with the Google API Pin
Anonymous21-Aug-05 21:48
sussAnonymous21-Aug-05 21:48 
GeneralGoogle Hacks: 100 Industrial-Strength Tips &amp; Tools Pin
Anonymous14-Aug-05 3:53
sussAnonymous14-Aug-05 3:53 
Generalnot able to host the page Pin
iomca4u6-Aug-05 19:14
memberiomca4u6-Aug-05 19:14 
QuestionSelecting words using the arrow keys? Pin
Anonymous11-Jul-05 4:36
sussAnonymous11-Jul-05 4:36 
vcdflow14-Jun-05 16:22
membervcdflow14-Jun-05 16:22 
wahabm8-Aug-06 1:11
memberwahabm8-Aug-06 1:11 
GeneralThe dictionary to use Pin
smiling4ever6-Jun-05 5:26
membersmiling4ever6-Jun-05 5:26 
GeneralDictionary for this article Pin
smiling4ever6-Jun-05 2:32
membersmiling4ever6-Jun-05 2:32 
Generalproblem to retrieve data (please help me) Pin
bibipopopopo28-Apr-05 13:23
memberbibipopopopo28-Apr-05 13:23 sample Pin
bibipopopopo28-Apr-05 12:18
memberbibipopopopo28-Apr-05 12:18 
GeneralNice Job Pin
Alamier7919-Apr-05 4:47
memberAlamier7919-Apr-05 4:47 
Generalgreat can do more! Pin
POMARC14-Apr-05 22:52
memberPOMARC14-Apr-05 22:52 
GeneralRe: great can do more! Pin
LimeyRedneck3-Aug-05 7:41
memberLimeyRedneck3-Aug-05 7:41 
GeneralSame as google sugges Pin
ccheee15-Feb-05 14:44
memberccheee15-Feb-05 14:44 
GeneralIs it possible to use dll instead of aspx page in URL Pin
karasi11-Feb-05 2:11
memberkarasi11-Feb-05 2:11 
GeneralRe: Is it possible to use dll instead of aspx page in URL Pin
Wiebe Tijsma27-Jun-05 1:12
memberWiebe Tijsma27-Jun-05 1:12 
GeneralRe: Is it possible to use dll instead of aspx page in URL Pin
Ashwinks15-Dec-05 13:34
memberAshwinks15-Dec-05 13:34 
GeneralExcellent article Pin
Omri Spector31-Jan-05 12:34
sussOmri Spector31-Jan-05 12:34 
GeneralRe: Excellent article Pin
Gavi Narra7-Feb-05 15:24
memberGavi Narra7-Feb-05 15:24 
QuestionHow about the performance? Pin
Hardy31-Jan-05 6:44
memberHardy31-Jan-05 6:44 
AnswerRe: How about the performance? Pin
Gavi Narra7-Feb-05 15:24
memberGavi Narra7-Feb-05 15:24 
GeneralRe: How about the performance? Pin
Wiebe Tijsma27-Jun-05 0:54
memberWiebe Tijsma27-Jun-05 0:54 
GeneralRe: How about the performance? Pin
Wiebe Tijsma27-Jun-05 1:09
memberWiebe Tijsma27-Jun-05 1:09 
AnswerRe: How about the performance? Pin
psi_u14-Aug-05 6:55
memberpsi_u14-Aug-05 6:55 
AnswerRe: How about the performance? Pin
Spiff Dog20-Feb-06 15:58
memberSpiff Dog20-Feb-06 15:58 
Generalaspx page returns blanks Pin
libajgl13-Jan-05 11:27
memberlibajgl13-Jan-05 11:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 27 Dec 2004
Article Copyright 2004 by Gavi Narra
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid