Solved

How to build a Search Engine?

Posted on 2003-12-11
7
457 Views
Last Modified: 2012-06-27
I have build a simple HTML website to display some information...
Now, I would like to build up a search engine for it...
For example, when user wants to search for "Apple", the search engine will search the word "Apple" through the contents of the webpages that have been built...
Can I use HTML to write the search engine?
If yes, how? Any example?
Thank you!!
0
Comment
Question by:programming02
7 Comments
 
LVL 17

Expert Comment

by:dorward
Comment Utility
No, HTML is a language for describing documents, it can't "do" stuff.

Generally search engines will build an index, store it in a database, and search that. HTML can provide a form to send the query with, and the results can be presented in HTML, but you need something else to do the searching itself.

To put it bluntly, if you have to ask if HTML can do it, then you probably have a lot of learning before you can write your own search engine. So use a prewritten one: http://www.cgi-resources.com/Programs_and_Scripts/Perl/Searching/Searching_Your_Web_Site/
0
 
LVL 9

Expert Comment

by:pepsichris
Comment Utility
You can get a JavaScript version, eg

http://javascript.internet.com/miscellaneous/site-search.html

It's a cheating method, of course, but pretty simple so could be suitable for a small site.  You can also use Google to search a site, eg.

something site:www.yoursite.com

once your site has been registered with them.

The best place to start looking is with whoever you registered your web space with, though.  They'll probably have a mention of search engines somewhere in their help system, which'll point you in the right direction.  If not then search their help system for "cgi", "perl" or "pl" and follow the information path from there.  It may be that your space doesn't have this functionality, in which case you'd have to go without, upgrade, or go with one of the options above.

If you like, then put your web provider's address here, and we'll have a look for you and point you in the right direction.
0
 
LVL 7

Expert Comment

by:gam3r_3xtr3m3
Comment Utility
you could do it on JavaScript but you can search only on your predefined pages and you'd have to put up flags on all your documents. and can be only built on frames. lol

echo dorward
>> To put it bluntly, if you have to ask if HTML can do it, then you probably have a lot of learning before you can write your own search engine.

I don't even have my own made search engine upto now. lol
Use premade ones like the link above.

gam3r
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:pepsichris
Comment Utility
Doesn't need frames - can be adapted pretty easily to appear like a normal Search Engine all in the one page.
0
 
LVL 9

Expert Comment

by:pepsichris
Comment Utility
In fact, even that example doesn't use frames.
0
 

Accepted Solution

by:
brezeeger earned 150 total points
Comment Utility
I recently wrote a search engine script for my website in javascript - here's a reduced version.  I based it off of that same code in pepsichris's link, but it has some distinct differneces.

In the actual search.htm or search.html page: (could be named anything)
<SCRIPT LANGUAGE="JavaScript" src="scripts/searchsite.js"></script>

The following is included in searchsite.js:

var topscore=0;
var numpages=0;      //How many different pages

      description = new Array();      //description of page
      link = new Array();            //url to link of page
      titles = new Array();            //title of page
      fullurl = new Array();            //full url of page
      keywords = new Array();      //keywords for page
      scores = new Array();      //scores for page
      
      description[numpages]=" Brezeegerland Home Page.";
      link[numpages]="index.htm";
      titles[numpages]=" Brezeegerland";
      fullurl[numpages]="http://www.brezeegerland.com/index.htm";
      keywords[numpages]=" brezeegerland download games freeware nintendo space knex k'nex free";
      scores[numpages]=0;
      numpages++;

      description[numpages]=" Get game reviews, tips, hints, etc. on Nintendo 64 games.";
      link[numpages]="nintendo/n64/index.htm";
      titles[numpages]=" Brezeegerland: Nintendo 64";
      fullurl[numpages]="http://www.brezeegerland.com/nintendo/n64/index.htm";
      keywords[numpages]=" nintendo64 n64 SuperSmashBrothers Super Smash Brothers zelda: Ocarina of time 1080 snowboarding waverace 64 waverace64 nintendo 64";
      scores[numpages]=0;
      numpages++;
description[numpages]=" Learn the cheats, tricks, locations for Nintendo 64's Zelda: Ocarina of Time.";
      link[numpages]="nintendo/n64/zelda/index.htm";
      titles[numpages]=" Brezeegerland:  Zelda: Ocarina of Time";
      fullurl[numpages]="http://www.brezeegerland.com/nintendo/n64/zelda/index.htm";
      keywords[numpages]=" Zelda: Ocarina of Time Zelda Ocarina of Time n64 nintendo tricks cheats courses modes hints Bosses Gold Skultua Tokens Heart Bottle Locations n64 nintendo64 nintendo 64";
      scores[numpages]=0;
      numpages++;
      description[numpages]=" Learn the Bosses of Nintendo 64's Zelda: Ocarina of Time and how to beat them.";
      link[numpages]="nintendo/n64/zelda/bosses.htm";
      titles[numpages]=" Brezeegerland:  Zelda: Ocarina of Time Bosses";
      fullurl[numpages]="http://www.brezeegerland.com/nintendo/n64/zelda/bosses.htm";
      keywords[numpages]=" Zelda: Ocarina of Time Zelda Ocarina of Time n64 nintendo Bosses Queen Gohma King Dodongo Barinade Phantom Ganon Volvagia Morpha Dead Hand BongoBongo Koume Kotake Twinrova n64 nintendo64 nintendo 64";
      scores[numpages]=0;
      numpages++;
      description[numpages]=" Learn the locations of heart pieces and bottles in Nintendo 64's Zelda: Ocarina of Time.";
      link[numpages]="nintendo/n64/zelda/locations.htm";
      titles[numpages]=" Brezeegerland:  Zelda: Ocarina of Time Heart and Bottle Locations";
      fullurl[numpages]="http://www.brezeegerland.com/nintendo/n64/zelda/locations.htm";
      keywords[numpages]=" Zelda: Ocarina of Time Zelda Ocarina of Time n64 nintendo64 nintendo 64 nintendo heart piece and bottle locations Lost Woods Hyrule Field Market Square Lon Lon Ranch Kakariko Village Death Mountain Goron City Zora's River Zora's Domain Death Mountain Crater Lake Hylia Ice Cavern Zora's Fountain Gerudo Valley and Fortress Desert Colossus";
      scores[numpages]=0;
      numpages++;

/*      description[numpages]=" DESCRIPTION OF YOUR SITE";
      link[numpages]="somepage.html";
      titles[numpages]=" TITLE HERE";
      fullurl[numpages]="http://www.YOURSITE.com/";
      keywords[numpages]=" YOUR SITE";
      scores[numpages]=0;
      numpages++;*/

//Follow this format    - link can either be the full URL or where the page is in relation to search.html - note the spaces in front
//of each keyword, description, and title - this is so whole words are found and not only parts.


search();
//All previous code is not in any function
//
function search() {
      var txt=location.search;
      temp=txt.split("?");
      txt=temp[1];    //The following if statements deal with invalid data in the URL that the search is based off of, so instructions
                                      //are given so the page is not empty.
      if(!txt)                  //no data, so
      {
            document.write("<HR><H1>Searching Tips</H1><HR></center>Add a &quot;-&quot; in front of the search term to exclude pages containing that term from the list.<BR>If a &quot;-&quot; is used, another search term must be supplied to search with.<BR><BR>Add a &quot;+&quot; in front of the search term if it <i>must</i> have that term!<BR><BR>This search engine now searches for &quot;key phrases&quot; with the use of quotes as well as keywords!<BR><BR><B>Examples:</b> -venus +space +&quot;Solar System&quot; moon</B><HR>Brezeegerland does not recommend using common terms such as: of, the, at, in, a, or, etc. unless within a key phrase.<BR><BR>Ignore the 's in the following examples.<BR>Example #1:' &quot;Battle of the Grontels&quot; ' is recommended.<BR>Example #2:' Battle of the Grontels ' is not recommended as the &quot;of&quot; and &quot;the&quot; are used in many descriptions and will return irrelevant pages.<BR>To see what I mean, try those two searches.<center>");    //There is no data, so this is just html code giving the user instructions
            document.write("<HR>Please Type in What You Want to Search For:<BR>");
            document.write("<form action='search.htm' method='get' name='searchbot' onSubmit='return checksearchbot()'>");
            document.write("<input type='text' size='15' name='keywords'><BR>");
            return 0;
      }
      if(txt.indexOf("keywords=")==-1)            //lack data
      {
            document.write("<HR><H1>Searching Tips</H1><HR></center>Add a &quot;-&quot; in front of the search term to exclude pages containing that term from the list.<BR>If a &quot;-&quot; is used, another search term must be supplied to search with.<BR><BR>Add a &quot;+&quot; in front of the search term if it <i>must</i> have that term!<BR><BR>This search engine now searches for &quot;key phrases&quot; with the use of quotes as well as keywords!<BR><BR><B>Examples:</b> -venus +space +&quot;Solar System&quot; moon</B><HR>Brezeegerland does not recommend using common terms such as: of, the, at, in, a, or, etc. unless within a key phrase.<BR><BR>Ignore the 's in the following examples.<BR>Example #1:' &quot;Battle of the Grontels&quot; ' is recommended.<BR>Example #2:' Battle of the Grontels ' is not recommended as the &quot;of&quot; and &quot;the&quot; are used in many descriptions and will return irrelevant pages.<BR>To see what I mean, try those two searches.<center>");
            document.write("<HR>Please Type in What You Want to Search For:<BR>");
            document.write("<form action='search.htm' method='get' name='searchbot' onSubmit='return checksearchbot()'>");
            document.write("<input type='text' size='15' name='keywords'><BR>");
            return 0;
      }      
      if(txt.indexOf("&view=")==-1 )      //this is just search.htm - nothing else! //lack data
      {
            document.write("<HR><H1>Searching Tips</H1><HR></center>Add a &quot;-&quot; in front of the search term to exclude pages containing that term from the list.<BR>If a &quot;-&quot; is used, another search term must be supplied to search with.<BR><BR>Add a &quot;+&quot; in front of the search term if it <i>must</i> have that term!<BR><BR>This search engine now searches for &quot;key phrases&quot; with the use of quotes as well as keywords!<BR><BR><B>Examples:</b> -venus +space +&quot;Solar System&quot; moon</B><HR>Brezeegerland does not recommend using common terms such as: of, the, at, in, a, or, etc. unless within a key phrase.<BR><BR>Ignore the 's in the following examples.<BR>Example #1:' &quot;Battle of the Grontels&quot; ' is recommended.<BR>Example #2:' Battle of the Grontels ' is not recommended as the &quot;of&quot; and &quot;the&quot; are used in many descriptions and will return irrelevant pages.<BR>To see what I mean, try those two searches.<center>");
            document.write("<HR>Please Type in What You Want to Search For:<BR>");
            document.write("<form action='search.htm' method='get' name='searchbot' onSubmit='return checksearchbot()'>");
            document.write("<input type='text' size='15' name='keywords'><BR>");
            return 0;
      }
      if(txt.indexOf("&page=")==-1)      //this is just search.htm - nothing else!//lack data
      {
            document.write("<HR><H1>Searching Tips</H1><HR></center>Add a &quot;-&quot; in front of the search term to exclude pages containing that term from the list.<BR>If a &quot;-&quot; is used, another search term must be supplied to search with.<BR><BR>Add a &quot;+&quot; in front of the search term if it <i>must</i> have that term!<BR><BR>This search engine now searches for &quot;key phrases&quot; with the use of quotes as well as keywords!<BR><BR><B>Examples:</b> -venus +space +&quot;Solar System&quot; moon</B><HR>Brezeegerland does not recommend using common terms such as: of, the, at, in, a, or, etc. unless within a key phrase.<BR><BR>Ignore the 's in the following examples.<BR>Example #1:' &quot;Battle of the Grontels&quot; ' is recommended.<BR>Example #2:' Battle of the Grontels ' is not recommended as the &quot;of&quot; and &quot;the&quot; are used in many descriptions and will return irrelevant pages.<BR>To see what I mean, try those two searches.<center>");
            document.write("<HR>Please Type in What You Want to Search For:<BR>");
            document.write("<form action='search.htm' method='get' name='searchbot' onSubmit='return checksearchbot()'>");
            document.write("<input type='text' size='15' name='keywords'><BR>");
            return 0;
      }
      txt=replacesrch(txt,"%22%22","%22+%22");       //stick a space between adjacent quotes before everything is split crazily
                                                                                        // and RETURNED to LOWERCASE!
      for(x=0;x>-1;x++)     //infinite loop - I don't know how to do a "do" loop in javascript, so here's my improv.
                {     // this loops remove extra search terms that are just "" and nothing else nothing inside
            if(txt.indexOf("++")==-1 && txt.indexOf("+&")==-1)
                  break;      //break out of the loop, conditions met
            txt=replacesrch(txt,"++","+");      //if someone put too many " "s before/after a word, a blank thing will be left -
                                                                                //get rid of it! a " " from a form turns into a "+" when sent into the url
            txt=replacesrch(txt,"+&","&");      //if someone put too many " "s before/after a word, a blank thing will be left -
                                                                                //get rid of it! We don't want to search for "", because everything would return
      }

      expression = txt.split("&");            //splits value into an array of strings - txt[2] is third string
      values = new Array();            //expression[0]="keywords=hi+%22Zelda%3A+Ocarina+of+Time%22" & exp[1]="view=10" & exp[2]="page=1"
      varnames = new Array();
      for(x=0; x < expression.length;x+=1)
      {
          varnames[x]=expression[x].split("=");
          if(x==0)   //keywords-varnames[0][0]="keywords", varnames[0][1]="hi+%22Zelda%3A+Ocarina+of+Time%22"
          {
              if(varnames[x][1].indexOf("+")==0)      //starts off with spaces! Get rid of them!
              {
            tempsplit=varnames[x][1].split("+");
            var tempaltered="";
            for(y=0;y<tempsplit.length;y++)
            {
                if(tempsplit[y])
                {
                    if(tempaltered=="")
                    {
                  tempaltered=tempaltered+tempsplit[y];
                    }
                   else
                   {
                             tempaltered=tempaltered+"+"+tempsplit[y];
                   }
                }   //end if tempsplit[y]
                      }  // end for y=0 - tempsplit.length

                      varnames[x][1]=tempaltered;

           }  //end varnames[x][1].indexOf("+")==0

         phrase=varnames[x][1].split("%22");   //%22=" phrase[0]="hi+" phrase[1]="Zelda%3A+Ocarina+of+Time" phrase[3]=""
          tempphrase= new Array();
          varnames[0][1]="";      //everything is still in phrase
          
          //The following loop takes text within quotes (%20 in url), and combines it into one keyword, taking into accout "+"s and "-"s
                    for(y=1; y<phrase.length; y+=2)
          {
              tempphrase[((y+1)/2)-1]=replacesrch(phrase[y],"+","%20");      //two quotes make keyword, start at 0
              if(phrase[y-1]!="")
              {
            if(phrase[y-1]!="%2b" && phrase[y-1]!="-") // normal
                    varnames[0][1]=varnames[0][1]+phrase[y-1]+tempphrase[((y+1)/2)-1];  //update varnames with new list
            if(phrase[y-1]=="%2b" || phrase[y-1]=="-") // must/(not) have
                    varnames[0][1]=varnames[0][1]+phrase[y-1]+tempphrase[((y+1)/2)-1];  //update varnames with new list
              }
              else
              {
            if(phrase[y-1]!="%2b" && phrase[y-1]!="-") // normal
                    varnames[0][1]=varnames[0][1]+tempphrase[((y+1)/2)-1];  //update varnames with new list
            if(phrase[y-1]=="%2b" || phrase[y-1]=="-") // must/(not) have
                   varnames[0][1]=varnames[0][1]+phrase[y-1]+tempphrase[((y+1)/2)-1];  //update varnames with new list
              }  // end else
          }   // end for y=1 phrase.length, +=2

          if(phrase.length>2)
              varnames[0][1]=varnames[0][1]+phrase[phrase.length-1];
          if(phrase.length==1)
              varnames[0][1]=phrase[0];      //words are beginnings - not within other words
          
      }  //End if x=0 - expression.length +=1

      values[x]=varnames[x][1].split("+");      //second (1) holds value w/ "+" - first(0) holds var name
      if(x==0)                   //This part had to follow the necessary preceding statement, and the previous x=0 had to go before it
      {
          for(z=0; z<values[0].length; z++)
          {
              if(values[0][z]!="")
                   values[0][z]="%20"+values[0][z];      //put a space in front so it searches at beginning of word - except URL...  
          }    // end of for z=0 values[0].length           ... accounted for

      }   //end if x==0
        }//end of first for loop (x=0; x < expression.length;x+=1)

//All that up there just took the url and split it into the keywords so it will be read correctly by the script below - it's pretty complex
//because (to put it bluntly) you never know how stupid the user can and will be
// the following code is not within any if statements or anything - i reduced the tabbing so it would all fit without overlapping

      view=eval(values[1][0]);         //this is how many results will be shown per page
      page=eval(values[2][0]);        //this is the current page number that is specefied in the url
      if(page<1)
      {
            page=1;      //can't have a page 0
      }
      if(view<1)                   //must view at least one item
      {
            view=10;
      }
      var numdash=0;   //a dash "-" means to exclude pages with that term - this is used in relevancy

        //searchterm is a counter used to make sure all the search terms are used.

      for(searchterm=0; searchterm < values[0].length; searchterm+=1)
      {
            if(values[0][searchterm].indexOf("-")==3)   //the 4th character in the searchterm %20-    0,1,2,3
            {
                  numdash+=1;
            }
      }
      topscore=(10*(values[0].length-numdash)); //when determining the highest score, don't include excluded search terms
      total=0;      //total matches found
      for(searchterm=0; searchterm < values[0].length; searchterm+=1)   //values[0].length is the number of entrys under
      {                                             //values[0] or all the searchterms
            var exclude=0;
            var currentkey="";   //currentkey is a string of the search term in plain english

//everything had been .toLowerCase in the first replacesrch when quotes without spaces between were separated
//we don't put our keywords/descriptions in computer lingo - we put it in english

            values[0][searchterm]=replacesrch(values[0][searchterm],"%2f","\/");      //Display / instead of %22 for user
            values[0][searchterm]=replacesrch(values[0][searchterm],"%5c","\\");      //Display \ instead of %22 for user
            values[0][searchterm]=replacesrch(values[0][searchterm],"%2c",",");            //Remove all Commas
            values[0][searchterm]=replacesrch(values[0][searchterm],"%3d","=");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%7c","|");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%7b","{");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%5b","[");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%5d","]");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%7d","}");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%3a",":");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%3b",";");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%27","'");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%3c","<");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%3e",">");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%2c",",");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%3f","?");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%60","`");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%7e","~");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%21","!");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%40","@");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%23","#");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%24","$");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%25","%");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%5e","^");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%26","&");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%28","(");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%29",")");
            values[0][searchterm]=replacesrch(values[0][searchterm],"%20"," ");


            currentkey=values[0][searchterm];    //txt was lowercase to start off with, so this is too

            if(values[0][searchterm].indexOf("-")==1)
            {
                  exclude=1;              //if found, this must be excluded from the results!
                  tempo=values[0][searchterm].split("-");
                  currentkey=" "+tempo[1];
                  values[0][searchterm]=" -"+currentkey;
            }
            if(values[0][searchterm].indexOf("%2b")==1)
            {
                  exclude=2;               //this term must be found, otherwise disregard this page
                  tempo=values[0][searchterm].split("%2b");
                  currentkey=" "+tempo[1];  //take the second portion into currentkey
                  values[0][searchterm]=" +"+currentkey;   //make the searchterm they see have the +
            }

            for(allcount=0; allcount < numpages; allcount+=1)      //go through all pages
            {
                  var found=0;
                  if (description[allcount].toLowerCase().indexOf(currentkey) > -1 && currentkey != "")
                  {  //is currentkey found in the pages description?  Yes
                        scores[allcount] += 3;  //description - med-high weight
                        if(exclude==1)   //we don't want this page
                        {
                              scores[allcount]=0-topscore; //give the page the lowest score so it cannot
                        }              //rise up past 0
                        
                        found+=1;   //this page was found!
                  }
                  if (keywords[allcount].toLowerCase().indexOf(currentkey) > -1 && currentkey != "")
                  {
                        scores[allcount] += 1;   //only keywords, poor weight
                        if(exclude==1)
                        {
                              scores[allcount]=0-topscore;
                        }
                        found+=1;
                  }
                  if (titles[allcount].toLowerCase().indexOf(currentkey) > -1)
                  {     //title - high weight
                        scores[allcount] += 4;
                        if(exclude==1)
                        {
                              scores[allcount]=0-topscore;
                        }
                        found+=1;
                  }
                  temp=replacesrch(currentkey," ","");
                  if (fullurl[allcount].toLowerCase().indexOf(temp) > -1 && temp != "")
                  {
                        scores[allcount] += 2;  //url - midlow weight
                        if(exclude==1)
                        {
                              scores[allcount]=0-topscore;
                        }
                        found+=1;
                  }
                  
                  if(exclude==2 && found==0) //is the term necessary?  was the term not found?
                  {   //yes and yes
                        scores[allcount]=0-topscore;  //ensure page cannot be displayed
                  }
                  found=0; //reset found
            }  //end of going through all pages for this ONE search term
            exclude=0;
      }   //end the search term for loop, finish or move on to next term

//determine how many results were found
      for(counter=0; counter<numpages; counter+=1)
      {
            if(scores[counter]>0)
            {
                  total+=1;
            }
      }
//user sees: Search for " "Zelda: Ocarina of Time" bosses " produced 4 results.
      document.write("Search for: &quot; "+values[0]+" &quot; produced "+total+" results.&nbsp;&nbsp;</center>");
      if(total>0)  //if results were found
      {
            lastpage=1; //lastpage starts at one,
            for(;lastpage*view+1 <= total; lastpage+=1) //increment until last page is found
            { }
            if(page>lastpage)  //does the page from the url say something higher than the last page?
                  page=lastpage;  //yes, display the last page

            var high=eval(view*page+1);  //based off how many results per page and the page #, what results should be
            var low=eval(view*(page-1));  //shown
            
            if(high>total)  //on last page, with only 3 results out of 10, don't say 11-20, but 11-13.
            {
                  high=total+1;
            }
            


            nextpage=eval(1*page+1);  //multiply by one, otherwise it appends one to the page number
            prepage=eval(page-1);

            document.write("<center>Displaying Results "+(low+1)+" - "+(high-1)+" on Page "+page+" of "+lastpage+".<HR></center>");  //say which results are going to be displayed.
            
            var counter=0;
            for(allsites=0; allsites<total; allsites+=1)  //allsites acts as a counter referring to the total results found
            {   //done this way to reduce time as not to calculate every single page
                  var record=0;
                  var whichone=-1;
                  for(scorecount=0; scorecount<numpages; scorecount+=1)  //find the page with the highest score
                  {
                        if(scores[scorecount] > record)
                        {
                              record = scores[scorecount]; //store the highest score and note which one had
                              whichone=scorecount;  //it
                        }
                  }
                  counter++;  //raise the counter one, this is the pages rank that's being evaluated
                  if(counter>low && counter<high)  //is the rank within the results that are to be shown.
                  {
                        document.write("<a class=genlinks href="+link[whichone]+">"+(allsites+1)+".&nbsp;&nbsp;"+titles[whichone]+"</a> - Relevance: "+ ((scores[whichone]/topscore)*100).toFixed(2) +"%<BR>"+description[whichone]+"<BR><font class=small color=black>"+fullurl[whichone]+"</font><BR><BR>"); //show the result relevance % with
                  }   //two decimals
                  scores[whichone]=0;    //make the displayed score, and look for the next top result, repeat, etc.
            }
            document.write("<center>");
            if(lastpage!=1)  //search engine page navigation
            {
                  document.write("<font color=black>| ");
            }
            if(page!=1)
            {
                  document.write("<a href='search.htm?keywords="+varnames[0][1]+"&view="+view+"&page=1' class=genlinks>First Page</a> | ");
            }
            if(page!=1)
            {
                  document.write("<a href='search.htm?keywords="+varnames[0][1]+"&view="+view+"&page="+prepage+"' class=genlinks>Previous Page</a>");
            }
            if(page!=lastpage && page!=1)
            {
                  document.write(" | ");
            }
            if(nextpage<=lastpage)
            {
                  document.write("<a href='search.htm?keywords="+varnames[0][1]+"&view="+view+"&page="+nextpage+"' class=genlinks>Next Page</a> | ");
            }
            if(page!=lastpage)
            {
                  document.write("<a href='search.htm?keywords="+varnames[0][1]+"&view="+view+"&page="+lastpage+"' class=genlinks>Last Page</a>");
            }
            if(lastpage!=1)
            {
                  document.write(" |</font>");
            }
      }
      if(total==0)  //no results were found
      {
            document.write("<center>Please try your search again using different terms.");
      }

//a search box is displayed under your results - this puts the terms inside of the box in the proper format

      var buildstring="";   //this goes in the text box
      for(x=0;x<values[0].length;x++)  //go through all the search terms in order
      {
            if(values[0][x].indexOf(" ")!=-1)   //is there a space in the term?
            {
                  if(values[0][x].indexOf("+")==1)  //is it required
                  {
                        values[0][x]=replacesrch(values[0][x],"+","");  //take out the +, and put it outside quotes
                        values[0][x]="+&quot;"+values[0][x]+"&quot;";      //space inserted before all values!!
//there is a space in front of each values[0][x] term
                  }
                  else if(values[0][x].indexOf("-")==1) //is it excluded
                  {
                        values[0][x]=replacesrch(values[0][x],"-","");
                        values[0][x]="-&quot;"+values[0][x]+"&quot;";      //space inserted before all values!!
                  }
                  else   //copy it normal
                        values[0][x]="&quot;"+values[0][x]+"&quot;";      //space inserted before all values!!

                  values[0][x]=replacesrch(values[0][x],"&quot; ","&quot;");    //remove all spaces surrounding quotes
                  values[0][x]=replacesrch(values[0][x]," &quot;","&quot;");    //remove all spaces surrounding quotes
                  values[0][x]=replacesrch(values[0][x],"&quot;&quot;","&quot; &quot;");
                                                //add a space between all "" exp - "hi""you" is now "hi" "you"
            }
            if(x==0 && values[0].length!=1) //start out the buildstring
                  buildstring=values[0][x]+" ";
            else if(x==values[0].length-1)  //last one, don't add a space
                  buildstring=buildstring+values[0][x];
            else //middle one, add on
                  buildstring=buildstring+values[0][x]+" ";
            buildstring=replacesrch(buildstring,"+&quot; ","+&quot;");      //remove all spaces surrounding quotes
            buildstring=replacesrch(buildstring,"-&quot; ","-&quot;");      //remove all spaces surrounding quotes
      }

//part of search form
      document.write("<HR>");
      document.write("<form action='search.htm' method='get' name='searchbot' onSubmit='return checksearchbot()'>");
      document.write("<input type='text' size='15' name='keywords' value='"+buildstring+"'><BR>");

}            //End Function

function replacesrch(alltxt,searchtxt,replacetxt)   //takes a text(alltxt), looks for a part(searchtxt) and replaces it(replace(txt)
{
      var temp="";
      var finals="";
      if(alltxt.indexOf(searchtxt)<0)
      {
            return alltxt.toLowerCase(); //not found, return how it was
      }
      if(alltxt.indexOf(searchtxt)>-1)
      {
            temp=alltxt.split(searchtxt);  //split it on the search text
            var replacelngth=temp.length;  //how many was temp split into

            for(counter=0; counter<replacelngth; counter+=1)
            {
                  finals=finals+temp[counter];  //take what you had and add on
                  if(counter!=replacelngth-1)  //not last one
                  {
                        finals=finals+replacetxt; //insert the replaced text inbetween
                  }
            }
      }
      return finals.toLowerCase();  //retrun the final result, lowercase.
}

------------------------------------------------------------------------------------
That's the script.
the .split("Some"); text works as follows:

a="Search Engine Script in JavaScript";
x=a.splt(" ");
then:
x[0]="Search"
x[1]="Engine"
...
x[4]="JavaScript"

Here's a general reference to some of my variables:
http://www.brezeegerland.com/search.htm?keywords=%22Zelda%3A+Ocarina+of+Time%22+bosses&view=10&page=1

expression was an entire expression that will appear in the URL and was found by splitting the "&"'s
values was the value of the expression, so %22Zelda%3A+Ocarina+of+Time%22+bosses, 10, and 1
values[0] dealt with the search terms, values[1] the view, and values[2] the page - that's why there were so many if(x==0) because I was working with values[0][one of search terms].  when values[0] was split, i got values[0][0]=term 1, values[0][1]= term 2, etc.

varnames[0]=keywords, these were used for checking purposes.
varnames[1]=view
varnames[2]=page
 Those struck me as the most confusing to work with.


Here's the HTML Code that goes on your site for the search:

<form action='search.htm' method='get' onSubmit='return checkSearch()' name='searchsite'>
<input type='text' size='15' name='keywords'><BR>
<input type='submit' value='Search Brezeegerland' alt='Search Brezeegerland'>
<INPUT type='hidden' name='view' value='10'>  
<input type='hidden' name='page' value='1'>
</form>

Do not change the names unless you want to change them in the code too.  The values, alts, and sizes may be changed.
Beneath the search engine script, I have on search.htm only:

<input type='submit' value='Search Brezeegerland' alt='Search Brezeegerland'><HR>Show how many Results?<BR>
<input type='radio' name='view' value='1'>1&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT type="radio" name="view" value="10" checked>10&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT type="radio" name="view" value="15">15&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT type="radio" name="view" value="25">25&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT type="radio" name="view" value="50">50&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT type="radio" name="view" value="10000">All<BR>
<input type='hidden' name='page' value='1'>
</form>

The search verification scripts are as follows (not required, but take out the onSubmit tags in form if removed)  There are two scripts because on the search page there are two forms.

function checkSearch() {
var correct = true
if (document.searchsite.keywords.value == "") {correct = false; alert("Please enter search term(s)!")}

return correct;
}

function checksearchbot() {
var correct = true
if (document.searchbot.keywords.value == "") {correct = false; alert("Please enter search term(s)!")}

return correct;
}

If you need any more details, let me know.  I tried to make this as clear as possible.  You can see how it looks on my website at http://www.brezeegerland.com/search.htm or ask any questions if you need more details.  Please note that these were in .js files, so the scripts are unviewable on the site, but seeing how the URL ties in and looking at the source for the forms might help some.  This script will open the results within the page wherever you put the initial:

<SCRIPT LANGUAGE="JavaScript" src="scripts/searchsite.js"></script>

Good Luck and Enjoy!

~Dan
0
 

Expert Comment

by:NeoHacker
Comment Utility
No, you cant do that w/ html.
try learning cgi/perl
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now