I have designed an internal search engine. I have it working to the point that it will search and find what I am looking for. My problem is that it is inconsistent, and when running the search engine with the same search string multiple times, it finds a different number of results every time.
Below is the code:
<code>
if (cs2 == true)
{
index_page = "cs2.htm";
search(index_page,input)
}
if (cssc == true)
{
index_page = "cssc.htm";
search(index_page,input)
}
if (eso == true)
{
index_page = "eso.htm";
search(index_page,input)
}
...
function search(first,find)
{
var i = 0;
var first_window = window.open(first,"first_window","width=1,height=1,top=1700,left=1700"
;
while (i < first_window.document.links.length)
{
var second_window = window.open(first_window.document.links,"second_window","width=1,height=1,top=1700,left=1700"
;
var j = 0;
while (j < second_window.document.links.length)
{
var pdf_link = "";
pdf_link = second_window.document.links[j];
var pdf_link_text = "";
pdf_link_text = second_window.document.links[j].innerHTML;
compare(pdf_link,pdf_link_text,find);
j++;
}
second_window.close();
i++;
}
first_window.close();
}
function compare(link,text,desired)
{
var found = text.toUpperCase().indexOf(desired.toUpperCase());
if (found != -1)
{
descriptions[array_index] = text;
listoflinks = listoflinks + link + ",";
array_index++;
}
}
<code>
What I have it do is read in a search string from a form, as well as where to search in. That is the first part of the code. It sends the main page to the search function. Inside the main page, it has links to sub pages. Search opens up each sub page and looks at the links. It then sends it to compare, which puts it on the arrays for displaying at the end if it matches what I am looking for. I have gotten it to find everything before, so I know it does work. Why is it random though?
Below is the code:
<code>
if (cs2 == true)
{
index_page = "cs2.htm";
search(index_page,input)
}
if (cssc == true)
{
index_page = "cssc.htm";
search(index_page,input)
}
if (eso == true)
{
index_page = "eso.htm";
search(index_page,input)
}
...
function search(first,find)
{
var i = 0;
var first_window = window.open(first,"first_window","width=1,height=1,top=1700,left=1700"
while (i < first_window.document.links.length)
{
var second_window = window.open(first_window.document.links,"second_window","width=1,height=1,top=1700,left=1700"
var j = 0;
while (j < second_window.document.links.length)
{
var pdf_link = "";
pdf_link = second_window.document.links[j];
var pdf_link_text = "";
pdf_link_text = second_window.document.links[j].innerHTML;
compare(pdf_link,pdf_link_text,find);
j++;
}
second_window.close();
i++;
}
first_window.close();
}
function compare(link,text,desired)
{
var found = text.toUpperCase().indexOf(desired.toUpperCase());
if (found != -1)
{
descriptions[array_index] = text;
listoflinks = listoflinks + link + ",";
array_index++;
}
}
<code>
What I have it do is read in a search string from a form, as well as where to search in. That is the first part of the code. It sends the main page to the search function. Inside the main page, it has links to sub pages. Search opens up each sub page and looks at the links. It then sends it to compare, which puts it on the arrays for displaying at the end if it matches what I am looking for. I have gotten it to find everything before, so I know it does work. Why is it random though?