1 // ----------------------------------------------------------------------------
2 // Zoom Search Engine 5.0 (30/4/2007)
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.
7 // email: zoom@wrensoft.com
8 // www: http://www.wrensoft.com
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
37 var PerPageOptions
= new Array(10, 20, 50, 100);
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');
49 var PAGEDATA_TITLE
= 1;
50 var PAGEDATA_DESC
= 2;
52 var PAGEINFO_DATETIME
= 0;
53 var PAGEINFO_FILESIZE
= 1;
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // This function will return the value of a GET parameter
61 function getParam(paramName
)
63 paramStr
= document
.location
.search
;
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]);
78 ret
= unescape(arg_values
[1]); // IE 5.0 and older does not have decodeURI
85 function getParamArray(paramName
)
87 paramStr
= document
.location
.search
;
89 var retArray
= new Array();
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]);
108 ret
= unescape(arg_values
[1]); // IE 5.0 and older does not have decodeURI
109 retArray
[retCount
] = ret
;
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;
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) == '-')
139 if (b
.charAt(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, ".?");
155 function PrintHighlightDescription(line
)
157 if (Highlighting
== 0)
159 document
.writeln(line
);
163 res
= " " + line
+ " ";
164 for (i
= 0; i
< numwords
; i
++) {
165 if (RegExpSearchWords
[i
] == "")
168 if (SearchAsSubstring
== 1)
169 res
= res
.replace(new RegExp("("+RegExpSearchWords
[i
]+")", "gi"), "[;:]$1[:;]");
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
)
183 return STR_NO_RESULTS
;
185 return num
+ " " + STR_RESULT
;
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
+ "&" + paramStr
;
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
) {
216 function htmlspecialchars(query
) {
217 query
= query
.replace(/\&/g, "&");
218 query
= query
.replace(/\</g, "<");
219 query
= query
.replace(/\>/g, ">");
220 query
= query
.replace(/\"/g, """);
221 query
= query
.replace(/\'/g, "'");
225 function QueryEntities(query
) {
226 query
= query
.replace(/\&/g, "&");
227 query
= query
.replace(/\</g, "<");
228 query
= query
.replace(/\>/g, ">");
229 query
= query
.replace(/\'/g, "'");
233 function FixQueryForAsianWords(query
) {
235 lastCharType
= 0; // 0 is normal, 1 is hiragana, 2 is katakana, 3 is "han"
237 // check for hiragana/katakana splitting required
239 for (i
= 0; i
< query
.length
; i
++)
241 ch
= query
.charAt(i
);
242 chVal
= query
.charCodeAt(i
);
244 if (chVal
>= 12352 && chVal
<= 12447)
246 else if (chVal
>= 12448 && chVal
<= 12543)
248 else if (chVal
>= 13312 && chVal
<= 44031)
253 if (lastCharType
!= currCharType
&& ch
!= " ")
255 lastCharType
= currCharType
;
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"));
279 if (typeof(DefaultToAnd
) != "undefined" && DefaultToAnd
== 1)
285 var cat
= getParamArray("zoom_cat[]");
288 cat
[0] = parseInt(getParam("zoom_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;
301 if (typeof(LinkBackURL
) == "undefined")
303 SelfURL
= document
.location
.href
;
304 // strip off parameters and anchors
306 paramIndex
= SelfURL
.indexOf("?");
308 SelfURL
= SelfURL
.substr(0, paramIndex
);
309 paramIndex
= SelfURL
.indexOf("#");
311 SelfURL
= SelfURL
.substr(0, paramIndex
);
314 SelfURL
= LinkBackURL
;
315 // encode invalid URL characters
316 SelfURL
= SelfURL
.replace(/\</g, "<");
317 SelfURL
= SelfURL
.replace(/\"/g, """);
319 var data
= new Array();
320 var output
= new Array();
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";
335 NumCats
= catnames
.length
;
338 timeStart
= new Date();
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>");
357 document
.writeln("<span class=\"zoom_categories\">");
358 document
.write(STR_FORM_CATEGORY
+ " ");
361 document
.writeln("<ul>");
362 document
.write("<li><input type=\"checkbox\" name=\"zoom_cat[]\" value=\"-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
+ "\"");
371 for (catit
= 0; catit
< num_zoom_cats
; catit
++)
375 document
.write(" checked=\"checked\"");
380 document
.writeln(">"+catnames
[i
]+"</input></li>");
382 document
.writeln("</ul><br /><br />");
386 document
.write("<select name='zoom_cat[]'>");
388 document
.write("<option value=\"-1\">" + STR_FORM_CATEGORY_ALL
+ "</option>");
389 for (i
= 0; i
< NumCats
; i
++) {
390 document
.write("<option value=\"" + i
+ "\"");
392 document
.write(" selected=\"selected\"");
393 document
.writeln(">" + catnames
[i
] + "</option>");
395 document
.writeln("</select> ");
397 document
.writeln("</span>");
399 document
.writeln("<span class=\"zoom_match\">" + STR_FORM_MATCH
+ " ");
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
);
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>");
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 />");
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>");
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
);
481 if (ToLowerSearchWords
== 1)
482 queryForSearch
= query
.toLowerCase();
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
);
500 document
.writeln(" " + STR_RESULTS_IN_ALL_CATEGORIES
);
501 query_zoom_cats
= "&zoom_cat%5B%5D=-1";
505 document
.writeln(" " + STR_RESULTS_IN_CATEGORY
+ " ");
506 for (catit
= 0; catit
< num_zoom_cats
; catit
++)
509 document
.write(", ");
510 document
.write("\"" + catnames
[cat
[catit
]] + "\"");
511 query_zoom_cats
+= "&zoom_cat%5B%5D="+cat
[catit
];
515 document
.writeln("<br /><br /></div>");
517 document
.writeln("<div class=\"results\">");
519 numwords
= searchWords
.length
;
525 pagesCount
= pageinfo
.length
;
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);
540 var UseWildCards
= new Array(numwords
);
542 for (sw
= 0; sw
< numwords
; sw
++) {
544 UseWildCards
[sw
] = 0;
548 if (searchWords
[sw
].length
< MinWordLen
) {
552 // check skip word list
553 for (i
= 0; i
< skipwords
.length
; i
++) {
554 if (searchWords
[sw
] == skipwords
[i
]) {
561 if (searchWords
[sw
].indexOf("*") == -1 && searchWords
[sw
].indexOf("?") == -1) {
562 UseWildCards
[sw
] = 0;
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
] == "") {
580 if (searchWords
[sw
].charAt(0) == '-')
582 searchWords
[sw
] = searchWords
[sw
].substr(1);
587 if (UseWildCards
[sw
] == 1) {
588 if (SearchAsSubstring
== 0)
589 pattern
= "^" + RegExpSearchWords
[sw
] + "$";
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
]);
603 match_result
= data
[0].indexOf(searchWords
[sw
]);
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
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) {
622 res_table
[ipage
][0] += parseInt(data
[kw
+1]);
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;
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
652 output
= new Array();
653 var full_numwords
= numwords
- SkippedWords
- exclude_count
;
654 for (i
= 0; i
< pagesCount
; i
++) {
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")
664 if (cati
== num_zoom_cats
)
668 if (pageinfo
[i
][PAGEINFO_CAT
].charAt(cat
[0]) == "0") {
673 if (IsFiltered
== false) {
674 if (res_table
[i
][2] >= full_numwords
) {
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];
693 // Sort results in order of score, use "SortCompare" function
696 if (sort
== 1 && UseDateTime
== 1)
697 output
.sort(SortByDate
); // sort by date
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
);
707 queryForURL
= escape(queryForURL
);
709 //Display search result information
710 document
.writeln("<div class=\"summary\">");
712 document
.writeln(STR_SUMMARY_NO_RESULTS_FOUND
+ "<br />");
713 else if (numwords
> 1 && andq
== 0) {
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 />");
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
);
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)
737 rec_count
= recommended
.length
;
738 for (rl
= 0; rl
< rec_count
&& num_recs_found
< RecommendedMax
; rl
++)
740 sep
= recommended
[rl
].lastIndexOf(" ");
743 rec_word
= recommended
[rl
].slice(0, sep
);
744 rec_idx
= parseInt(recommended
[rl
].slice(sep
));
745 for (sw
= 0; sw
<= numwords
; sw
++)
749 match_result
= wordcasecmp(rec_word
, queryForSearch
);
753 if (UseWildCards
[sw
] == 1)
755 if (SearchAsSubstring
== 0)
756 pattern
= "^" + RegExpSearchWords
[sw
] + "$";
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
]);
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
];
780 if (GotoHighlight
== 1)
782 if (SearchAsSubstring
== 1)
783 urlLink
= AddParamToURL(urlLink
, "zoom_highlightsub=" + queryForURL
);
785 urlLink
= AddParamToURL(urlLink
, "zoom_highlight=" + queryForURL
);
787 if (PdfHighlight
== 1)
789 if (urlLink
.indexOf(".pdf") != -1)
790 urlLink
= urlLink
+"#search=""+query
+""";
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
);
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>");
811 if (num_recs_found
> 0)
812 document
.writeln("</div");
815 // Show sorting options
818 if (UseDateTime
== 1)
820 document
.writeln("<div class=\"sorting\">");
822 document
.writeln("<a href=\"" + SelfURL
+ "?zoom_query=" + queryForURL
+ "&zoom_page=" + page
+ "&zoom_per_page=" + per_page
+ query_zoom_cats
+ "&zoom_and=" + andq
+ "&zoom_sort=0\">" + STR_SORTBY_RELEVANCE
+ "</a> / <b>" + STR_SORTEDBY_DATE
+ "</b>");
824 document
.writeln("<b>" + STR_SORTEDBY_RELEVANCE
+ "</b> / <a href=\"" + SelfURL
+ "?zoom_query=" + queryForURL
+ "&zoom_page=" + page
+ "&zoom_per_page=" + per_page
+ query_zoom_cats
+ "&zoom_and=" + andq
+ "&zoom_sort=1\">" + STR_SORTBY_DATE
+ "</a>");
825 document
.writeln("</div>");
829 // determine current line of result from the output array
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);
853 catpage
= pageinfo
[ipage
][PAGEINFO_CAT
];
856 if (GotoHighlight
== 1)
858 if (SearchAsSubstring
== 1)
859 urlLink
= AddParamToURL(urlLink
, "zoom_highlightsub=" + queryForURL
);
861 urlLink
= AddParamToURL(urlLink
, "zoom_highlight=" + queryForURL
);
863 if (PdfHighlight
== 1)
865 if (urlLink
.indexOf(".pdf") != -1)
866 urlLink
= urlLink
+"#search=""+query
+""";
869 if (arrayline
% 2 == 0)
870 document
.writeln("<div class=\"result_block\">");
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> ");
888 if (DisplayTitle
== 1)
890 document
.writeln("<a href=\"" + urlLink
+ "\"" + target
+ ">");
891 PrintHighlightDescription(pgtitle
);
892 document
.writeln("</a>");
895 document
.writeln("<a href=\"" + urlLink
+ "\"" + target
+ ">" + pgurl
+ "</a>");
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");
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
+= " - ";
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
+= " - ";
933 info_str
+= datetime
.getDate() + " " + months
[datetime
.getMonth()] + " " + datetime
.getFullYear();
936 if (DisplayFilesize
== 1) {
937 if (info_str
.length
> 0)
938 info_str
+= " - ";
939 info_str
+= filesize
+ "k";
942 if (DisplayURL
== 1) {
943 if (info_str
.length
> 0)
944 info_str
+= " - ";
945 info_str
+= STR_RESULT_URL
+ " " + pgurl
;
948 document
.writeln("<div class=\"infoline\">");
949 document
.writeln(info_str
);
950 document
.writeln("</div></div>\n");
954 // Show links to other result pages
956 // 10 results to the left of the current page
957 start_range
= page
- 10;
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
+ " ");
968 document
.writeln("<a href=\"" + SelfURL
+ "?zoom_query=" + queryForURL
+ "&zoom_page=" + (page
-1) + "&zoom_per_page=" + per_page
+ query_zoom_cats
+ "&zoom_and=" + andq
+ "&zoom_sort=" + sort
+ "\"><< " + STR_RESULT_PAGES_PREVIOUS
+ "</a> ");
969 for (i
= start_range
; i
<= end_range
; i
++)
972 document
.writeln(page
+ " ");
974 document
.writeln("<a href=\"" + SelfURL
+ "?zoom_query=" + queryForURL
+ "&zoom_page=" + i
+ "&zoom_per_page=" + per_page
+ query_zoom_cats
+ "&zoom_and=" + andq
+ "&zoom_sort=" + sort
+ "\">" + i
+ "</a> ");
976 if (page
!= num_pages
)
977 document
.writeln("<a href=\"" + SelfURL
+ "?zoom_query=" + queryForURL
+ "&zoom_page=" + (page
+1) + "&zoom_per_page=" + per_page
+ query_zoom_cats
+ "&zoom_and=" + andq
+ "&zoom_sort=" + sort
+ "\">" + STR_RESULT_PAGES_NEXT
+ " >></a> ");
978 document
.writeln("</div>");
981 document
.writeln("</div>"); // end results style tag
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");
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>");