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 |
dpavlin |
527 |
var form = document.getElementById('search'); |
31 |
|
|
var query = null; |
32 |
dpavlin |
531 |
if (form) query = form.elements['query'].value; |
33 |
dpavlin |
484 |
|
34 |
dpavlin |
527 |
if(!query) |
35 |
|
|
{ |
36 |
|
|
return false; |
37 |
|
|
} |
38 |
dpavlin |
484 |
|
39 |
dpavlin |
527 |
if(query == null || query == "") |
40 |
|
|
{ |
41 |
|
|
alert("No search terms entered!"); |
42 |
|
|
return false; |
43 |
|
|
} |
44 |
dpavlin |
484 |
|
45 |
dpavlin |
527 |
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 |
dpavlin |
484 |
|
52 |
dpavlin |
527 |
return false; |
53 |
dpavlin |
484 |
} |
54 |
|
|
|
55 |
|
|
// Function to find a specified "DIV" element by id |
56 |
|
|
function findDiv(id) |
57 |
|
|
{ |
58 |
dpavlin |
527 |
return document.getElementById(id); |
59 |
dpavlin |
484 |
} |
60 |
|
|
|
61 |
|
|
// Print results to page |
62 |
|
|
function printResults(result) |
63 |
|
|
{ |
64 |
dpavlin |
527 |
//clearTimeout(watchdog_id); |
65 |
|
|
//debug("clearTimeout = "+watchdog_id); |
66 |
|
|
debug("printResults("+result.length+")"); |
67 |
dpavlin |
484 |
|
68 |
dpavlin |
527 |
var d = findDiv("results"); |
69 |
|
|
var status = findDiv("status"); |
70 |
dpavlin |
484 |
|
71 |
dpavlin |
527 |
// Null result output |
72 |
|
|
if(result.length < 1) |
73 |
|
|
{ |
74 |
|
|
if (status) status.innerHTML = "Nije pronaĆ°en niti jedan rezultat."; |
75 |
dpavlin |
484 |
|
76 |
dpavlin |
527 |
if(search_err != "") |
77 |
|
|
{ |
78 |
|
|
e = document.createElement("font"); |
79 |
|
|
e.setAttribute("color","red"); |
80 |
|
|
e.setAttribute("size","+1"); |
81 |
|
|
e.appendChild(document.createTextNode(search_err)); |
82 |
|
|
d.appendChild(e); |
83 |
|
|
d.appendChild(document.createElement("br")); |
84 |
|
|
} |
85 |
dpavlin |
484 |
|
86 |
dpavlin |
527 |
return; |
87 |
|
|
} |
88 |
dpavlin |
484 |
|
89 |
dpavlin |
527 |
debug("sort results by title"); |
90 |
|
|
results.sort(sortResults_title); |
91 |
dpavlin |
494 |
|
92 |
dpavlin |
527 |
// Add results to main document |
93 |
|
|
for(var i=result.length-1; i>=0; i--) |
94 |
|
|
{ |
95 |
|
|
var li = document.createElement("li"); |
96 |
dpavlin |
484 |
|
97 |
dpavlin |
527 |
var e = document.createElement("a"); |
98 |
|
|
e.setAttribute("href","hijerarhija.html?o="+result[i].link); |
99 |
|
|
var regex = new RegExp(/ *\* */); |
100 |
|
|
if (results[i].title.match(regex)) { |
101 |
|
|
e.appendChild(self.document.createTextNode(results[i].title.replace(regex,' '))); |
102 |
|
|
var pic = self.document.createElement("img"); |
103 |
|
|
pic.src = 'img/crovoc.png'; |
104 |
|
|
pic.border = 0; |
105 |
|
|
e.appendChild(pic); |
106 |
|
|
} else { |
107 |
|
|
e.appendChild(document.createTextNode(result[i].title)); |
108 |
|
|
} |
109 |
|
|
li.appendChild(e); |
110 |
|
|
li.appendChild(document.createTextNode(" ")); |
111 |
dpavlin |
484 |
|
112 |
dpavlin |
527 |
e = document.createElement("a"); |
113 |
|
|
e.setAttribute("href","thes/"+result[i].link+".html"+location.search); |
114 |
|
|
//e.setAttribute("target","popup"); |
115 |
|
|
//e.onclick = function() { return popup(); }; |
116 |
|
|
e.onclick = popup; |
117 |
|
|
var pic = self.document.createElement("img"); |
118 |
|
|
pic.src = 'img/listic.png'; |
119 |
|
|
pic.border = 0; |
120 |
|
|
e.appendChild(pic); |
121 |
|
|
li.appendChild(e); |
122 |
dpavlin |
484 |
/* |
123 |
dpavlin |
527 |
e = document.createElement("font"); |
124 |
|
|
e.setAttribute("color","gray"); |
125 |
|
|
e.appendChild(document.createTextNode("["+result[i].frequency+"]")); |
126 |
|
|
li.appendChild(e); |
127 |
dpavlin |
484 |
*/ |
128 |
dpavlin |
527 |
li.appendChild(document.createElement("br")); |
129 |
|
|
d.appendChild(li); |
130 |
|
|
} |
131 |
dpavlin |
484 |
|
132 |
dpavlin |
527 |
if (status) status.innerHTML = "PronaĆ°eno je "+results.length+" rezultata."; |
133 |
dpavlin |
484 |
|
134 |
|
|
} |
135 |
dpavlin |
494 |
|
136 |
|
|
// override default sort by frequency and sort by headline |
137 |
|
|
function sortResults_title(a, b) |
138 |
|
|
{ |
139 |
dpavlin |
527 |
return a.title.toLowerCase() == b.title.toLowerCase() ? 0 : ( a.title.toLowerCase() > b.title.toLowerCase() ? -1 : 1); |
140 |
dpavlin |
494 |
} |