1 |
dpavlin |
484 |
/** |
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 |
dpavlin |
517 |
var query = null; |
32 |
|
|
if (document.form.elements['query']) query = document.form.elements['query'].value; |
33 |
dpavlin |
509 |
var index_name = document.form.elements['index_name'].options[document.form.elements['index_name'].selectedIndex].value; |
34 |
dpavlin |
484 |
|
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 |
dpavlin |
494 |
debug("sort results by title"); |
115 |
|
|
results.sort(sortResults_title); |
116 |
|
|
|
117 |
dpavlin |
484 |
// Add results to main document |
118 |
|
|
for(var i=result.length-1; i>=0; i--) |
119 |
|
|
{ |
120 |
|
|
var e = document.createElement("font"); |
121 |
|
|
|
122 |
|
|
e = document.createElement("a"); |
123 |
dpavlin |
499 |
e.setAttribute("href","hijerarhija.html?o="+result[i].link); |
124 |
dpavlin |
484 |
e.appendChild(document.createTextNode(result[i].title)); |
125 |
|
|
d.appendChild(e); |
126 |
|
|
d.appendChild(document.createTextNode(" ")); |
127 |
|
|
|
128 |
|
|
e = document.createElement("a"); |
129 |
|
|
e.setAttribute("href","thes/"+result[i].link+".html"+location.search); |
130 |
|
|
//e.setAttribute("target","popup"); |
131 |
|
|
//e.onclick = function() { return popup(); }; |
132 |
|
|
e.onclick = popup; |
133 |
|
|
e.appendChild(document.createTextNode("\u00bb")); |
134 |
|
|
d.appendChild(e); |
135 |
|
|
/* |
136 |
|
|
e = document.createElement("font"); |
137 |
|
|
e.setAttribute("color","gray"); |
138 |
|
|
e.appendChild(document.createTextNode("["+result[i].frequency+"]")); |
139 |
|
|
d.appendChild(e); |
140 |
|
|
*/ |
141 |
|
|
d.appendChild(document.createElement("br")); |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
// Change header |
145 |
|
|
header = (d.getElementsByTagName("h2"))[0].firstChild; |
146 |
|
|
|
147 |
|
|
try { |
148 |
|
|
header.replaceData(0, 14, "Search Results"); |
149 |
|
|
} catch(e) {} |
150 |
|
|
|
151 |
|
|
} |
152 |
dpavlin |
494 |
|
153 |
|
|
// override default sort by frequency and sort by headline |
154 |
|
|
function sortResults_title(a, b) |
155 |
|
|
{ |
156 |
dpavlin |
495 |
return a.title.toLowerCase() == b.title.toLowerCase() ? 0 : ( a.title.toLowerCase() > b.title.toLowerCase() ? -1 : 1); |
157 |
dpavlin |
494 |
} |