ICE 3.4.2
[php5-ice-freebsdport.git] / java / resources / IceGridAdmin / zoom_search.js
blobd9c53a2c6857e091dbdaac7901af1a6da5c6a46f
1 // ----------------------------------------------------------------------------
2 // Zoom Search Engine 5.0 (30/4/2007)
3 //
4 // This file (search.js) is the JavaScript search front-end for client side
5 // searches using index files created by the Zoom Search Engine Indexer.
6 //
7 // email: zoom@wrensoft.com
8 // www: http://www.wrensoft.com
9 //
10 // Copyright (C) Wrensoft 2000-2007
12 // This script performs client-side searching with the index data file
13 // (zoom_index.js) generated by the Zoom Search Engine Indexer. It allows you
14 // to run searches on mediums such as CD-ROMs, or other local data, where a
15 // web server is not available.
17 // We recommend against using client-side searches for online websites because
18 // it requires the entire index data file to be downloaded onto the user's
19 // local machine. This can be very slow for large websites, and our server-side
20 // search scripts (available for PHP, ASP and CGI) are far better suited for this.
21 // However, JavaScript is still an option for smaller websites in a limited
22 // hosting situation (eg: your web host does not support PHP, ASP or CGI).
23 // ----------------------------------------------------------------------------
25 // Include required files for index data, settings, etc.
26 document.write("<script language=\"JavaScript\" src=\"zoom_index.js\" charset=\"" + Charset + "\"><\/script>");
27 document.write("<script language=\"JavaScript\" src=\"zoom_pageinfo.js\" charset=\"" + Charset + "\"><\/script>");
29 document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=" + Charset + "\">");
31 // ----------------------------------------------------------------------------
32 // Settings (change if necessary)
33 // ----------------------------------------------------------------------------
35 // The options available in the dropdown menu for number of results
36 // per page
37 var PerPageOptions = new Array(10, 20, 50, 100);
39 // Globals
40 var SkippedWords = 0;
41 var searchWords = new Array();
42 var RegExpSearchWords = new Array();
43 var SkippedOutputStr = "";
45 var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
47 // Index format
48 var PAGEDATA_URL = 0;
49 var PAGEDATA_TITLE = 1;
50 var PAGEDATA_DESC = 2;
51 var PAGEDATA_IMG = 3;
52 var PAGEINFO_DATETIME = 0;
53 var PAGEINFO_FILESIZE = 1;
54 var PAGEINFO_CAT = 2;
56 // ----------------------------------------------------------------------------
57 // Helper Functions
58 // ----------------------------------------------------------------------------
60 // This function will return the value of a GET parameter
61 function getParam(paramName)
63 paramStr = document.location.search;
64 if (paramStr == "")
65 return "";
67 // remove '?' in front of paramStr
68 if (paramStr.charAt(0) == "?")
69 paramStr = paramStr.substr(1);
71 arg = (paramStr.split("&"));
72 for (i=0; i < arg.length; i++) {
73 arg_values = arg[i].split("=")
74 if (unescape(arg_values[0]) == paramName) {
75 if (UseUTF8 == 1 && self.decodeURIComponent) // check if decodeURIComponent() is defined
76 ret = decodeURIComponent(arg_values[1]);
77 else
78 ret = unescape(arg_values[1]); // IE 5.0 and older does not have decodeURI
79 return ret;
82 return "";
85 function getParamArray(paramName)
87 paramStr = document.location.search;
89 var retArray = new Array();
90 var retCount = 0;
92 if (paramStr == "")
93 return retArray;
95 // remove '?' in front of paramStr
96 if (paramStr.charAt(0) == "?")
97 paramStr = paramStr.substr(1);
99 arg = (paramStr.split("&"));
100 for (i=0; i < arg.length; i++)
102 arg_values = arg[i].split("=")
103 if (unescape(arg_values[0]) == paramName)
105 if (UseUTF8 == 1 && self.decodeURIComponent) // check if decodeURIComponent() is defined
106 ret = decodeURIComponent(arg_values[1]);
107 else
108 ret = unescape(arg_values[1]); // IE 5.0 and older does not have decodeURI
109 retArray[retCount] = ret;
110 retCount++;
113 return retArray;
116 // Compares the two values, used for sorting output results
117 // Results that match all search terms are put first, highest score
118 function SortCompare (a, b)
120 if (a[2] < b[2]) return 1;
121 else if (a[2] > b[2]) return -1;
122 else if (a[1] < b[1]) return 1;
123 else if (a[1] > b[1]) return -1;
124 else return 0;
127 function SortByDate(a, b)
129 if (pageinfo[a[0]][PAGEINFO_DATETIME] < pageinfo[b[0]][PAGEINFO_DATETIME]) return 1;
130 else if (pageinfo[a[0]][PAGEINFO_DATETIME] > pageinfo[b[0]][PAGEINFO_DATETIME]) return -1;
131 else return SortCompare(a, b);
134 function sw_compare(a, b)
136 if (a.charAt(0) == '-')
137 return 1;
139 if (b.charAt(0) == '-')
140 return -1;
142 return 0;
145 function pattern2regexp(pattern)
147 pattern = pattern.replace(/\#/g, "\\#");
148 pattern = pattern.replace(/\$/g, "\\$");
149 pattern = pattern.replace(/\./g, "\\.");
150 pattern = pattern.replace(/\*/g, "[\\d\\S]*");
151 pattern = pattern.replace(/\?/g, ".?");
152 return pattern;
155 function PrintHighlightDescription(line)
157 if (Highlighting == 0)
159 document.writeln(line);
160 return;
163 res = " " + line + " ";
164 for (i = 0; i < numwords; i++) {
165 if (RegExpSearchWords[i] == "")
166 continue;
168 if (SearchAsSubstring == 1)
169 res = res.replace(new RegExp("("+RegExpSearchWords[i]+")", "gi"), "[;:]$1[:;]");
170 else
171 res = res.replace(new RegExp("(\\W|^|\\b)("+RegExpSearchWords[i]+")(\\W|$|\\b)", "gi"), "$1[;:]$2[:;]$3");
173 // replace the marker text with the html text
174 // this is to avoid finding previous <span>'ed text.
175 res = res.replace(/\[;:\]/g, "<span class=\"highlight\">");
176 res = res.replace(/\[:;\]/g, "</span>");
177 document.writeln(res);
180 function PrintNumResults(num)
182 if (num == 0)
183 return STR_NO_RESULTS;
184 else if (num == 1)
185 return num + " " + STR_RESULT;
186 else
187 return num + " " + STR_RESULTS;
190 function AddParamToURL(url, paramStr)
192 // add GET parameters to URL depending on
193 // whether there are any existing parameters
194 if (url.indexOf("?") > -1)
195 return url + "&amp;" + paramStr;
196 else
197 return url + "?" + paramStr;
200 function SkipSearchWord(sw) {
201 if (searchWords[sw] != "") {
202 if (SkippedWords > 0)
203 SkippedOutputStr += ", ";
204 SkippedOutputStr += "\"<b>" + searchWords[sw] + "</b>\"";
205 searchWords[sw] = "";
209 function wordcasecmp(word1, word2) {
210 if (word1 == word2)
211 return 0;
212 else
213 return -1;
216 function htmlspecialchars(query) {
217 query = query.replace(/\&/g, "&#38;");
218 query = query.replace(/\</g, "&#60;");
219 query = query.replace(/\>/g, "&#62;");
220 query = query.replace(/\"/g, "&#34;");
221 query = query.replace(/\'/g, "&#39;");
222 return query;
225 function QueryEntities(query) {
226 query = query.replace(/\&/g, "&#38;");
227 query = query.replace(/\</g, "&#60;");
228 query = query.replace(/\>/g, "&#62;");
229 query = query.replace(/\'/g, "&#39;");
230 return query;
233 function FixQueryForAsianWords(query) {
234 currCharType = 0;
235 lastCharType = 0; // 0 is normal, 1 is hiragana, 2 is katakana, 3 is "han"
237 // check for hiragana/katakana splitting required
238 newquery = "";
239 for (i = 0; i < query.length; i++)
241 ch = query.charAt(i);
242 chVal = query.charCodeAt(i);
244 if (chVal >= 12352 && chVal <= 12447)
245 currCharType = 1;
246 else if (chVal >= 12448 && chVal <= 12543)
247 currCharType = 2;
248 else if (chVal >= 13312 && chVal <= 44031)
249 currCharType = 3;
250 else
251 currCharType = 0;
253 if (lastCharType != currCharType && ch != " ")
254 newquery += " ";
255 lastCharType = currCharType;
256 newquery += ch;
258 return newquery;
261 // ----------------------------------------------------------------------------
262 // Parameters initialisation (globals)
263 // ----------------------------------------------------------------------------
265 var query = getParam("zoom_query");
266 query = query.replace(/[\++]/g, " "); // replace the '+' with spaces
267 SearchAsSubstring = (query == query.replace(/[\"+]/g, " "));
268 query = query.replace(/[\"+]/g, " ");
270 var per_page = parseInt(getParam("zoom_per_page"));
271 if (isNaN(per_page)) per_page = 10;
273 var page = parseInt(getParam("zoom_page"));
274 if (isNaN(page)) page = 1;
276 var andq = parseInt(getParam("zoom_and"));
277 if (isNaN(andq))
279 if (typeof(DefaultToAnd) != "undefined" && DefaultToAnd == 1)
280 andq = 1;
281 else
282 andq = 0;
285 var cat = getParamArray("zoom_cat[]");
286 if (cat.length == 0)
288 cat[0] = parseInt(getParam("zoom_cat"));
289 if (isNaN(cat))
290 cat[0] = -1; // search all categories
292 var num_zoom_cats = cat.length;
295 // for sorting options. zero is default (relevance)
296 // 1 is sort by date (if date/time is available)
297 var sort = parseInt(getParam("zoom_sort"));
298 if (isNaN(sort)) sort = 0;
300 var SelfURL = "";
301 if (typeof(LinkBackURL) == "undefined")
303 SelfURL = document.location.href;
304 // strip off parameters and anchors
305 var paramIndex;
306 paramIndex = SelfURL.indexOf("?");
307 if (paramIndex > -1)
308 SelfURL = SelfURL.substr(0, paramIndex);
309 paramIndex = SelfURL.indexOf("#");
310 if (paramIndex > -1)
311 SelfURL = SelfURL.substr(0, paramIndex);
313 else
314 SelfURL = LinkBackURL;
315 // encode invalid URL characters
316 SelfURL = SelfURL.replace(/\</g, "&lt;");
317 SelfURL = SelfURL.replace(/\"/g, "&quot;");
319 var data = new Array();
320 var output = new Array();
322 target = "";
323 if (UseLinkTarget == 1)
324 target = " target=\"" + LinkTarget + "\" ";
326 // ----------------------------------------------------------------------------
327 // Main search function starts here
328 // ----------------------------------------------------------------------------
330 function ZoomSearch()
332 var loadingmsg = document.getElementById("loadingmsg");
333 if (loadingmsg) loadingmsg.style.display = "None";
334 if (UseCats)
335 NumCats = catnames.length;
337 if (Timing == 1) {
338 timeStart = new Date();
341 // Display the form
342 if (FormFormat > 0) {
343 document.writeln("<form method=\"get\" action=\"" + SelfURL + "\" class=\"zoom_searchform\">");
344 document.writeln("<input type=\"text\" name=\"zoom_query\" size=\"20\" value=\"" + htmlspecialchars(query) + "\" class=\"zoom_searchbox\" />");
345 document.writeln("<input type=\"submit\" value=\"" + STR_FORM_SUBMIT_BUTTON + "\" class=\"zoom_button\" /><br />");
346 if (FormFormat == 2) {
347 document.writeln("<span class=\"zoom_results_per_page\">" + STR_FORM_RESULTS_PER_PAGE + "\n");
348 document.writeln("<select name=\"zoom_per_page\">");
349 for (i = 0; i < PerPageOptions.length; i++) {
350 document.write("<option");
351 if (PerPageOptions[i] == per_page)
352 document.write(" selected=\"selected\"");
353 document.writeln(">" + PerPageOptions[i] + "</option>");
355 document.writeln("</select><br /><br /></span>");
356 if (UseCats) {
357 document.writeln("<span class=\"zoom_categories\">");
358 document.write(STR_FORM_CATEGORY + " ");
359 if (SearchMultiCats)
361 document.writeln("<ul>");
362 document.write("<li><input type=\"checkbox\" name=\"zoom_cat[]\" value=\"-1\"");
363 if (cat[0] == -1)
364 document.write(" checked=\"checked\"");
365 document.writeln(">" + STR_FORM_CATEGORY_ALL + "</input></li>");
366 for (i = 0; i < NumCats; i++)
368 document.write("<li><input type=\"checkbox\" name=\"zoom_cat[]\" value=\"" +i+ "\"");
369 if (cat[0] != -1)
371 for (catit = 0; catit < num_zoom_cats; catit++)
373 if (i == cat[catit])
375 document.write(" checked=\"checked\"");
376 break;
380 document.writeln(">"+catnames[i]+"</input></li>");
382 document.writeln("</ul><br /><br />");
384 else
386 document.write("<select name='zoom_cat[]'>");
387 // 'all cats option
388 document.write("<option value=\"-1\">" + STR_FORM_CATEGORY_ALL + "</option>");
389 for (i = 0; i < NumCats; i++) {
390 document.write("<option value=\"" + i + "\"");
391 if (i == cat[0])
392 document.write(" selected=\"selected\"");
393 document.writeln(">" + catnames[i] + "</option>");
395 document.writeln("</select>&nbsp;&nbsp;");
397 document.writeln("</span>");
399 document.writeln("<span class=\"zoom_match\">" + STR_FORM_MATCH + " ");
400 if (andq == 0) {
401 document.writeln("<input type=\"radio\" name=\"zoom_and\" value=\"0\" checked=\"checked\" />" + STR_FORM_ANY_SEARCH_WORDS);
402 document.writeln("<input type=\"radio\" name=\"zoom_and\" value=\"1\" />" + STR_FORM_ALL_SEARCH_WORDS);
403 } else {
404 document.writeln("<input type=\"radio\" name=\"zoom_and\" value=\"0\" />" + STR_FORM_ANY_SEARCH_WORDS);
405 document.writeln("<input type=\"radio\" name=\"zoom_and\" value=\"1\" checked=\"checked\" />" + STR_FORM_ALL_SEARCH_WORDS);
407 document.writeln("<input type=\"hidden\" name=\"zoom_sort\" value=\"" + sort + "\" />");
408 document.writeln("<br /><br /></span>");
410 else
412 document.writeln("<input type=\"hidden\" name=\"zoom_per_page\" value=\"" + per_page + "\" />");
413 document.writeln("<input type=\"hidden\" name=\"zoom_and\" value=\"" + andq + "\" />");
414 document.writeln("<input type=\"hidden\" name=\"zoom_sort\" value=\"" + sort + "\" />");
417 document.writeln("</form>");
420 // give up early if no search words provided
421 if (query.length == 0) {
422 //document.writeln("No search query entered.<br />");
423 if (ZoomInfo == 1)
424 document.writeln("<center><p><small>" + STR_POWEREDBY + " <a href=\"http://www.wrensoft.com/zoom/\" target=\"_blank\"><b>Zoom Search Engine</b></a></small></p></center>");
425 return;
428 if (MapAccents == 1) {
429 for (i = 0; i < NormalChars.length; i++) {
430 query = query.replace(AccentChars[i], NormalChars[i]);
434 // Special query processing required when SearchAsSubstring is enabled
435 if (SearchAsSubstring == 1 && UseUTF8 == 1)
436 query = FixQueryForAsianWords(query);
438 // prepare search query, strip quotes, trim whitespace
439 if (WordJoinChars.indexOf(".") == -1)
440 query = query.replace(/[\.+]/g, " ");
442 if (WordJoinChars.indexOf("-") == -1)
443 query = query.replace(/(\S)\-/g, "$1 ");
445 if (WordJoinChars.indexOf("_") == -1)
446 query = query.replace(/[\_+]/g, " ");
448 if (WordJoinChars.indexOf("'") == -1)
449 query = query.replace(/[\'+]/g, " ");
451 if (WordJoinChars.indexOf("#") == -1)
452 query = query.replace(/[\#+]/g, " ");
454 if (WordJoinChars.indexOf("$") == -1)
455 query = query.replace(/[\$+]/g, " ");
457 if (WordJoinChars.indexOf("&") == -1)
458 query = query.replace(/[\&+]/g, " ");
460 if (WordJoinChars.indexOf(":") == -1)
461 query = query.replace(/[\:+]/g, " ");
463 if (WordJoinChars.indexOf(",") == -1)
464 query = query.replace(/[\,+]/g, " ");
466 if (WordJoinChars.indexOf("/") == -1)
467 query = query.replace(/[\/+]/g, " ");
469 if (WordJoinChars.indexOf("\\") == -1)
470 query = query.replace(/[\\+]/g, " ");
472 // substitute multiple whitespace chars to single character
473 // also strip any of the wordjoinchars if followed immediately by a space
474 query = query.replace(/[\s\(\)\^\[\]\|\+\{\}\%]+|[\-._',:&\/\\\\](\s|$)/g, " ");
476 // trim trailing/leading whitespace
477 query = query.replace(/^\s*|\s*$/g,"");
479 var queryForHTML = htmlspecialchars(query);
480 var queryForSearch;
481 if (ToLowerSearchWords == 1)
482 queryForSearch = query.toLowerCase();
483 else
484 queryForSearch = query;
485 queryForSearch = htmlspecialchars(queryForSearch);
487 // split search phrase into words
488 searchWords = queryForSearch.split(" "); // split by spaces.
490 // Sort search words if there are negative signs
491 if (queryForSearch.indexOf("-") != -1)
492 searchWords.sort(sw_compare);
494 var query_zoom_cats = "";
496 document.write("<div class=\"searchheading\">" + STR_RESULTS_FOR + " " + queryForHTML);
497 if (UseCats) {
498 if (cat[0] == -1)
500 document.writeln(" " + STR_RESULTS_IN_ALL_CATEGORIES);
501 query_zoom_cats = "&amp;zoom_cat%5B%5D=-1";
503 else
505 document.writeln(" " + STR_RESULTS_IN_CATEGORY + " ");
506 for (catit = 0; catit < num_zoom_cats; catit++)
508 if (catit > 0)
509 document.write(", ");
510 document.write("\"" + catnames[cat[catit]] + "\"");
511 query_zoom_cats += "&amp;zoom_cat%5B%5D="+cat[catit];
515 document.writeln("<br /><br /></div>");
517 document.writeln("<div class=\"results\">");
519 numwords = searchWords.length;
520 kw_ptr = 0;
521 outputline = 0;
522 ipage = 0;
523 matches = 0;
524 var SWord;
525 pagesCount = pageinfo.length;
527 exclude_count = 0;
528 ExcludeTerm = 0;
530 // Initialise a result table the size of all pages
531 res_table = new Array(pagesCount);
532 for (i = 0; i < pagesCount; i++)
534 res_table[i] = new Array(3);
535 res_table[i][0] = 0;
536 res_table[i][1] = 0;
537 res_table[i][2] = 0;
540 var UseWildCards = new Array(numwords);
542 for (sw = 0; sw < numwords; sw++) {
544 UseWildCards[sw] = 0;
546 if (skipwords) {
547 // check min length
548 if (searchWords[sw].length < MinWordLen) {
549 SkipSearchWord(sw);
550 continue;
552 // check skip word list
553 for (i = 0; i < skipwords.length; i++) {
554 if (searchWords[sw] == skipwords[i]) {
555 SkipSearchWord(sw);
556 break;
561 if (searchWords[sw].indexOf("*") == -1 && searchWords[sw].indexOf("?") == -1) {
562 UseWildCards[sw] = 0;
563 } else {
564 UseWildCards[sw] = 1;
565 RegExpSearchWords[sw] = pattern2regexp(searchWords[sw]);
568 if (Highlighting == 1 && UseWildCards[sw] == 0)
569 RegExpSearchWords[sw] = searchWords[sw];
572 // Begin searching...
573 for (sw = 0; sw < numwords; sw++) {
575 if (searchWords[sw] == "") {
576 SkippedWords++;
577 continue;
580 if (searchWords[sw].charAt(0) == '-')
582 searchWords[sw] = searchWords[sw].substr(1);
583 ExcludeTerm = 1;
584 exclude_count++;
587 if (UseWildCards[sw] == 1) {
588 if (SearchAsSubstring == 0)
589 pattern = "^" + RegExpSearchWords[sw] + "$";
590 else
591 pattern = RegExpSearchWords[sw];
592 re = new RegExp(pattern, "g");
595 for (kw_ptr = 0; kw_ptr < dictwords.length; kw_ptr++) {
597 data = dictwords[kw_ptr].split(" ");
599 if (UseWildCards[sw] == 0) {
600 if (SearchAsSubstring == 0)
601 match_result = wordcasecmp(data[0], searchWords[sw]);
602 else
603 match_result = data[0].indexOf(searchWords[sw]);
604 } else
605 match_result = data[0].search(re);
608 if (match_result != -1) {
609 // keyword found, include it in the output list
610 for (kw = 1; kw < data.length; kw += 2) {
611 // check if page is already in output list
612 pageexists = 0;
613 ipage = data[kw];
615 if (ExcludeTerm == 1)
617 // we clear out the score entry so that it'll be excluded in the filter stage
618 res_table[ipage][0] = 0;
620 else if (res_table[ipage][0] == 0) {
621 matches++;
622 res_table[ipage][0] += parseInt(data[kw+1]);
624 else {
626 if (res_table[ipage][0] > 10000) {
627 // take it easy if its too big to prevent gigantic scores
628 res_table[ipage][0] += 1;
629 } else {
630 res_table[ipage][0] += parseInt(data[kw+1]); // add in score
631 res_table[ipage][0] *= 2; // double score as we have two words matching
634 res_table[ipage][1] += 1;
635 // store the 'and' user search terms matched' value
636 if (res_table[ipage][2] == sw || res_table[ipage][2] == sw-SkippedWords-exclude_count)
637 res_table[ipage][2] += 1;
640 if (UseWildCards[sw] == 0 && SearchAsSubstring == 0)
641 break; // this search word was found, so skip to next
646 if (SkippedWords > 0)
647 document.writeln("<div class=\"summary\">" + STR_SKIPPED_FOLLOWING_WORDS + " " + SkippedOutputStr + ".<br /><br /></div>");
649 // Count number of output lines that match ALL search terms
650 oline = 0;
651 fullmatches = 0;
652 output = new Array();
653 var full_numwords = numwords - SkippedWords - exclude_count;
654 for (i = 0; i < pagesCount; i++) {
655 IsFiltered = false;
656 if (res_table[i][0] > 0) {
657 if (UseCats && cat[0] != -1) {
658 // using cats and not doing an "all cats" search
659 if (SearchMultiCats) {
660 for (cati = 0; cati < num_zoom_cats; cati++) {
661 if (pageinfo[i][PAGEINFO_CAT].charAt(cat[cati]) == "1")
662 break;
664 if (cati == num_zoom_cats)
665 IsFiltered = true;
667 else {
668 if (pageinfo[i][PAGEINFO_CAT].charAt(cat[0]) == "0") {
669 IsFiltered = true;
673 if (IsFiltered == false) {
674 if (res_table[i][2] >= full_numwords) {
675 fullmatches++;
676 } else {
677 if (andq == 1)
678 IsFiltered = true;
681 if (IsFiltered == false) {
682 // copy if not filtered out
683 output[oline] = new Array(3);
684 output[oline][0] = i;
685 output[oline][1] = res_table[i][0];
686 output[oline][2] = res_table[i][1];
687 oline++;
691 matches = oline;
693 // Sort results in order of score, use "SortCompare" function
694 if (matches > 1)
696 if (sort == 1 && UseDateTime == 1)
697 output.sort(SortByDate); // sort by date
698 else
699 output.sort(SortCompare); // sort by relevance
702 // prepare queryForURL
703 var queryForURL = query.replace(/\s/g, "+");
704 if (UseUTF8 == 1 && self.encodeURIComponent)
705 queryForURL = encodeURIComponent(queryForURL);
706 else
707 queryForURL = escape(queryForURL);
709 //Display search result information
710 document.writeln("<div class=\"summary\">");
711 if (matches == 0)
712 document.writeln(STR_SUMMARY_NO_RESULTS_FOUND + "<br />");
713 else if (numwords > 1 && andq == 0) {
714 //OR
715 SomeTermMatches = matches - fullmatches;
716 document.writeln(PrintNumResults(fullmatches) + " " + STR_SUMMARY_FOUND_CONTAINING_ALL_TERMS + " ");
717 if (SomeTermMatches > 0)
718 document.writeln(PrintNumResults(SomeTermMatches) + " " + STR_SUMMARY_FOUND_CONTAINING_SOME_TERMS);
719 document.writeln("<br />");
721 else if (numwords > 1 && andq == 1) //AND
722 document.writeln(PrintNumResults(fullmatches) + " " + STR_SUMMARY_FOUND_CONTAINING_ALL_TERMS + "<br />");
723 else
724 document.writeln(PrintNumResults(matches) + " " + STR_SUMMARY_FOUND + "<br />");
726 document.writeln("</div>\n");
728 // number of pages of results
729 num_pages = Math.ceil(matches / per_page);
730 if (num_pages > 1)
731 document.writeln("<div class=\"result_pagescount\"><br />" + num_pages + " " + STR_PAGES_OF_RESULTS + "</div>\n");
733 // Show recommended links if any
734 if (Recommended == 1)
736 num_recs_found = 0;
737 rec_count = recommended.length;
738 for (rl = 0; rl < rec_count && num_recs_found < RecommendedMax; rl++)
740 sep = recommended[rl].lastIndexOf(" ");
741 if (sep > -1)
743 rec_word = recommended[rl].slice(0, sep);
744 rec_idx = parseInt(recommended[rl].slice(sep));
745 for (sw = 0; sw <= numwords; sw++)
747 if (sw == numwords)
749 match_result = wordcasecmp(rec_word, queryForSearch);
751 else
753 if (UseWildCards[sw] == 1)
755 if (SearchAsSubstring == 0)
756 pattern = "^" + RegExpSearchWords[sw] + "$";
757 else
758 pattern = RegExpSearchWords[sw];
759 re = new RegExp(pattern, "g");
760 match_result = rec_word.search(re);
762 else if (SearchAsSubstring == 0)
764 match_result = wordcasecmp(rec_word, searchWords[sw]);
766 else
767 match_result = rec_word.indexOf(searchWords[sw]);
769 if (match_result != -1)
771 if (num_recs_found == 0)
773 document.writeln("<div class=\"recommended\">");
774 document.writeln("<div class=\"recommended_heading\">" + STR_RECOMMENDED + "</div>");
776 pgurl = pagedata[rec_idx][PAGEDATA_URL];
777 pgtitle = pagedata[rec_idx][PAGEDATA_TITLE];
778 pgdesc = pagedata[rec_idx][PAGEDATA_DESC];
779 urlLink = pgurl;
780 if (GotoHighlight == 1)
782 if (SearchAsSubstring == 1)
783 urlLink = AddParamToURL(urlLink, "zoom_highlightsub=" + queryForURL);
784 else
785 urlLink = AddParamToURL(urlLink, "zoom_highlight=" + queryForURL);
787 if (PdfHighlight == 1)
789 if (urlLink.indexOf(".pdf") != -1)
790 urlLink = urlLink+"#search=&quot;"+query+"&quot;";
792 document.writeln("<div class=\"recommend_block\">");
793 document.writeln("<div class=\"recommend_title\">");
794 document.writeln("<a href=\"" + urlLink + "\"" + target + ">");
795 if (pgtitle.length > 1)
796 PrintHighlightDescription(pgtitle);
797 else
798 PrintHighlightDescription(pgurl);
799 document.writeln("</a></div>");
800 document.writeln("<div class=\"recommend_description\">")
801 PrintHighlightDescription(pgdesc);
802 document.writeln("</div>");
803 document.writeln("<div class=\"recommend_infoline\">" + pgurl + "</div>");
804 document.writeln("</div>");
805 num_recs_found++;
806 break;
811 if (num_recs_found > 0)
812 document.writeln("</div");
815 // Show sorting options
816 if (matches > 1)
818 if (UseDateTime == 1)
820 document.writeln("<div class=\"sorting\">");
821 if (sort == 1)
822 document.writeln("<a href=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + page + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=0\">" + STR_SORTBY_RELEVANCE + "</a> / <b>" + STR_SORTEDBY_DATE + "</b>");
823 else
824 document.writeln("<b>" + STR_SORTEDBY_RELEVANCE + "</b> / <a href=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + page + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=1\">" + STR_SORTBY_DATE + "</a>");
825 document.writeln("</div>");
829 // determine current line of result from the output array
830 if (page == 1) {
831 arrayline = 0;
832 } else {
833 arrayline = ((page - 1) * per_page);
836 // the last result to show on this page
837 result_limit = arrayline + per_page;
839 // display the results
840 while (arrayline < matches && arrayline < result_limit) {
841 ipage = output[arrayline][0];
842 score = output[arrayline][1];
844 pgurl = pagedata[ipage][PAGEDATA_URL];
845 pgtitle = pagedata[ipage][PAGEDATA_TITLE];
846 pgdesc = pagedata[ipage][PAGEDATA_DESC];
847 pgimage = pagedata[ipage][PAGEDATA_IMG];
848 pgdate = pageinfo[ipage][PAGEINFO_DATETIME];
849 filesize = pageinfo[ipage][PAGEINFO_FILESIZE];
850 filesize = Math.ceil(filesize / 1024);
851 if (filesize < 1)
852 filesize = 1;
853 catpage = pageinfo[ipage][PAGEINFO_CAT];
855 urlLink = pgurl;
856 if (GotoHighlight == 1)
858 if (SearchAsSubstring == 1)
859 urlLink = AddParamToURL(urlLink, "zoom_highlightsub=" + queryForURL);
860 else
861 urlLink = AddParamToURL(urlLink, "zoom_highlight=" + queryForURL);
863 if (PdfHighlight == 1)
865 if (urlLink.indexOf(".pdf") != -1)
866 urlLink = urlLink+"#search=&quot;"+query+"&quot;";
869 if (arrayline % 2 == 0)
870 document.writeln("<div class=\"result_block\">");
871 else
872 document.writeln("<div class=\"result_altblock\">");
874 if (UseZoomImage == 1)
876 if (pgimage.length > 1)
878 document.writeln("<div class=\"result_image\">");
879 document.writeln("<a href=\"" + urlLink + "\"" + target + "><img src=\"" + pgimage + "\" class=\"result_image\"></a>");
880 document.writeln("</div>");
884 document.writeln("<div class=\"result_title\">");
885 if (DisplayNumber == 1)
886 document.writeln("<b>" + (arrayline+1) + ".</b>&nbsp;");
888 if (DisplayTitle == 1)
890 document.writeln("<a href=\"" + urlLink + "\"" + target + ">");
891 PrintHighlightDescription(pgtitle);
892 document.writeln("</a>");
894 else
895 document.writeln("<a href=\"" + urlLink + "\"" + target + ">" + pgurl + "</a>");
897 if (UseCats)
899 document.write("<span class=\"category\">");
900 for (cati = 0; cati < NumCats; cati++)
902 if (catpage.charAt(cati) == "1")
903 document.write(" ["+catnames[cati]+"]");
905 document.writeln("</span>");
907 document.writeln("</div>");
909 if (DisplayMetaDesc == 1)
911 // print meta description
912 document.writeln("<div class=\"description\">");
913 PrintHighlightDescription(pgdesc);
914 document.writeln("</div>\n");
917 info_str = "";
919 if (DisplayTerms == 1)
920 info_str += STR_RESULT_TERMS_MATCHED + " " + output[arrayline][2];
922 if (DisplayScore == 1) {
923 if (info_str.length > 0)
924 info_str += "&nbsp; - &nbsp;";
925 info_str += STR_RESULT_SCORE + " " + score;
928 if (DisplayDate == 1 && pgdate > 0)
930 datetime = new Date(pgdate*1000);
931 if (info_str.length > 0)
932 info_str += "&nbsp; - &nbsp;";
933 info_str += datetime.getDate() + " " + months[datetime.getMonth()] + " " + datetime.getFullYear();
936 if (DisplayFilesize == 1) {
937 if (info_str.length > 0)
938 info_str += "&nbsp; - &nbsp;";
939 info_str += filesize + "k";
942 if (DisplayURL == 1) {
943 if (info_str.length > 0)
944 info_str += "&nbsp; - &nbsp;";
945 info_str += STR_RESULT_URL + " " + pgurl;
948 document.writeln("<div class=\"infoline\">");
949 document.writeln(info_str);
950 document.writeln("</div></div>\n");
951 arrayline++;
954 // Show links to other result pages
955 if (num_pages > 1) {
956 // 10 results to the left of the current page
957 start_range = page - 10;
958 if (start_range < 1)
959 start_range = 1;
961 // 10 to the right
962 end_range = page + 10;
963 if (end_range > num_pages)
964 end_range = num_pages;
966 document.writeln("<div class=\"result_pages\">" + STR_RESULT_PAGES + " ");
967 if (page > 1)
968 document.writeln("<a href=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + (page-1) + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=" + sort + "\">&lt;&lt; " + STR_RESULT_PAGES_PREVIOUS + "</a> ");
969 for (i = start_range; i <= end_range; i++)
971 if (i == page)
972 document.writeln(page + " ");
973 else
974 document.writeln("<a href=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + i + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=" + sort + "\">" + i + "</a> ");
976 if (page != num_pages)
977 document.writeln("<a href=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + (page+1) + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=" + sort + "\">" + STR_RESULT_PAGES_NEXT + " &gt;&gt;</a> ");
978 document.writeln("</div>");
981 document.writeln("</div>"); // end results style tag
983 if (Timing == 1) {
984 timeEnd = new Date();
985 timeDifference = timeEnd - timeStart;
986 document.writeln("<div class=\"searchtime\"><br /><br />" + STR_SEARCH_TOOK + " " + (timeDifference/1000) + " " + STR_SECONDS + ".</div>\n");
989 if (ZoomInfo == 1)
990 document.writeln("<center><p><small>" + STR_POWEREDBY + " <a href=\"http://www.wrensoft.com/zoom/\" target=\"_blank\"><b>Zoom Search Engine</b></a></small></p></center>");