home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / system / diskche / diskcheckup.exe / HELP / zoom_search.js < prev   
Text File  |  2007-10-30  |  36KB  |  993 lines

  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
  11. //
  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.
  16. //
  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. // ----------------------------------------------------------------------------
  24.  
  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>");
  28.  
  29. document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=" + Charset + "\">");
  30.  
  31. // ----------------------------------------------------------------------------
  32. // Settings (change if necessary)
  33. // ----------------------------------------------------------------------------
  34.  
  35. // The options available in the dropdown menu for number of results
  36. // per page
  37. var PerPageOptions = new Array(10, 20, 50, 100);
  38.  
  39. // Globals
  40. var SkippedWords = 0;
  41. var searchWords = new Array();
  42. var RegExpSearchWords = new Array();
  43. var SkippedOutputStr = "";
  44.  
  45. var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
  46.  
  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;
  55.  
  56. // ----------------------------------------------------------------------------
  57. // Helper Functions
  58. // ----------------------------------------------------------------------------
  59.  
  60. // This function will return the value of a GET parameter
  61. function getParam(paramName)
  62. {
  63.     paramStr = document.location.search;
  64.     if (paramStr == "")
  65.         return "";
  66.  
  67.     // remove '?' in front of paramStr
  68.     if (paramStr.charAt(0) == "?")
  69.         paramStr = paramStr.substr(1);
  70.  
  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;
  80.         }
  81.     }
  82.     return "";
  83. }
  84.  
  85. function getParamArray(paramName)
  86. {
  87.     paramStr = document.location.search;
  88.  
  89.     var retArray = new Array();
  90.     var retCount = 0;
  91.  
  92.     if (paramStr == "")
  93.         return retArray;
  94.  
  95.     // remove '?' in front of paramStr
  96.     if (paramStr.charAt(0) == "?")
  97.         paramStr = paramStr.substr(1);
  98.  
  99.     arg = (paramStr.split("&"));
  100.     for (i=0; i < arg.length; i++) 
  101.     {
  102.         arg_values = arg[i].split("=")
  103.         if (unescape(arg_values[0]) == paramName) 
  104.         {
  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++;            
  111.         }
  112.     }
  113.     return retArray;    
  114. }
  115.  
  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)
  119. {
  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;
  125. }
  126.  
  127. function SortByDate(a, b)
  128. {    
  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);
  132. }
  133.  
  134. function sw_compare(a, b)
  135. {
  136.     if (a.charAt(0) == '-') 
  137.         return 1;
  138.     
  139.     if (b.charAt(0) == '-') 
  140.         return -1;
  141.     
  142.     return 0;
  143. }
  144.  
  145. function pattern2regexp(pattern)
  146. {
  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;
  153. }
  154.  
  155. function PrintHighlightDescription(line) 
  156. {
  157.     if (Highlighting == 0)
  158.     {
  159.         document.writeln(line);
  160.         return;
  161.     }
  162.         
  163.     res = " " + line + " ";
  164.     for (i = 0; i < numwords; i++) {
  165.         if (RegExpSearchWords[i] == "")
  166.             continue;
  167.  
  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");
  172.     }
  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);
  178. }
  179.  
  180. function PrintNumResults(num)
  181. {
  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;
  188. }
  189.  
  190. function AddParamToURL(url, paramStr)
  191. {
  192.     // add GET parameters to URL depending on 
  193.     // whether there are any existing parameters
  194.     if (url.indexOf("?") > -1)    
  195.         return url + "&" + paramStr;
  196.     else        
  197.         return url + "?" + paramStr;            
  198. }
  199.  
  200. function SkipSearchWord(sw) {
  201.     if (searchWords[sw] != "") {
  202.         if (SkippedWords > 0)
  203.             SkippedOutputStr += ", ";
  204.         SkippedOutputStr += "\"<b>" + searchWords[sw] + "</b>\"";
  205.         searchWords[sw] = "";
  206.     }
  207. }
  208.  
  209. function wordcasecmp(word1, word2) {
  210.     if (word1 == word2)
  211.         return 0;
  212.     else
  213.         return -1;    
  214. }
  215.  
  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, "'");
  222.     return query;
  223. }
  224.  
  225. function QueryEntities(query) {    
  226.     query = query.replace(/\&/g, "&");    
  227.     query = query.replace(/\</g, "<");
  228.     query = query.replace(/\>/g, ">");
  229.     query = query.replace(/\'/g, "'");    
  230.     return query;
  231. }
  232.  
  233. function FixQueryForAsianWords(query) {
  234.     currCharType = 0;
  235.     lastCharType = 0;    // 0 is normal, 1 is hiragana, 2 is katakana, 3 is "han"
  236.     
  237.     // check for hiragana/katakana splitting required
  238.     newquery = "";
  239.     for (i = 0; i < query.length; i++)
  240.     {
  241.         ch = query.charAt(i);
  242.         chVal = query.charCodeAt(i);
  243.         
  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;
  252.                         
  253.         if (lastCharType != currCharType && ch != " ")
  254.             newquery += " ";            
  255.         lastCharType = currCharType;                
  256.         newquery += ch;
  257.     }
  258.     return newquery;
  259. }
  260.  
  261. // ----------------------------------------------------------------------------
  262. // Parameters initialisation (globals)
  263. // ----------------------------------------------------------------------------
  264.  
  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, " ");
  269.  
  270. var per_page = parseInt(getParam("zoom_per_page"));
  271. if (isNaN(per_page)) per_page = 10;
  272.  
  273. var page = parseInt(getParam("zoom_page"));
  274. if (isNaN(page)) page = 1;
  275.  
  276. var andq = parseInt(getParam("zoom_and"));
  277. if (isNaN(andq))
  278. {
  279.     if (typeof(DefaultToAnd) != "undefined" && DefaultToAnd == 1)
  280.         andq = 1;
  281.     else
  282.         andq = 0;
  283. }
  284.  
  285. var cat = getParamArray("zoom_cat[]");
  286. if (cat.length == 0)
  287. {
  288.     cat[0] = parseInt(getParam("zoom_cat"));
  289.     if (isNaN(cat))
  290.         cat[0] = -1;    // search all categories
  291. }
  292. var num_zoom_cats = cat.length;    
  293.  
  294.  
  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;
  299.  
  300. var SelfURL = "";
  301. if (typeof(LinkBackURL) == "undefined")
  302. {
  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);        
  312. }
  313. else
  314.     SelfURL = LinkBackURL;
  315. // encode invalid URL characters
  316. SelfURL = SelfURL.replace(/\</g, "<");
  317. SelfURL = SelfURL.replace(/\"/g, """);
  318.  
  319. var data = new Array();
  320. var output = new Array();
  321.  
  322. target = "";
  323. if (UseLinkTarget == 1)
  324.     target = " target=\"" + LinkTarget + "\" ";
  325.  
  326. // ----------------------------------------------------------------------------
  327. // Main search function starts here
  328. // ----------------------------------------------------------------------------
  329.  
  330. function ZoomSearch() 
  331. {
  332.         var loadingmsg = document.getElementById("loadingmsg");
  333.         if (loadingmsg) loadingmsg.style.display = "None";
  334.     if (UseCats)
  335.         NumCats = catnames.length;
  336.  
  337.     if (Timing == 1) {
  338.         timeStart = new Date();
  339.     }        
  340.         
  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>");
  354.             }
  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)
  360.                 {                                                    
  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++)  
  367.                     {              
  368.                         document.write("<li><input type=\"checkbox\" name=\"zoom_cat[]\" value=\"" +i+ "\"");
  369.                         if (cat[0] != -1)
  370.                         {
  371.                             for (catit = 0; catit < num_zoom_cats; catit++)
  372.                             {
  373.                                 if (i == cat[catit])
  374.                                 {
  375.                                     document.write(" checked=\"checked\"");
  376.                                     break;
  377.                                 }
  378.                             }
  379.                         }
  380.                         document.writeln(">"+catnames[i]+"</input></li>");
  381.                     }
  382.                     document.writeln("</ul><br /><br />");
  383.                 }
  384.                 else
  385.                 {                        
  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>");
  394.                     }
  395.                     document.writeln("</select>  ");
  396.                 }
  397.                 document.writeln("</span>");
  398.             }
  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);                
  406.             }
  407.             document.writeln("<input type=\"hidden\" name=\"zoom_sort\" value=\"" + sort + "\" />");
  408.             document.writeln("<br /><br /></span>");
  409.         }
  410.         else
  411.         {
  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 + "\" />");
  415.         }
  416.         
  417.         document.writeln("</form>");
  418.     }
  419.  
  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;
  426.     }
  427.  
  428.     if (MapAccents == 1) {
  429.         for (i = 0; i < NormalChars.length; i++) {
  430.             query = query.replace(AccentChars[i], NormalChars[i]);
  431.         }
  432.     }
  433.  
  434.     // Special query processing required when SearchAsSubstring is enabled
  435.     if (SearchAsSubstring == 1 && UseUTF8 == 1)
  436.         query = FixQueryForAsianWords(query);
  437.  
  438.     // prepare search query, strip quotes, trim whitespace
  439.     if (WordJoinChars.indexOf(".") == -1)
  440.         query = query.replace(/[\.+]/g, " ");
  441.  
  442.     if (WordJoinChars.indexOf("-") == -1)
  443.         query = query.replace(/(\S)\-/g, "$1 ");
  444.  
  445.     if (WordJoinChars.indexOf("_") == -1)
  446.         query = query.replace(/[\_+]/g, " ");
  447.  
  448.     if (WordJoinChars.indexOf("'") == -1)
  449.         query = query.replace(/[\'+]/g, " ");
  450.  
  451.     if (WordJoinChars.indexOf("#") == -1)
  452.         query = query.replace(/[\#+]/g, " ");
  453.  
  454.     if (WordJoinChars.indexOf("$") == -1)
  455.         query = query.replace(/[\$+]/g, " ");
  456.  
  457.     if (WordJoinChars.indexOf("&") == -1)
  458.         query = query.replace(/[\&+]/g, " ");
  459.  
  460.     if (WordJoinChars.indexOf(":") == -1)
  461.         query = query.replace(/[\:+]/g, " ");
  462.  
  463.     if (WordJoinChars.indexOf(",") == -1)
  464.         query = query.replace(/[\,+]/g, " ");
  465.  
  466.     if (WordJoinChars.indexOf("/") == -1)
  467.         query = query.replace(/[\/+]/g, " ");
  468.  
  469.     if (WordJoinChars.indexOf("\\") == -1)
  470.         query = query.replace(/[\\+]/g, " ");
  471.         
  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, " ");   
  475.     
  476.     // trim trailing/leading whitespace
  477.     query = query.replace(/^\s*|\s*$/g,""); 
  478.     
  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);    
  486.  
  487.     // split search phrase into words
  488.     searchWords = queryForSearch.split(" "); // split by spaces.
  489.     
  490.     // Sort search words if there are negative signs
  491.     if (queryForSearch.indexOf("-") != -1)
  492.         searchWords.sort(sw_compare);      
  493.  
  494.     var query_zoom_cats = "";
  495.  
  496.     document.write("<div class=\"searchheading\">" + STR_RESULTS_FOR + " " + queryForHTML);
  497.     if (UseCats) {
  498.         if (cat[0] == -1)
  499.         {
  500.             document.writeln(" " + STR_RESULTS_IN_ALL_CATEGORIES);
  501.             query_zoom_cats = "&zoom_cat%5B%5D=-1";
  502.         }
  503.         else
  504.         {
  505.             document.writeln(" " + STR_RESULTS_IN_CATEGORY + " ");
  506.             for (catit = 0; catit < num_zoom_cats; catit++)
  507.             {
  508.                 if (catit > 0)
  509.                     document.write(", ");
  510.                 document.write("\"" + catnames[cat[catit]] + "\"");
  511.                 query_zoom_cats += "&zoom_cat%5B%5D="+cat[catit];
  512.             }
  513.         }
  514.     }
  515.     document.writeln("<br /><br /></div>");
  516.  
  517.     document.writeln("<div class=\"results\">");
  518.  
  519.     numwords = searchWords.length;
  520.     kw_ptr = 0;
  521.     outputline = 0;    
  522.     ipage = 0;
  523.     matches = 0;
  524.     var SWord;
  525.     pagesCount = pageinfo.length;
  526.     
  527.     exclude_count = 0;
  528.     ExcludeTerm = 0;
  529.     
  530.     // Initialise a result table the size of all pages
  531.     res_table = new Array(pagesCount);
  532.     for (i = 0; i < pagesCount; i++)
  533.     {
  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;
  538.     }
  539.     
  540.     var UseWildCards = new Array(numwords);    
  541.         
  542.     for (sw = 0; sw < numwords; sw++) {
  543.  
  544.         UseWildCards[sw] = 0;
  545.  
  546.         if (skipwords) {
  547.             // check min length
  548.             if (searchWords[sw].length < MinWordLen) {
  549.                 SkipSearchWord(sw);
  550.                 continue;
  551.             }
  552.             // check skip word list
  553.             for (i = 0; i < skipwords.length; i++) {
  554.                 if (searchWords[sw] == skipwords[i]) {
  555.                     SkipSearchWord(sw);
  556.                     break;
  557.                 }
  558.             }
  559.         }
  560.  
  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]);
  566.         }
  567.         
  568.         if (Highlighting == 1 && UseWildCards[sw] == 0)
  569.             RegExpSearchWords[sw] = searchWords[sw];                    
  570.     }
  571.                    
  572.     // Begin searching...
  573.     for (sw = 0; sw < numwords; sw++) {
  574.  
  575.         if (searchWords[sw] == "") {
  576.             SkippedWords++;
  577.             continue;
  578.         }
  579.  
  580.         if (searchWords[sw].charAt(0) == '-')
  581.         {            
  582.             searchWords[sw] = searchWords[sw].substr(1);            
  583.             ExcludeTerm = 1;
  584.             exclude_count++;            
  585.         }
  586.         
  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");
  593.         }
  594.  
  595.         for (kw_ptr = 0; kw_ptr < dictwords.length; kw_ptr++) {
  596.  
  597.             data = dictwords[kw_ptr].split(" ");
  598.  
  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);
  606.  
  607.  
  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];
  614.                     
  615.                     if (ExcludeTerm == 1)
  616.                     {
  617.                         // we clear out the score entry so that it'll be excluded in the filter stage
  618.                         res_table[ipage][0] = 0;
  619.                     }                    
  620.                     else if (res_table[ipage][0] == 0) {
  621.                         matches++;
  622.                         res_table[ipage][0] += parseInt(data[kw+1]);
  623.                     }
  624.                     else {
  625.  
  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
  632.                         }
  633.                     }
  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;
  638.  
  639.                 }
  640.                 if (UseWildCards[sw] == 0 && SearchAsSubstring == 0)
  641.                     break;    // this search word was found, so skip to next
  642.             }
  643.         }
  644.     }
  645.     
  646.     if (SkippedWords > 0)
  647.         document.writeln("<div class=\"summary\">" + STR_SKIPPED_FOLLOWING_WORDS + " " + SkippedOutputStr + ".<br /><br /></div>");
  648.  
  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;
  663.                     }
  664.                     if (cati == num_zoom_cats)
  665.                         IsFiltered = true;
  666.                 }
  667.                 else {                                        
  668.                     if (pageinfo[i][PAGEINFO_CAT].charAt(cat[0]) == "0") {
  669.                         IsFiltered = true;
  670.                     }
  671.                 }
  672.             }
  673.             if (IsFiltered == false) {
  674.                 if (res_table[i][2] >= full_numwords) {
  675.                     fullmatches++;
  676.                 } else {
  677.                     if (andq == 1)
  678.                         IsFiltered = true;
  679.                 }
  680.             }
  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++;
  688.             }
  689.         }
  690.     }
  691.     matches = oline;    
  692.  
  693.     // Sort results in order of score, use "SortCompare" function
  694.     if (matches > 1)    
  695.        {
  696.            if (sort == 1 && UseDateTime == 1)
  697.                output.sort(SortByDate);    // sort by date
  698.            else
  699.             output.sort(SortCompare);    // sort by relevance
  700.     }
  701.     
  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);    
  708.  
  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 />");
  720.     }
  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 />");
  725.  
  726.     document.writeln("</div>\n");
  727.  
  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");
  732.         
  733.     // Show recommended links if any
  734.     if (Recommended == 1)
  735.     {
  736.         num_recs_found = 0;
  737.         rec_count = recommended.length;
  738.         for (rl = 0; rl < rec_count && num_recs_found < RecommendedMax; rl++)
  739.         {
  740.             sep = recommended[rl].lastIndexOf(" ");
  741.             if (sep > -1)
  742.             {
  743.                 rec_word = recommended[rl].slice(0, sep);
  744.                 rec_idx = parseInt(recommended[rl].slice(sep));
  745.                 for (sw = 0; sw <= numwords; sw++)    
  746.                 {
  747.                     if (sw == numwords)
  748.                     {
  749.                         match_result = wordcasecmp(rec_word, queryForSearch);
  750.                     }
  751.                     else
  752.                     {
  753.                         if (UseWildCards[sw] == 1)
  754.                         {
  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);                            
  761.                         }
  762.                         else if (SearchAsSubstring == 0)
  763.                         {
  764.                             match_result = wordcasecmp(rec_word, searchWords[sw]);
  765.                         }
  766.                         else
  767.                             match_result = rec_word.indexOf(searchWords[sw]);
  768.                     }
  769.                     if (match_result != -1)
  770.                     {
  771.                         if (num_recs_found == 0)
  772.                         {
  773.                             document.writeln("<div class=\"recommended\">");
  774.                             document.writeln("<div class=\"recommended_heading\">" + STR_RECOMMENDED + "</div>");
  775.                         }
  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)                
  781.                         {
  782.                             if (SearchAsSubstring == 1)
  783.                                 urlLink = AddParamToURL(urlLink, "zoom_highlightsub=" + queryForURL);
  784.                             else
  785.                                 urlLink = AddParamToURL(urlLink, "zoom_highlight=" + queryForURL);
  786.                         }            
  787.                         if (PdfHighlight == 1)
  788.                         {
  789.                             if (urlLink.indexOf(".pdf") != -1)
  790.                                 urlLink = urlLink+"#search=""+query+""";
  791.                         }                         
  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;                
  807.                     }
  808.                 }                
  809.             }
  810.         }
  811.         if (num_recs_found > 0)
  812.             document.writeln("</div");
  813.     }
  814.     
  815.     // Show sorting options
  816.     if (matches > 1)
  817.     {
  818.         if (UseDateTime == 1)
  819.         {
  820.             document.writeln("<div class=\"sorting\">");
  821.             if (sort == 1)
  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>");
  823.             else
  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>");
  826.         }        
  827.     }    
  828.  
  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);
  834.     }
  835.  
  836.     // the last result to show on this page
  837.     result_limit = arrayline + per_page;
  838.  
  839.     // display the results
  840.     while (arrayline < matches && arrayline < result_limit) {
  841.         ipage = output[arrayline][0];
  842.         score = output[arrayline][1];
  843.         
  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];
  854.         
  855.         urlLink = pgurl;                                        
  856.         if (GotoHighlight == 1)                
  857.         {
  858.             if (SearchAsSubstring == 1)
  859.                 urlLink = AddParamToURL(urlLink, "zoom_highlightsub=" + queryForURL);
  860.             else
  861.                 urlLink = AddParamToURL(urlLink, "zoom_highlight=" + queryForURL);
  862.         }        
  863.         if (PdfHighlight == 1)
  864.         {
  865.             if (urlLink.indexOf(".pdf") != -1)
  866.                 urlLink = urlLink+"#search=""+query+""";
  867.         } 
  868.                 
  869.         if (arrayline % 2 == 0)
  870.             document.writeln("<div class=\"result_block\">");
  871.         else
  872.             document.writeln("<div class=\"result_altblock\">");
  873.         
  874.         if (UseZoomImage == 1)
  875.         {            
  876.             if (pgimage.length > 1)
  877.             {
  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>");
  881.             }
  882.         }
  883.                             
  884.         document.writeln("<div class=\"result_title\">");
  885.         if (DisplayNumber == 1)
  886.             document.writeln("<b>" + (arrayline+1) + ".</b> ");
  887.             
  888.         if (DisplayTitle == 1)
  889.         {
  890.                document.writeln("<a href=\"" + urlLink + "\"" + target + ">");
  891.             PrintHighlightDescription(pgtitle);
  892.                document.writeln("</a>");
  893.         }        
  894.         else
  895.             document.writeln("<a href=\"" + urlLink + "\"" + target + ">" + pgurl + "</a>");
  896.                    
  897.         if (UseCats) 
  898.         {            
  899.             document.write("<span class=\"category\">");
  900.             for (cati = 0; cati < NumCats; cati++)
  901.             {
  902.                 if (catpage.charAt(cati) == "1")
  903.                     document.write(" ["+catnames[cati]+"]");
  904.             }             
  905.             document.writeln("</span>");
  906.         }
  907.         document.writeln("</div>");
  908.         
  909.         if (DisplayMetaDesc == 1)
  910.         {
  911.             // print meta description
  912.             document.writeln("<div class=\"description\">");            
  913.             PrintHighlightDescription(pgdesc);
  914.             document.writeln("</div>\n");
  915.         }
  916.         
  917.         info_str = "";
  918.         
  919.         if (DisplayTerms == 1)
  920.             info_str += STR_RESULT_TERMS_MATCHED + " " + output[arrayline][2];
  921.             
  922.         if (DisplayScore == 1) {
  923.             if (info_str.length > 0)
  924.                 info_str += "  -  ";
  925.             info_str += STR_RESULT_SCORE + " " + score;
  926.         }
  927.         
  928.         if (DisplayDate == 1 && pgdate > 0) 
  929.         {
  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();
  934.         }
  935.         
  936.         if (DisplayFilesize == 1) {
  937.             if (info_str.length > 0)
  938.                 info_str += "  -  ";
  939.             info_str += filesize + "k";
  940.         }        
  941.              
  942.         if (DisplayURL == 1) {
  943.             if (info_str.length > 0)
  944.                 info_str += "  -  ";
  945.             info_str += STR_RESULT_URL + " " + pgurl;
  946.         }
  947.                    
  948.         document.writeln("<div class=\"infoline\">");
  949.         document.writeln(info_str);                        
  950.         document.writeln("</div></div>\n");
  951.         arrayline++;
  952.     }
  953.  
  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;
  960.  
  961.         // 10 to the right
  962.         end_range = page + 10;
  963.         if (end_range > num_pages)
  964.             end_range = num_pages;
  965.  
  966.         document.writeln("<div class=\"result_pages\">" + STR_RESULT_PAGES + " ");
  967.         if (page > 1)
  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++) 
  970.         {
  971.             if (i == page)
  972.                 document.writeln(page + " ");
  973.             else
  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> ");            
  975.         }
  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>");
  979.     }
  980.  
  981.     document.writeln("</div>"); // end results style tag
  982.  
  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");
  987.     }
  988.  
  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>");
  991. }
  992.  
  993.