Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Engine

Status
Not open for further replies.

lck092580

Programmer
Jun 19, 2002
440
CA
Anyhow know any good sites with tutorials for building a search feature on a website? Thanks.

T
 
Hi there,
Here is some very basic code for a simplistic search engine, i dont know of any tutorials.

<html><HEAD>
<meta name=&quot;AUTHOR&quot; content=&quot;GUJUM0deL (ketan mehta)&quot;>
<meta name=&quot;description&quot; content=&quot;search engine using JS&quot;>

<SCRIPT LANGUAGE=&quot;_JavaScript&quot;>
/*INSTRUCTIONS:
Ok, this is the setup and its quite simple to figure out if you know JS or any other type
of scripting language. First off in the ARRAYs you write in the HTML page, the path of the
site (which can be left blank), a description to what the link is, the keywords entered for
the search criteria, and finaly the description to what the link is about. (IF CONFUSED JUST RUN THE SCRIPT THE WAY IT IS FIRST AND SEE THE RESULTS! OR, JUST EMAIL ME BACK AND I'LL EXPLAIN)
*/
var item = new Array();
Km=0; item[Km]=new Array(&quot;hotmail.com&quot;,&quot; any, free, email, e-mail&quot;,&quot;FREE E-Mails!!&quot;);
Km++; item[Km]=new Array(&quot;Yahoo.com&quot;,&quot; any, yahoo&quot;,&quot;Wanna Yahoo!&quot;);
Km++; item[Km]=new Array(&quot;tvguide.com&quot;,&quot; any, tv, guide, shows&quot;,&quot;TV Guide&quot;);

//YOU CAN EDIT WHAT THE NEW WINDOW WILL LOOK LIKE, SUCH AS TEXT COLOR, BACKGROUND COLOR, LINK COLOR.
pageview=&quot;<html><head><title>Search Results</title></head><body bgcolor='black' text='white' link='#bda940' vlink='#cccccc'><left><table border=0 width=200>&quot;;

function search(formfld) {
//YOU CAN EDIT THE WINDOW PROPERTIES ONLY, NOTHING ELSE.
windw = window.open(&quot;&quot;,&quot;&quot;,&quot;toolbar=no,location=no,directories=no,status=no,menubar=no,height=215,width=250, scrollbars=yes,resizable=no&quot;);
//DO NOT EDIT FROM HERE!!
windw.document.write(pageview);
txt = formfld.searchvalue.value.split(&quot; &quot;);
findingval = new Array(); total=0;
for (i = 0; i < item.length; i++) {
findingval = 0; order = new Array(0, 4, 2, 3);
for (j = 0; j < order.length; j++)
for (k = 0; k < txt.length; k++)
if (item[order[j]].indexOf(txt[k].toLowerCase()) > -1 && txt[k] != &quot;&quot;)
findingval += (j+1);
}
for (i = 0; i < findingval.length; i++) {
n = 0; w = -1;
for (j = 0;j < findingval.length; j++)
if (findingval[j] > n) { n = findingval[j]; w = j; };
if (w > -1) total += show(w, windw, n);
findingval[w] = 0;
}
windw.document.write(&quot;</table><br>Total found: &quot;+total+&quot;<br>&quot;);
windw.document.write(&quot;<INPUT onfiltered='blur();' type='button' style='background-color:#004080; border-color:#004080; color:#FFFFFF;' value='Close' onfiltered='self.close()'&quot;);
//PLEASE LEAVE THIS PORTION HERE. IT IS MY AUTHOR'S TAG.
windw.document.write(&quot;<br><br><font size='1'><center>© Heffernan's Search Engine. All right reserved. </center></font> </body></html>&quot;);

}
/* This function is important. Here you actualy show what the search result window display.
DO NOT EDIT HERE. ONLY EDIT IF YOU KNOW WHAT YOU ARE DOING.
*/
function show(which,dniw,num) {
link = item[which][1] + item[which][0];
//If you want to you can change the 'target' to anything.
line = &quot;<tr><td><a href=&quot;+link+&quot; target='_new'>&quot;+item[which][2]+&quot;</a><br>&quot;;
line += item[which][4] + &quot;<br><br></td></tr>&quot;;
/* By adding this tag: <br>&quot;+link+&quot; between the: + &quot; on the above line you will display the
link in text well.
*/
dniw.document.write(line);
return true;
}
</script>
</HEAD>

<BODY bgcolor=&quot;#000000&quot; text=&quot;bda94c&quot;>
<center>
<!--- leave the 'form method' line the way it is. ALL OF IT -->
<form method=get action=&quot;_javascript:void(0)&quot; onfiltered=&quot;search(this); return false;&quot;>
<tr><td>
<p><b><font color=&quot;ff0000&quot;>to see it in action type in:</font> </b></p>
<p>'all' to see all the search results. <i>Without the single quotes.</i><br>
'hotmail' to see the search result for that key word.<br>
You can also enter part of a word and the result will bring back the
entry. <i>Try entering: 'ail' and see what happens.</i><br>
</p>
<p> This script also has the <b>.toLowerCase()</b> so that it convert
all the search words to lowercase. In other words, this script is NOT
case sensitive!! So if you enter in HOTMAIL or hotMAil or hotMAIl,
you still get the right result.</p>
<p><i> Just makes sure that all the keywords are in lowercase in the Array
sction at the top...</i></p>
<p>NS and IE display it differently, <i>BUT IT WORKS IN BOTH BROWSERS!!
</i>For a cooler effect use CSS for the textbox and buttons, like
I did. ( Just a note that NS4 will not display the CSS tags)</p>
<p><b>PLEASE LEAVE MY AUTHORSHIP IN THE SCRIPT THANKS.</b></p>
<p>
<input type=text name=searchvalue value=&quot;&quot;>
<input onfiltered='blur();' type=submit value=&quot;Search&quot; style=&quot;background-color:#004080; border-color:#004080; color:#FFFFFF;&quot; name=&quot;Input&quot;>
</p>
</td>
</tr>
</form>
</center>
</body>
</html>




Hope this helps!!!
 
Bravogolf, your code dropped subscript variables of the form [ignore][/ignore].

lck092580, my advice to you would be to go immediately to and learn all you can.

Cheers,
[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
But I what I want is a search feature for our webpage that searches through our website and not the internet.
 
To put a search facility in your site you have have two basic approaches...

1) Get a third party to index your site and host a search facility for it. You have to pay for this service, either in cash or by letting the third party put adverts among your results. The URLs posted by Edward and Babel are examples of this, is another popular one. The advantage of doing it this way is that it's quick and easy, the disadvantage is that you have less control.

2) Use a program hosted on your site to do the searching. You can pay pots of money for such programs from commercial suppliers (such as Google), or you can get cheaper (or free!) shareware solutions. A good place to start looking for the latter is
If you're looking for guidance on building your own, I suggest you download a few free scripts and dissect them in your favourite editor. That's what I did when building mine! -- Chris Hunt
Extra Connections Ltd
 
Chris is basically correct, except...

The link I posted is just an example of how Google does it. Obviously, it's free to submit your site to Google and you can tailor a query (from your website!) to Google to return only results in your domain. This is practically the same thing as, oh, a custom searcher on your site.

One of the options on that page is setting up a free service to search your site. I recommend always investigating things that are
* free
* used often by lots of people
* easy to implement
* effective as hell

For a chuckle, take a peek at

Cheers,
[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Hey that's my code Bravogolf posted at the top... [smile], did it help you lck092580?? Forget the Nobel Peace prize, I just want to take over the world!! [hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top