1 |
/** |
2 |
usage.js an example usage of the search engine |
3 |
|
4 |
A part of the jsfind project (http://projects.elucidsoft.net/jsfind) |
5 |
Copyright (C) 2003 Shawn Garbett |
6 |
|
7 |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
9 |
as published by the Free Software Foundation; either version 2 |
10 |
of the License, or (at your option) any later version. |
11 |
|
12 |
This program is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU General Public License |
18 |
along with this program; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 |
|
21 |
Contact Info: |
22 |
Shawn Garbett <Shawn@eLucidSoft.net> |
23 |
http://www.elucidsoft.net |
24 |
4037 General Bate Drive |
25 |
Nashville, TN 37204 |
26 |
*/ |
27 |
|
28 |
function go(f) |
29 |
{ |
30 |
var form = document.getElementById('search'); |
31 |
var query = null; |
32 |
if (document.form.elements['query']) query = document.form.elements['query'].value; |
33 |
var index_name = document.form.elements['index_name'].options[document.form.elements['index_name'].selectedIndex].value; |
34 |
|
35 |
if(!query) |
36 |
{ |
37 |
return false; |
38 |
} |
39 |
|
40 |
if(query == null || query == "") |
41 |
{ |
42 |
alert("No search terms entered!"); |
43 |
return false; |
44 |
} |
45 |
|
46 |
var parsed_string = query.replace(/\s/gi,"+"); |
47 |
//var url=location.host+location.pathname+"?search="+parsed_string; |
48 |
var url=location.pathname+"?"; |
49 |
if (index_name) url += "index_name="+index_name+"&"; |
50 |
url += "query="+parsed_string; |
51 |
location = url; |
52 |
|
53 |
return false; |
54 |
} |
55 |
|
56 |
// Function to help find a "DIV" element |
57 |
function findDivHelper(n, id) |
58 |
{ |
59 |
for(var m=n.firstChild; m != null; m=m.nextSibling) |
60 |
{ |
61 |
if((m.nodeType == 1) && |
62 |
(m.tagName.toLowerCase() == "div") && |
63 |
m.getAttribute("id") && |
64 |
(m.getAttribute("id").toLowerCase() == id.toLowerCase() )) |
65 |
{ |
66 |
return m; |
67 |
} |
68 |
else |
69 |
{ |
70 |
var r=findDivHelper(m, id); |
71 |
if(r) return r; |
72 |
} |
73 |
} |
74 |
return null; |
75 |
} |
76 |
|
77 |
// Function to find a specified "DIV" element by id |
78 |
function findDiv(id) |
79 |
{ |
80 |
return findDivHelper(document.body,id); |
81 |
} |
82 |
|
83 |
// Print results to page |
84 |
function printResults(result) |
85 |
{ |
86 |
//clearTimeout(watchdog_id); |
87 |
//debug("clearTimeout = "+watchdog_id); |
88 |
debug("printResults("+result.length+")"); |
89 |
|
90 |
var d = findDiv("results"); |
91 |
var header; |
92 |
|
93 |
// Null result output |
94 |
if(result.length < 1) |
95 |
{ |
96 |
header = (d.getElementsByTagName("h2"))[0].firstChild; |
97 |
try { |
98 |
header.replaceData(0, 14, "Nothing Found "); |
99 |
} catch(e) {} |
100 |
|
101 |
if(search_err != "") |
102 |
{ |
103 |
e = document.createElement("font"); |
104 |
e.setAttribute("color","red"); |
105 |
e.setAttribute("size","+1"); |
106 |
e.appendChild(document.createTextNode(search_err)); |
107 |
d.appendChild(e); |
108 |
d.appendChild(document.createElement("br")); |
109 |
} |
110 |
|
111 |
return; |
112 |
} |
113 |
|
114 |
// Add results to main document |
115 |
for(var i=result.length-1; i>=0; i--) |
116 |
{ |
117 |
var e = document.createElement("font"); |
118 |
|
119 |
e = document.createElement("a"); |
120 |
e.setAttribute("href","browse.html?o="+result[i].link); |
121 |
e.appendChild(document.createTextNode(result[i].title)); |
122 |
d.appendChild(e); |
123 |
d.appendChild(document.createTextNode(" ")); |
124 |
|
125 |
e = document.createElement("a"); |
126 |
e.setAttribute("href","thes/"+result[i].link+".html"+location.search); |
127 |
e.setAttribute("target","popup"); |
128 |
//e.onclick = function() { return popup(); }; |
129 |
e.onclick = popup; |
130 |
e.appendChild(document.createTextNode("\u00bb")); |
131 |
d.appendChild(e); |
132 |
/* |
133 |
e = document.createElement("font"); |
134 |
e.setAttribute("color","gray"); |
135 |
e.appendChild(document.createTextNode("["+result[i].frequency+"]")); |
136 |
d.appendChild(e); |
137 |
*/ |
138 |
d.appendChild(document.createElement("br")); |
139 |
} |
140 |
|
141 |
// Change header |
142 |
header = (d.getElementsByTagName("h2"))[0].firstChild; |
143 |
|
144 |
try { |
145 |
header.replaceData(0, 14, "Search Results"); |
146 |
} catch(e) {} |
147 |
|
148 |
} |