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