overview
12-26-2007, 04:28 PM
Hello.
I have been working on a Javascript powered search engine for a set of browser based user guides. I can't use any server-side languages as it will all be accessed from a network drive, which as been a real pain as I would rather have just made a php search engine, but whatever...
I have a working JavaScript search function, currently the results are displayed in the same window/frame as the search form.
All i need is to be able to target the results to a different frame. For example, I'll keep the search form in a top frame, and some information in the bottom frame. Submitting the search form will display the results in the bottom frame. Its giving me a headache, I'm sure it is remarkably simple...
The code:
title = new Object();
desc = new Object();
links= new Object();
matched= new Object();
keywords= new Object();
found= new Object();
var temp=0;
// # of titles present in the database
title[0]=1
//no of keywords after parsing
keywords[0]=0
//no of matches found.
found[0]=0
// SEARCH TERMS...
title[1]="keywordss"
desc[1]="title"
links[1]="link"
matched[1]=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;
}
}
// 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('<link rel=stylesheet href=style.css type=text/css>');
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>');
output.document.write('<a name=top>');
output.document.write('<center>');
output.document.write('<table width=550>');
output.document.write('<tr>');
output.document.write('<td class=layout>');
output.document.write(' <p />');
output.document.write('<center>');
output.document.write('<h1>search results</h1>');
output.document.write('</center>');
if (found[0]==0)
{
output.document.write('<p />');
output.document.write("<h2>No documents matched your search.</h2>");
}
else
{
// data has been found
output.document.write('<p />');
output.document.write('<h2>');
output.document.write(found[0] + ' documents found...');
output.document.write("</h2><p /><table>");
for (i=1; i<=found[0];i++)
{
output.document.write("<tr><td class=tables width=25>");
output.document.write("<h3 class=tablehead>");
output.document.write("" +i +"");
output.document.write("<td class=tables width=525><h3 class=tablejust>");
itemp=found[i];
output.document.write(desc[itemp].bold() +"<br>" +
links[itemp].link(links[itemp])+"<br>");
temp= (matched[itemp]/keywords[0])*100
matched[itemp]=0
}
found[0]=0;
output.document.write("</table>");
}
output.document.write('<hr size=1 color=cccccc>');
output.document.write('<img src=images/icon.jpg>');
output.document.write('</tr>');
output.document.write('</tr>');
output.document.write('</table>');
output.document.write ("</body></html>");
output.document.close();
}
Thanks! :)
I have been working on a Javascript powered search engine for a set of browser based user guides. I can't use any server-side languages as it will all be accessed from a network drive, which as been a real pain as I would rather have just made a php search engine, but whatever...
I have a working JavaScript search function, currently the results are displayed in the same window/frame as the search form.
All i need is to be able to target the results to a different frame. For example, I'll keep the search form in a top frame, and some information in the bottom frame. Submitting the search form will display the results in the bottom frame. Its giving me a headache, I'm sure it is remarkably simple...
The code:
title = new Object();
desc = new Object();
links= new Object();
matched= new Object();
keywords= new Object();
found= new Object();
var temp=0;
// # of titles present in the database
title[0]=1
//no of keywords after parsing
keywords[0]=0
//no of matches found.
found[0]=0
// SEARCH TERMS...
title[1]="keywordss"
desc[1]="title"
links[1]="link"
matched[1]=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;
}
}
// 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('<link rel=stylesheet href=style.css type=text/css>');
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>');
output.document.write('<a name=top>');
output.document.write('<center>');
output.document.write('<table width=550>');
output.document.write('<tr>');
output.document.write('<td class=layout>');
output.document.write(' <p />');
output.document.write('<center>');
output.document.write('<h1>search results</h1>');
output.document.write('</center>');
if (found[0]==0)
{
output.document.write('<p />');
output.document.write("<h2>No documents matched your search.</h2>");
}
else
{
// data has been found
output.document.write('<p />');
output.document.write('<h2>');
output.document.write(found[0] + ' documents found...');
output.document.write("</h2><p /><table>");
for (i=1; i<=found[0];i++)
{
output.document.write("<tr><td class=tables width=25>");
output.document.write("<h3 class=tablehead>");
output.document.write("" +i +"");
output.document.write("<td class=tables width=525><h3 class=tablejust>");
itemp=found[i];
output.document.write(desc[itemp].bold() +"<br>" +
links[itemp].link(links[itemp])+"<br>");
temp= (matched[itemp]/keywords[0])*100
matched[itemp]=0
}
found[0]=0;
output.document.write("</table>");
}
output.document.write('<hr size=1 color=cccccc>');
output.document.write('<img src=images/icon.jpg>');
output.document.write('</tr>');
output.document.write('</tr>');
output.document.write('</table>');
output.document.write ("</body></html>");
output.document.close();
}
Thanks! :)