SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Nov 2000
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Search Engine

    Hi all, I'm trying to get a script to work with frames but not having any luck, can you help?

    The script is for a client side search engine and it works fine in the same page but this is not good use of it so I have tried changing the properties to what I thought would work but not the case.

    Here's the script

    <SCRIPT>
    title = new Object();
    desc = new Object();
    links= new Object();
    matched= new Object();
    keywords= new Object();
    found= new Object();
    var temp=0;

    title[0]=5

    keywords[0]=0

    found[0]=0

    title[1]="User Profile ( NT ) SMS Delivery Sequence"
    desc[1]="SMS Delivery Sequence, set up instructions"
    links[1]=""
    matched[1]=0

    title[2]="Knowledge Search & Data Management"
    desc[2]="Meeting Questions for David Poulton"
    links[2]="page2.htm"
    matched[2]=0

    title[3]="Cahoot call standards"
    desc[3]="Information on the call standards"
    links[3]="page3.htm"
    matched[3]=0

    title[4]="Publishing,Daily Bulletin, Archive, Publish"
    desc[4]="This is the procedure for publishing to the daily bulletin"
    links[4]="page4.htm"
    matched[4]=0


    title[5]="To discuss with Team Leaders"
    desc[5]="discussion with team leaders regarding communications"
    links[5]="page5.htm"
    matched[5]=0

    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;
    }

    }

    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]++;
    }
    }
    }

    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;
    }
    }
    }

    output = self; >I have tried html tags like _blank and the name of the frame mainFrame
    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('<h1> Search Results </h1>');
    output.document.write('<hr>');
    output.document.write(' You searched for: '.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=#9999ee>");
    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>");
    }

    output.document.write ("<hr>");
    //output.document.write ("<form><center>");
    //output.document.write ("<input type='button' value='Start Another Search' onClick = 'self.close()'");
    //output.document.write ("<center></form>");

    output.document.write ("</body></html>");
    output.document.close();
    }
    </SCRIPT>

    thanks for your help

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am SO afraid to ask what you mean by "client side search engine"!!!

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Addict
    Join Date
    Nov 2000
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good question It's called client side because the javascript is in the html and not on the server.

    what it does is search the contents of the script for keywords,

    title[1]="keyword keyword keyword key word"
    desc[1]="description goes here"
    links[1]="page with the keywords.html"
    matched[1]=0

    When it finds the keywords it displays them with the description and a link to the page. (it doesn't craw the pages)

    It works quite well although a little labourious to input the code as long as it's a small site.

    I am using it for an Intranet site that is not hosted on a web server so I don't have many options open to me, unless I want to spend a small fortune! (which is not an option)

    Having the search box on every page is to much work so having it in a separate frame would be the best way to use it, if it will work.

    This must be the property I need to change

    output = self; >
    output.document.write('<html>');
    output.document.write('<head>'); etc....

    but I don't know what I can change it too?

    Any help would be much appriciated!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •