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 |
|
|
var query = form.elements['query'].value; |
32 |
|
|
var index_name = form.elements['index_name'].options[form.elements['index_name'].selectedIndex].value; |
33 |
|
|
|
34 |
|
|
if(!query) |
35 |
|
|
{ |
36 |
|
|
return false; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
if(query == null || query == "") |
40 |
|
|
{ |
41 |
|
|
alert("No search terms entered!"); |
42 |
|
|
return false; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
var parsed_string = query.replace(/\s/gi,"+"); |
46 |
|
|
//var url=location.host+location.pathname+"?search="+parsed_string; |
47 |
|
|
var url=location.pathname+"?"; |
48 |
|
|
if (index_name) url += "index_name="+index_name+"&"; |
49 |
|
|
url += "query="+parsed_string; |
50 |
|
|
location = url; |
51 |
|
|
|
52 |
|
|
return false; |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
// Function to help find a "DIV" element |
56 |
|
|
function findDivHelper(n, id) |
57 |
|
|
{ |
58 |
|
|
for(var m=n.firstChild; m != null; m=m.nextSibling) |
59 |
|
|
{ |
60 |
|
|
if((m.nodeType == 1) && |
61 |
|
|
(m.tagName.toLowerCase() == "div") && |
62 |
|
|
m.getAttribute("id") && |
63 |
|
|
(m.getAttribute("id").toLowerCase() == id.toLowerCase() )) |
64 |
|
|
{ |
65 |
|
|
return m; |
66 |
|
|
} |
67 |
|
|
else |
68 |
|
|
{ |
69 |
|
|
var r=findDivHelper(m, id); |
70 |
|
|
if(r) return r; |
71 |
|
|
} |
72 |
|
|
} |
73 |
|
|
return null; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
// Function to find a specified "DIV" element by id |
77 |
|
|
function findDiv(id) |
78 |
|
|
{ |
79 |
|
|
return findDivHelper(document.body,id); |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
// Print results to page |
83 |
|
|
function printResults(result) |
84 |
|
|
{ |
85 |
|
|
//clearTimeout(watchdog_id); |
86 |
|
|
//debug("clearTimeout = "+watchdog_id); |
87 |
|
|
debug("printResults("+result.length+")"); |
88 |
|
|
|
89 |
|
|
var d = findDiv("results"); |
90 |
|
|
var header; |
91 |
|
|
|
92 |
|
|
// Null result output |
93 |
|
|
if(result.length < 1) |
94 |
|
|
{ |
95 |
|
|
header = (d.getElementsByTagName("h2"))[0].firstChild; |
96 |
|
|
try { |
97 |
|
|
header.replaceData(0, 14, "Nothing Found "); |
98 |
|
|
} catch(e) {} |
99 |
|
|
|
100 |
|
|
if(search_err != "") |
101 |
|
|
{ |
102 |
|
|
e = document.createElement("font"); |
103 |
|
|
e.setAttribute("color","red"); |
104 |
|
|
e.setAttribute("size","+1"); |
105 |
|
|
e.appendChild(document.createTextNode(search_err)); |
106 |
|
|
d.appendChild(e); |
107 |
|
|
d.appendChild(document.createElement("br")); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
return; |
111 |
|
|
} |
112 |
|
|
|
113 |
dpavlin |
494 |
debug("sort results by title"); |
114 |
|
|
results.sort(sortResults_title); |
115 |
|
|
|
116 |
dpavlin |
484 |
// Add results to main document |
117 |
|
|
for(var i=result.length-1; i>=0; i--) |
118 |
|
|
{ |
119 |
|
|
var e = document.createElement("font"); |
120 |
|
|
|
121 |
|
|
e = document.createElement("a"); |
122 |
|
|
e.setAttribute("href","hijerarhija.html?o="+result[i].link+"#mfn"+result[i].link); |
123 |
|
|
e.appendChild(document.createTextNode(result[i].title)); |
124 |
|
|
d.appendChild(e); |
125 |
|
|
d.appendChild(document.createTextNode(" ")); |
126 |
|
|
|
127 |
|
|
e = document.createElement("a"); |
128 |
|
|
e.setAttribute("href","thes/"+result[i].link+".html"+location.search); |
129 |
|
|
//e.setAttribute("target","popup"); |
130 |
|
|
//e.onclick = function() { return popup(); }; |
131 |
|
|
e.onclick = popup; |
132 |
|
|
e.appendChild(document.createTextNode("\u00bb")); |
133 |
|
|
d.appendChild(e); |
134 |
|
|
/* |
135 |
|
|
e = document.createElement("font"); |
136 |
|
|
e.setAttribute("color","gray"); |
137 |
|
|
e.appendChild(document.createTextNode("["+result[i].frequency+"]")); |
138 |
|
|
d.appendChild(e); |
139 |
|
|
*/ |
140 |
|
|
d.appendChild(document.createElement("br")); |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
// Change header |
144 |
|
|
header = (d.getElementsByTagName("h2"))[0].firstChild; |
145 |
|
|
|
146 |
|
|
try { |
147 |
|
|
header.replaceData(0, 14, "Search Results"); |
148 |
|
|
} catch(e) {} |
149 |
|
|
|
150 |
|
|
} |
151 |
dpavlin |
494 |
|
152 |
|
|
// override default sort by frequency and sort by headline |
153 |
|
|
function sortResults_title(a, b) |
154 |
|
|
{ |
155 |
|
|
return a.title == b.title ? 0 : ( a.title > b.title ? -1 : 1); |
156 |
|
|
} |