Click to See Complete Forum and Search --> : only for javascript experts


vinsa
07-06-2003, 06:52 AM
Hello,
first sorry for my english.
This is my search engine.
I'll use it for search on my
computer (not in internet).
But I have problem.
My data base is to large - 10 Mb.
This script is not full - this is
just example. So my browser (IE5.0)
load the whole data in the memory -
this is slowly and not effective.
I want to save
my data base in another text
file (not .js). So IE will not load
the whole data in advance.
When I click
the search button the script begin searching in
this text file with my data. Is
this possible with javascript or I must
use Java Applet.

<HTML><HEAD><TITLE>dictionary</TITLE>
<META content="text/html; charset=windows-1251" http-equiv=Content-Type>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var item = new Array();

// Here is my data base


// "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"

c=0; item[c]=new Array("index.html","","about","key words","1. наоколо, в кръг, тук-там, навсякъде<P><b>runwurs are ABOUT</b> носят се слухове, говори се <P><b>there is measles ABOUT</b> има много (заболявания от) шарка <P>2. приблизително, почти, горе-долу <P><b>the work is ABOUT done</b> работата е на привършване");
c++; item[c]=new Array("about.htm","","About Me","about,author,contact,email,who","Contact details and general information about the creator of the site and what the site is about.");
c++; item[c]=new Array("links.htm","","Links page","links,more,where,similar,friends","Links to my favourite sites which I find interesting. Other friends sites which have similar interests to my own.");
c++; item[c]=new Array("main.htm","main/","Main Page","content,main,focus","The main part of my site which contains what you have come to see. Lots of stuff like that and more great things. All in a sub directory.");
c++; item[c]=new Array("logo.jpg","main/images/","Link Logo","link,image,logo,graphic","The logo.jpg is just a small image which you can place on your site as a link to me. It's in a second level subdirectory.");

page="<html><head><title>Search Results</title></head><body bgcolor='white' leftmargin=3 topmargin=3 text='black'><center><table border=0 cellspacing=0 cellpadding=0 width=100%>";


function search(frm) {
win = parent.middle("","secId5874","scrollbars=1");
win.document.write(page);
txt = frm.srchval.value.split(" ");
fnd = new Array(); total=0;
for (i = 0; i < item.length; i++) {
fnd[i] = 0; order = new Array(0, 4, 2, 3);
for (j = 0; j < order.length; j++)
for (k = 0; k < txt.length; k++)
if (item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "")
fnd[i] += (j+1);
}
for (i = 0; i < fnd.length; i++) {
n = 0; w = -1;
for (j = 0;j < fnd.length; j++)
if (fnd[j] > n) { n = fnd[j]; w = j; };
if (w > -1) total += show(w, win, n);
fnd[w] = 0;
}
win.document.write("</table><br>Total found: "+total+"<br></body></html>");
win.document.close();
}
function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = "<tr><td><a href='"+link+"'><b>"+item[which][2]+"</b></a><br>";
line += item[which][4] + "<br>"+link+"</td></tr>";
wind.document.write(line);
return 1;
}
// End -->
</script>



</HEAD>
<BODY
bgcolor="">


<form method=get action="javascript:void(0)" onsubmit="search(this); return false;">
<tr><td><input type=text name=srchval value=""><input type=submit value="Search"></td></tr>
</form>



<IFRAME name="middle" width="250" height="300" src="web1.html" frameborder=0 style="border-style: inset; border-width: 2px"></IFRAME>



</BODY></HTML>

Fang
07-06-2003, 07:29 AM
You could use Data Binding (http://msdn.microsoft.com/library/default.asp?url=/workshop/author/databind/data_binding.asp), your data can be held in a .csv type file format.

vinsa
07-06-2003, 11:58 AM
can I search in txt file with javascript? How?

Fang
07-07-2003, 03:10 AM
This only works with IE!
Here is a simple example to displaying and query your database.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Basic Data Binding</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<!-- Data source object: file parameters -->
<object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="MyDatabase.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>

<h2>Sortable table</h2>
<table id="stocktbl" datasrc="#selectlist" border="1"cellpadding="3" cellspacing="0" summary="Sortable table">
<thead>
<tr onclick="SortTable();">
<td><a href="#" id="first">First</a></td>
<td><a href="#" id="last">Last</a></td>
</tr>
</thead>

<tbody>
<tr>
<td><span datafld="first"></span></td>
<td><span datafld="last"></span></td>
</tr>
</tbody>
</table>
<br /><br />

<h2>Simple search</h2>
<form name="SearchResults">
Query First name: <input id="query" value="" /><button onclick="SearchTable();">search</button><br />
Result Last name: <input id="results" value="" /><button type="reset">reset</button>
</form>
<script type="text/javascript">
<!--
function SortTable() {
if(event.srcElement.id != "") {
selectlist.Sort=event.srcElement.id;
selectlist.Reset();
}
}

function SearchTable() {
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
if(selectlist.recordset("first")==document.SearchResults.query.value) {
document.SearchResults.results.value=selectlist.recordset("last")
return;
}
selectlist.recordset.MoveNext();
}
document.SearchResults.results.value="not found";
}
//-->
</script>
</body>
</html>


Contents of the data file "MyDatabase.txt"

First;Last
John;Smith
Frank;White
Dave;Jones


Both files must be in the same directory.

vinsa
07-07-2003, 04:17 AM
*************************************************
OK,
this is usefully, but
searching is not perfect.
I can find John,
but can't find nothing about:
john, JOHN, joh, johns.
My page will be a dictionary
and the searching is important.
Can you repair the searching?
The search result is not necessary
to be exact. He must be approximately
exact. Example:
1. when I type johns -> search result: John
2. when I type JOHN -> search result: John (case must have no matter)
3. when I type joh -> search result: John
*************************************************

Fang
07-07-2003, 06:22 AM
This will find "john", "JOHN", "joh", or "johns"


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Basic Data Binding</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<!-- Data source object: file parameters -->
<object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="MyDatabase.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>

<h2>Sortable table</h2>
<table id="stocktbl" datasrc="#selectlist" border="1"cellpadding="3" cellspacing="0" summary="Sortable table">
<thead>
<tr onclick="SortTable();">
<td><a href="#" id="first">First</a></td>
<td><a href="#" id="last">Last</a></td>
</tr>
</thead>

<tbody>
<tr>
<td><span datafld="first"></span></td>
<td><span datafld="last"></span></td>
</tr>
</tbody>
</table>
<br /><br />

<h2>Simple search</h2>
<form name="SearchResults">
Query First name: <input id="query" value="" /><button onclick="SearchTable();">search</button><br />
Result(s): <input id="results" value="" /><button type="reset">reset</button>
</form>
<script type="text/javascript">
<!--
function SortTable() {
if(event.srcElement.id != "") {
selectlist.Sort=event.srcElement.id;
selectlist.Reset();
}
}

function SearchTable() {
var list="";
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
list+=selectlist.recordset("first")+", ";
}
selectlist.recordset.MoveNext();
}
document.SearchResults.results.value=(list=="")? "not found" : list;
}
//-->
</script>
</body>
</html>

vinsa
07-07-2003, 08:16 AM
Fang - you are great!
Thank you with all my heart.
The searching is now perfect.
I fixed a little bug.
When the first textarea
is empty the script record
all words in the data base ->
John, Frank, Dave.
My data base contain over 5000
words. I repair again the script,
and when the first textarea
is empty -> have no results.
Look the blue text;)
I hope, that I don't bore you.
========================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Basic Data Binding</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251">
</head>
<body>
<!-- Data source object: file parameters -->
<object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="MyDatabase.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>



<tbody>
<tr>
<td><span datafld="first"></span></td>
<td><span datafld="last"></span></td>
</tr>
</tbody>
</table>
<br /><br />

<h2>Simple search</h2>
<form name="SearchResults">
Query First name: <input id="query" value="" /><button onclick="SearchAble();">search</button><br />
Result(s): <input id="results" value="" /><button type="reset">reset</button>
</form>
<script type="text/javascript">
<!--

function SearchAble() {
if (document.SearchResults.query.value == ""){
document.SearchResults.results.value= "not found"
}
else{
SearchTable()
}
}

function SearchTable() {
var list="";
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
list+=selectlist.recordset("last")+", ";
}
selectlist.recordset.MoveNext();
}
document.SearchResults.results.value=(list=="")? "not found" : list;
}
//-->
</script>
</body>
</html>

Fang
07-07-2003, 08:30 AM
It may be better to check the length of the query string:

function SearchAble() {
if (document.SearchResults.query.value.length<3){ //minimum of 3 characters
document.SearchResults.results.value= "Query string too short"
}
else{
SearchTable()
}
}

vinsa
07-08-2003, 06:48 AM
First sorry for my English.
Hello Fang,
I edit your source.
But I need your help again.
I can't control some parameters
of search result
(like font, font style(underline bold italic), font size,
font color, new row (like <br>).
I want when I type keyword2 -> search result to look
like the attached pic (image).
Can you help me?

P.S. Contents of the data file "MyDatabase.txt" is:
First;Last
keyword1;bla bla1
keyword2;word1 [word2] word3 word4 word5 word6 word7 word8 word9
keyword3;bla bla3
==============
This is my new source

<html>
<head>
<title>Basic Data Binding</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251">
</head>
<body>
<!-- Data source object: file parameters -->
<object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="MyDatabase.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>


<h2>Simple search</h2>
<form name="SearchResults">
Query First name: <input id="query" value="" /><button onclick="SearchAble();">search</button><br />
<button onclick="Clear();">Clear</button>
</form>
<script type="text/javascript">
<!--
page="<html><head><title>Search Results</title></head><body bgcolor='yellow' leftmargin=3 topmargin=3 text='blue'><center><table border=0 cellspacing=0 cellpadding=0 width=100%><font face=Arial size=3>";

function SearchAble() {
if (document.SearchResults.query.value == ""){
win = parent.middle("","secId5874","scrollbars=1");
win.document.write("write something");
win.document.close();
}
else{
SearchTable()
}
}

function SearchTable() {
win = parent.middle("","secId5874","scrollbars=1");
win.document.write(page);
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
win.document.write(selectlist.recordset("last")+", ");
win.document.write("</font></table></body></html>");
win.document.close();
}
selectlist.recordset.MoveNext();
}

}

function Clear() {
win = parent.middle("","secId5874","scrollbars=1");
win.document.write(page);
win.document.close();
document.SearchResults.query.value = "";
}
//-->
</script>


<IFRAME name="middle" width="250" height="300" src="nach.html" frameborder=0 style="border-style: inset; border-width: 2px"></IFRAME>

</body>
</html>

<!Contents of the data file "MyDatabase.txt" - example:
First;Last
keyword1;bla bla1
keyword2;word1 [word2] word3 word4 word5 word6 word7 word8 word9
keyword3;bla bla3 >

Fang
07-08-2003, 10:21 AM
Change SearchTable() and add FormatResults() functions.
This assumes there is only one result and atleast 4 words in the result!

function SearchTable() {
win = parent.middle("","secId5874","scrollbars=1");
//win.document.write(page);
var list="";
var result=0;
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
list=''+selectlist.recordset("last")+'';
}
selectlist.recordset.MoveNext();
}
//Display list
win.document.write(page+FormatResults(list)+'</font></table></body></html>');
win.document.close();
}

function FormatResults(result) {
var listing="";
var last="";
result=result.split(" ");
last='<div style="color:red;white-space:nowrap;">';
for(var i=4; i<result.length; i++) {
last+=result[i]+" ";
}
last+='</div>';
listing+='<div style="font-weight: bold; text-decoration: underline;">'+result[0]+'</div><div>'+result[1]+'</div><div style="font-style:italic;">'+result[2]+'</div><div style="font-family:Arial;font-size:larger;">'+result[3]+'</div>'+last;
return listing;
}

vinsa
07-09-2003, 07:20 AM
Hello Fang,
I find bug again in searching but I can't fixed.
1.when I type "a" in the text area ->
search results: "important/undefined" not "a/undefined"
2.when I type "i" in the text area ->
search results: "in/undefined" not "i/undefined"
Why? I want when I type in the text area
"a" -> search results: "a/undefined"
3. when I type "impo" in the text area ->
search results: "impossible/undefined" not "important/undefined"
Why? "important" is befor "impossible" and "r" is befor "s"
in English alphabet.
This is the source:

============================================
</head>
<body bgcolor=082984>
<!-- Data source object: file parameters -->
<object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="MyDatabase.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>


<h2>Simple search</h2>
<form name="SearchResults">
Query First name: <input id="query" value="" onkeyup="SearchTable();" /><button onclick="SearchAble();">search</button><br />
<button onclick="Clear();">Clear</button>
</form>
<script type="text/javascript">
<!--
page="<html><head><title>Search Results</title><style>.avn {color:red;}</style></head><body bgcolor='f0f0f0' leftmargin=3 topmargin=3 text='blue'><center><table border=0 cellspacing=0 cellpadding=2 width=100%><font face=Arial size=3>";

function SearchAble() {
if (document.SearchResults.query.value == ""){
win = parent.middle("","secId5874","scrollbars=1");
win.document.write("write something");
win.document.close();
}
else{
SearchTable()
}
}

function SearchTable() {
win = parent.middle("","secId5874","scrollbars=1");
//win.document.write(page);
var list="";
var result=0;
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
list=''+selectlist.recordset("last")+'';
}
selectlist.recordset.MoveNext();
}
//Display list
win.document.write(page+FormatResults(list)+'</font></table></body></html>');
win.document.close();
}

function FormatResults(result) {
var listing="";
var last="";
result=result.split(" ");
last='<div style="color:black;white-space:nowrap; font-size:9pt;">';
for(var i=2; i<result.length; i++) {
last+=result[i]+" ";
}
last+='</div>';
listing+='<div style="font-size:larger;">'+result[0]+'</div><div style="font-family:PhoneticTM;">'+result[1]+'</div>'+last;
return listing;
}



function Clear() {
win = parent.middle("","secId5874","scrollbars=1");
win.document.write(page);
win.document.close();
document.SearchResults.query.value = "";
}
//-->
</script>


<IFRAME name="middle" width="223" scrolling="auto" height="267" src="nach.html" frameborder=0 style="border-style: inset; border-width: 2px"></IFRAME>

</body>
</html>
=====================================


P.S.Contents of the data file "MyDatabase.txt"
a;a
able;able
about;about
absolutely;absolutely
accept;accept
I;I
ice;ice
idea;idea
if;if
ill;ill
important;important
impossible;impossible
impulse;impulse
in;in

Fang
07-09-2003, 09:05 AM
The function FormatResults() can only deal with a database that looks like:
keyword;word1 [word2] word3 word4 ...wordxx
if there are less than 4 words accociated with the keyword then an error occurs.
you must set out the constraints of your database and then write the query program.

vinsa
07-09-2003, 11:44 AM
Hi Fang,
the problem is not in database file.
I try with this data base, but I have the same problem again:
=======================
First;Last
a;a a2 a3 a4 a5 a6
able;able able2 able3 able4 able5 able6
about;about about2 about3 about4 about5 about6
absolutely;absolutely absolutely2 absolutely3 absolutely4 absolutely5 absolutely6
accept;accept accept2 accept3 accep4t accept5 accept6
I;I I2 I3 I4 I5 I6
ice;ice ice2 ice3 ice4 ice5 ice6
idea;idea idea2 idea3 idea4 idea5 idea6
if;if if2 if3 if4 if5 if6
ill;ill ill2 ill3 ill4 ill5 ill6
important;important important2 important3 important4 important5 important6
impossible;impossible impossible2 impossible3 impossible4 impossible5 impossible6
impulse;impulse impulse2 impulse3 impulse4 impulse5 impulse6
in;in in2 in3 in4 in5 in6
=========================
1.when I type "a" in the text area ->
search results: "important important2 important3 important4 important5 important6 "
not "a a2 a3 a4 a5 a6 "
2.when I type "i" in the text area ->
search results: "in in in2 in3 in4 in5 in6" not "I I I2 I3 I4 I5 I6"
Why? I want when I type in the text area
"a" -> search results: "a a a2 a3 a4 a5 a6 "
3. when I type "impo" in the text area ->
search results: "impossible impossible impossible2 impossible3 impossible4 impossible5 impossible6"
not "important impulse impulse2 impulse3 impulse4 impulse5 impulse6"
Why? "important" is befor "impossible" and "r" is befor "s"
in English alphabet.
Try to find info about "a", not "a ".
I think that the script search in database from the bottom upwards.
He must search in database from the top downwards.
Can you fix this?

==============
This is the page source:

<html>
<head>
<title>Basic Data Binding</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251">
</head>
<body bgcolor=082984>
<!-- Data source object: file parameters -->
<object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="MyDatabase.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>


<h2>Simple search</h2>
<form name="SearchResults">
Query First name: <input id="query" value="" /><button onclick="SearchAble();">search</button><br />
<button onclick="Clear();">Clear</button>
</form>
<script type="text/javascript">
<!--
page="<html><head><title>Search Results</title><style>.avn {color:red;}</style></head><body bgcolor='f0f0f0' leftmargin=3 topmargin=3 text='blue'><center><table border=0 cellspacing=0 cellpadding=2 width=100%><font face=Arial size=3>";

function SearchAble() {
if (document.SearchResults.query.value == ""){
win = parent.middle("","secId5874","scrollbars=1");
win.document.write("write something");
win.document.close();
}
else{
SearchTable()
}
}

function SearchTable() {
win = parent.middle("","secId5874","scrollbars=1");
//win.document.write(page);
var list="";
var result=0;
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
list=''+selectlist.recordset("last")+'';
}
selectlist.recordset.MoveNext();
}
//Display list
win.document.write(page+FormatResults(list)+'</font></table></body></html>');
win.document.close();
}

function FormatResults(result) {
var listing="";
var last="";
result=result.split(" ");
last='<div style="color:black;white-space:nowrap; font-size:9pt;">';
for(var i=2; i<result.length; i++) {
last+=result[i]+" ";
}
last+='</div>';
listing+='<div style="font-size:larger;">'+result[0]+'</div><div style="font-family:PhoneticTM;">'+result[1]+'</div>'+last;
return listing;
}



function Clear() {
win = parent.middle("","secId5874","scrollbars=1");
win.document.write(page);
win.document.close();
document.SearchResults.query.value = "";
}
//-->
</script>


<IFRAME name="middle" width="223" scrolling="auto" height="267" src="nach.html" frameborder=0 style="border-style: inset; border-width: 2px"></IFRAME>

</body>
</html>

Fang
07-09-2003, 12:10 PM
The program finds the last instance of your query.
To find the first instance add else here:

if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
list=''+selectlist.recordset("last")+'';
}
else {
selectlist.recordset.MoveNext();
}

h_monteiro
07-09-2003, 04:15 PM
I'm not sure if this will help.

I created a search feature for a website.

It searches against an array list of agreements available from my company.

Go to www.amerilawyer.com/agreements

Then, persform a search for an agreement.

The results page has the bulk of the source code for the search feature. Just view its source.

Maybe this will help with your ideas.

vinsa
07-10-2003, 04:40 AM
Hi Fang,
I find something interesting - perfect search-engine,
but I can't convert it for my need.
Can you integrate this search-engine in my page.
(I have in mind to search in my database).
I tryed, but I can't do it. Please help me.
==================
This is the perfect search-engine
I need to work only with IE
==================
<HTML><HEAD><TITLE>perfect seaching</TITLE>
<META content="text/html; charset=windows-1251" http-equiv=Content-Type>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var NS4 = (document.layers);
var IE4 = (document.all);

var win = this;
var n = 0;

function findInPage(str) {
var txt, i, found;
if (str == "")
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0) alert(str + " was not found on this page.");
}
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}
if (found) {
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
else
alert(str + " was not found on this page.");
}
}
return false;
}
// End -->
</script>

</HEAD>
<BODY>
<form name=search onSubmit="return findInPage(this.string.value);">
<b>Search here:</b> <input name=string type=text size=15 onChange="n = 0;">
<INPUT type=submit value=start>
</form>
</body></html>
==================
This is my page with not perfect search-engine
==================<html>
<head>
<title>Basic Data Binding</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251">
</head>
<body bgcolor=082984>
<!-- Data source object: file parameters -->
<object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="MyDatabase.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>


<h2>Simple search</h2>
<form name="SearchResults">
Query First name: <input id="query" value="" /><button onclick="SearchAble();">search</button><br />
<button onclick="Clear();">Clear</button>
</form>
<script type="text/javascript">
<!--
page="<html><head><title>Search Results</title><style>.avn {color:red;}</style></head><body bgcolor='f0f0f0' leftmargin=3 topmargin=3 text='blue'><center><table border=0 cellspacing=0 cellpadding=2 width=100%><font face=Arial size=3>";

function SearchAble() {
if (document.SearchResults.query.value == ""){
win = parent.middle("","secId5874","scrollbars=1");
win.document.write("write something");
win.document.close();
}
else{
SearchTable()
}
}

function SearchTable() {
win = parent.middle("","secId5874","scrollbars=1");
//win.document.write(page);
var list="";
var result=0;
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
list=''+selectlist.recordset("last")+'';
}
selectlist.recordset.MoveNext();
}
//Display list
win.document.write(page+FormatResults(list)+'</font></table></body></html>');
win.document.close();
}

function FormatResults(result) {
var listing="";
var last="";
result=result.split(" ");
last='<div style="color:black;white-space:nowrap; font-size:9pt;">';
for(var i=2; i<result.length; i++) {
last+=result[i]+" ";
}
last+='</div>';
listing+='<div style="font-size:larger;">'+result[0]+'</div><div style="font-family:PhoneticTM;">'+result[1]+'</div>'+last;
return listing;
}



function Clear() {
win = parent.middle("","secId5874","scrollbars=1");
win.document.write(page);
win.document.close();
document.SearchResults.query.value = "";
}
//-->
</script>


<IFRAME name="middle" width="223" scrolling="auto" height="267" src="nach.html" frameborder=0 style="border-style: inset; border-width: 2px"></IFRAME>

</body>
</html>

P.S. Contents of the data file "MyDatabase.txt" - example:
First;Last
keyword1;bla bla1 bla2 bla3 bla4 bla5 bla6
keyword2;word1 word2 word3 word4 word5 word6 word7 word8 word9
keyword3;bla bla3 bla4 bla5 bla6 bla7 bla8 bla9

vinsa
07-12-2003, 10:21 AM
Hello Fang!
First sorry for my English.
I found a better search engine.
Can help me to
search in my database with
this search-engine. This search-engine
search in the same page. I want to
search in my database and results to show
in ifframe "middle".
==================
<HTML><HEAD><TITLE>seaching</TITLE>
<META content="text/html; charset=windows-1251" http-equiv=Content-Type>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var IE4 = (document.all);

var win = this;
var n = 0;

function findInPage(str) {
var txt, i, found;
if (str == "")
return false;
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}
if (found) {
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
else
alert(str + " was not found on this page.");
}
}
return false;
}
// End -->
</script>

</HEAD>
<BODY>

<!-- Data source object: file parameters -->
<object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="MyDatabase.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>

<form name=search onSubmit="return findInPage(this.string.value);">
<b>Search here:</b> <input name=string type=text size=15 onChange="n = 0;">
<INPUT type=submit value=start>
</form>
<IFRAME name="middle" width="223" scrolling="auto" height="267" src="nach.html" frameborder=0 style="border-style: inset; border-width: 2px"></IFRAME>

</body></html>
==================================
P.S. Contents of the data file "MyDatabase.txt"
(First are the keywords, Last are the search results).
This is only example:
==================================
First;Last
a;a word1 word2 word3 word4 word5 word6
able;able word1 word2 word3 word4 word5 word6
absolutely;absolutely word1 word2 word3 word4 word5 word6
accept;accept word1 word2 word3 word4 word5 word6
I;I word1 word2 word3 word4 word5 word6
ice;ice word1 word2 word3 word4 word5 word6
idea;idea word1 word2 word3 word4 word5 word6
if;if word1 word2 word3 word4 word5 word6
ill;ill word1 word2 word3 word4 word5 word6
important;important word1 word2 word3 word4 word5 word6
impossible;impossible word1 word2 word3 word4 word5 word6
impulse;impulse word1 word2 word3 word4 word5 word6
in;in word1 word2 word3 word4 word5 word6
speak;speak word1 word2 word3 word4 word5 word6