...

View Full Version : JS Search



winlineau
07-06-2002, 02:31 AM
I am modifing a search engine made in JS.

This is my current code:

<HTML>
<HEAD>
<TITLE> Search Engine </TITLE>
<script>

if (location.search){
var vals=location.search.substr(1).split("&");
for (var i in vals) {
vals[i] = vals[i].replace(/\+/g, " ").split("=");
vals[i][0] = unescape(vals[i][0]);
vals[i][1] = unescape(vals[i][1]);
if (vals[i][0]=="keywords"){
keyword = vals[i][1] = unescape(vals[i][1]);
alert(keyword)
}
}
}

<!--// This Script was created by Satadip Dutta.
// Email: sat_dutta@post1.com / satadipd@inf.com
// URL:http://dutta.home.ml.org
// EDITED FOR WINLINE BY: Tim Groeneveld
// Version 1.1-IExp
// Please honor my hard work, if you use a variant of this in your page,
// then please email me :) and keep these comments in the Script.
// This code is Copyright (c) 1997 Satadip Dutta
// all rights reserved.
// License is granted to user to reuse this code on their own Web site
// if, and only if, this entire copyright notice is included. The Web Site
// containing this script must be a not-for-profit ( non-commercial ) web site.
// Exclusive written permission must be obtained before using this version of the search engine
//-->

<!-- End copyright - This must be retained and posted as is to use this script -->

title = new Object();
desc = new Object();
links= new Object();
matched= new Object();
keywords= new Object();
found= new Object();
var temp=0;
// actual location or the item to be searched
// description of he location
// actual link
// percentage match found
// keywords as parsed from the input
// # of titles present in the database
title[0]=15
//no of keywords after parsing
keywords[0]=0
//no of matches found.
found[0]=0

<!-- Begin List of Searchable Items -->

<!--put the list of the links and descriptions here!!-->

title[1]="Yahoo!"
desc[1]="Viset Yahoo. The most popular 'mix' Page"
links[1]="http://www.yahoo.com"
matched[1]=0

title[2]="Microsoft"
desc[2]="Visit Microsoft, The makers of WINDOWS and Office"
links[2]="http://www.microsoft.com"
matched[2]=0

title[3]="Javascriptkit"
desc[3]="Visit WINLINE's 'javaward's winner 2 Years running"
links[3]="http://javascriptkit.com"
matched[3]=0

title[4]="event handler onClick onLoad onMouseover onMouseout onUnload"
desc[4]="Understanding Event Handlers in JavaScript"
links[4]="http://www.javascriptkit.com/event.htm"
matched[4]=0


title[5]="MP3.Com"
desc[5]="Download free MP3's from popular artists"
links[5]="http://www.mp3.com"
matched[5]=0

title[6]="Making Movies"
desc[6]="American Alien's Resource for Young Filmmakers"
links[6]="http://www.americanalien.net/MakingMovies.html"
matched[6]=0

title[7]="popupsponsor.com/"
desc[7]="Get a Pop-Up Sponser"
links[7]="http://www.popupsponsor.com/"
matched[7]=0

title[8]="Andrews Lyrics"
desc[8]="The best place for finding lyrics"
links[8]="http://www.geocities.com/andrews_lyrics/"
matched[8]=0

title[9]="Welcome to 2mogi.com webmail"
desc[9]="Visit to get free Mail!"
links[9]="http://2mogi.com"
matched[9]=0

title[10]="Yahoo! Mail"
desc[10]="Yahoo's Free WebMail Service"
links[10]="http://mail.yahoo.com"
matched[10]=0

title[11]="hotpop: pop3"
desc[11]="Easy setup and works ok - and that is more than you can expect with most free email services."
links[11]="http://www.HotPOP.com"
matched[11]=0

title[12]="free downloads center"
desc[12]="offers antivirus, business, educational, fax, and much more"
links[12]="http://www.freedownloadscenter.com"
matched[12]=0

title[13]="CRCA Christian Reformed Churches of Australia"
desc[13]="Visit for sermons, webmail and more!"
links[13]="http://www.crca.org.au/"
matched[13]=0

title[14]="Yahoo!"
desc[14]="Viset Yahoo. The most popular 'mix' Page"
links[14]="http://www.yahoo.com"
matched[14]=0

title[15]="Yahoo!"
desc[15]="Viset Yahoo. The most popular 'mix' Page"
links[15]="http://www.yahoo.com"
matched[15]=0

<!-- End list of Searchable items -->

function search(){
var skeyword=document.searchengine.keywords.value.toLowerCase();
var check=1;
var pos=0;
var i=0;
var j=0;
var itemp=0;
var config='';

while (true)
{
if (skeyword.indexOf("+") == -1 )
{
keywords[check]=skeyword;
break;
}
pos=skeyword.indexOf("+");
if (skeyword !="+")
{
keywords[check]=skeyword.substring(0,pos);
check++;
}
else
{
check--;
break;
}
skeyword=skeyword.substring(pos+1, skeyword.length);
if (skeyword.length ==0)
{
check--;
break;
}

}
// the keywords have been put in keywords object.
keywords[0]=check;

// matching and storing the matches in matched
for ( i=1; i<=keywords[0];i++)
{
for (j=1;j<=title[0];j++)
{
if (title[j].toLowerCase().indexOf(keywords[i]) > -1 )
{
matched[j]++;
}
}
}
// putting all the indexes of the matched records in found

for (i=1;i<=title[0];i++)
{
if (matched[i] > 0 )
{
found[0]++;
// increment the found
found[found[0]]=i;

}
}



for (i=1;i<=found[0]-1;i++)
{
for(j=i+1;j<=found[0];j++)
{
if ( matched[found[i]]< matched[found[j]] )
{
temp= found[j];
found[j]=found[i];
found[i]=temp;
}
}
}

// end of sort

output = self;
output.document.write('<html>');
output.document.write('<head>');
output.document.write('<script>');
output.document.write('window.onerror=new Function("return true")');
output.document.write('<\/script>');
output.document.write('<title> Search Results </title>');
output.document.write('</head>');
output.document.write('<BODY bgcolor=#ffffff text=#000000 link=#990099 vlink =#339966 >');
output.document.write('<center> <h1> Search Results </h1></center>');
output.document.write('<hr>');
output.document.write(' The Keyword(s) you searched :: '.big() )
for (i=1; i<=keywords[0]; i++)
{
output.document.write( keywords[i].bold() +" ");
}
output.document.write('<br>');

if (found[0]==0)
{
//alert(found[0]);
output.document.write('<hr>');
output.document.write("<b>No matches resulted in this search </b> <br>");
}
else
{
// data has been found
output.document.write(" <hr> <b> The Results of the search are : </b> ");
output.document.write( found[0] +" Entries found ".italics());
output.document.write("<table border=1 width=100%>");
for (i=1; i<=found[0];i++)
{
output.document.write("<tr><td valign=top bgcolor=#9999ff>");
output.document.write("<h3>" +i +"</h3>");
output.document.write("<td valign=top>");
itemp=found[i];
output.document.write(desc[itemp].bold() +"<br>" +
links[itemp].link(links[itemp])+"<br>");
temp= (matched[itemp]/keywords[0])*100
output.document.write("<i> Matched with keywords :: " +temp+" % </i>" );
matched[itemp]=0
}
found[0]=0;
output.document.write("</table>");
}


document.write("<form name='searchengine' onSubmit='search()'>");
document.write("Keywords: <input type = text name ='keywords' value='"+skeyword+"' maxlength=40>");
document.write("<input type = submit name='go' Value='SEARCH' onClick='search()'>");
document.write("<br><hr></form>");
document.write ("</body></html>");
output.document.close();
}
</script>

</HEAD>
<BODY BGCOLOR=white TEXT=black LINK=#0000FF VLINK=#6600AA ALINK=#6600AA>

<center>
<H1>Search Engine</H1>
</center>


<form name="searchengine" onSubmit="search()">
<center>
Keywords:
<input type = text name ="keywords" value="" maxlength=40>
<input type = submit name="go" Value="SEARCH" onClick="search()">
<br>
<hr>
</center>
</form>

</BODY>
</HTML>






I need to make it so when you make a search, you can re search after. Thank you

E.G. http://google.yahoo.com/bin/query?p=%22CodingForums.com%22&hc=0&hs=0

mordred
07-06-2002, 04:28 PM
You can't modify this script to work exactly as a serverside search engine, it only goes through the title object and searches upon each of its entries according to the keywords you entered in the form.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum