📄 zoom_search.js
字号:
// ----------------------------------------------------------------------------
// Zoom Search Engine 5.0 (30/4/2007)
//
// This file (search.js) is the JavaScript search front-end for client side
// searches using index files created by the Zoom Search Engine Indexer.
//
// email: zoom@wrensoft.com
// www: http://www.wrensoft.com
//
// Copyright (C) Wrensoft 2000-2007
//
// This script performs client-side searching with the index data file
// (zoom_index.js) generated by the Zoom Search Engine Indexer. It allows you
// to run searches on mediums such as CD-ROMs, or other local data, where a
// web server is not available.
//
// We recommend against using client-side searches for online websites because
// it requires the entire index data file to be downloaded onto the user's
// local machine. This can be very slow for large websites, and our server-side
// search scripts (available for PHP, ASP and CGI) are far better suited for this.
// However, JavaScript is still an option for smaller websites in a limited
// hosting situation (eg: your web host does not support PHP, ASP or CGI).
// ----------------------------------------------------------------------------
// Include required files for index data, settings, etc.
document.write("<script language=\"JavaScript\" src=\"zoom_index.js\" charset=\"" + Charset + "\"><\/script>");
document.write("<script language=\"JavaScript\" src=\"zoom_pageinfo.js\" charset=\"" + Charset + "\"><\/script>");
document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=" + Charset + "\">");
// ----------------------------------------------------------------------------
// Settings (change if necessary)
// ----------------------------------------------------------------------------
// The options available in the dropdown menu for number of results
// per page
var PerPageOptions = new Array(10, 20, 50, 100);
// Globals
var SkippedWords = 0;
var searchWords = new Array();
var RegExpSearchWords = new Array();
var SkippedOutputStr = "";
var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
// Index format
var PAGEDATA_URL = 0;
var PAGEDATA_TITLE = 1;
var PAGEDATA_DESC = 2;
var PAGEDATA_IMG = 3;
var PAGEINFO_DATETIME = 0;
var PAGEINFO_FILESIZE = 1;
var PAGEINFO_CAT = 2;
// ----------------------------------------------------------------------------
// Helper Functions
// ----------------------------------------------------------------------------
// This function will return the value of a GET parameter
function getParam(paramName)
{
paramStr = document.location.search;
if (paramStr == "")
return "";
// remove '?' in front of paramStr
if (paramStr.charAt(0) == "?")
paramStr = paramStr.substr(1);
arg = (paramStr.split("&"));
for (i=0; i < arg.length; i++) {
arg_values = arg[i].split("=")
if (unescape(arg_values[0]) == paramName) {
if (UseUTF8 == 1 && self.decodeURIComponent) // check if decodeURIComponent() is defined
ret = decodeURIComponent(arg_values[1]);
else
ret = unescape(arg_values[1]); // IE 5.0 and older does not have decodeURI
return ret;
}
}
return "";
}
function getParamArray(paramName)
{
paramStr = document.location.search;
var retArray = new Array();
var retCount = 0;
if (paramStr == "")
return retArray;
// remove '?' in front of paramStr
if (paramStr.charAt(0) == "?")
paramStr = paramStr.substr(1);
arg = (paramStr.split("&"));
for (i=0; i < arg.length; i++)
{
arg_values = arg[i].split("=")
if (unescape(arg_values[0]) == paramName)
{
if (UseUTF8 == 1 && self.decodeURIComponent) // check if decodeURIComponent() is defined
ret = decodeURIComponent(arg_values[1]);
else
ret = unescape(arg_values[1]); // IE 5.0 and older does not have decodeURI
retArray[retCount] = ret;
retCount++;
}
}
return retArray;
}
// Compares the two values, used for sorting output results
// Results that match all search terms are put first, highest score
function SortCompare (a, b)
{
if (a[2] < b[2]) return 1;
else if (a[2] > b[2]) return -1;
else if (a[1] < b[1]) return 1;
else if (a[1] > b[1]) return -1;
else return 0;
}
function SortByDate(a, b)
{
if (pageinfo[a[0]][PAGEINFO_DATETIME] < pageinfo[b[0]][PAGEINFO_DATETIME]) return 1;
else if (pageinfo[a[0]][PAGEINFO_DATETIME] > pageinfo[b[0]][PAGEINFO_DATETIME]) return -1;
else return SortCompare(a, b);
}
function sw_compare(a, b)
{
if (a.charAt(0) == '-')
return 1;
if (b.charAt(0) == '-')
return -1;
return 0;
}
function pattern2regexp(pattern)
{
pattern = pattern.replace(/\#/g, "\\#");
pattern = pattern.replace(/\$/g, "\\$");
pattern = pattern.replace(/\./g, "\\.");
pattern = pattern.replace(/\*/g, "[\\d\\S]*");
pattern = pattern.replace(/\?/g, ".?");
return pattern;
}
function PrintHighlightDescription(line)
{
if (Highlighting == 0)
{
document.writeln(line);
return;
}
res = " " + line + " ";
for (i = 0; i < numwords; i++) {
if (RegExpSearchWords[i] == "")
continue;
if (SearchAsSubstring == 1)
res = res.replace(new RegExp("("+RegExpSearchWords[i]+")", "gi"), "[;:]$1[:;]");
else
res = res.replace(new RegExp("(\\W|^|\\b)("+RegExpSearchWords[i]+")(\\W|$|\\b)", "gi"), "$1[;:]$2[:;]$3");
}
// replace the marker text with the html text
// this is to avoid finding previous <span>'ed text.
res = res.replace(/\[;:\]/g, "<span class=\"highlight\">");
res = res.replace(/\[:;\]/g, "</span>");
document.writeln(res);
}
function PrintNumResults(num)
{
if (num == 0)
return STR_NO_RESULTS;
else if (num == 1)
return num + " " + STR_RESULT;
else
return num + " " + STR_RESULTS;
}
function AddParamToURL(url, paramStr)
{
// add GET parameters to URL depending on
// whether there are any existing parameters
if (url.indexOf("?") > -1)
return url + "&" + paramStr;
else
return url + "?" + paramStr;
}
function SkipSearchWord(sw) {
if (searchWords[sw] != "") {
if (SkippedWords > 0)
SkippedOutputStr += ", ";
SkippedOutputStr += "\"<b>" + searchWords[sw] + "</b>\"";
searchWords[sw] = "";
}
}
function wordcasecmp(word1, word2) {
if (word1 == word2)
return 0;
else
return -1;
}
function htmlspecialchars(query) {
query = query.replace(/\&/g, "&");
query = query.replace(/\</g, "<");
query = query.replace(/\>/g, ">");
query = query.replace(/\"/g, """);
query = query.replace(/\'/g, "'");
return query;
}
function QueryEntities(query) {
query = query.replace(/\&/g, "&");
query = query.replace(/\</g, "<");
query = query.replace(/\>/g, ">");
query = query.replace(/\'/g, "'");
return query;
}
function FixQueryForAsianWords(query) {
currCharType = 0;
lastCharType = 0; // 0 is normal, 1 is hiragana, 2 is katakana, 3 is "han"
// check for hiragana/katakana splitting required
newquery = "";
for (i = 0; i < query.length; i++)
{
ch = query.charAt(i);
chVal = query.charCodeAt(i);
if (chVal >= 12352 && chVal <= 12447)
currCharType = 1;
else if (chVal >= 12448 && chVal <= 12543)
currCharType = 2;
else if (chVal >= 13312 && chVal <= 44031)
currCharType = 3;
else
currCharType = 0;
if (lastCharType != currCharType && ch != " ")
newquery += " ";
lastCharType = currCharType;
newquery += ch;
}
return newquery;
}
// ----------------------------------------------------------------------------
// Parameters initialisation (globals)
// ----------------------------------------------------------------------------
var query = getParam("zoom_query");
query = query.replace(/[\++]/g, " "); // replace the '+' with spaces
SearchAsSubstring = (query == query.replace(/[\"+]/g, " "));
query = query.replace(/[\"+]/g, " ");
var per_page = parseInt(getParam("zoom_per_page"));
if (isNaN(per_page)) per_page = 10;
var page = parseInt(getParam("zoom_page"));
if (isNaN(page)) page = 1;
var andq = parseInt(getParam("zoom_and"));
if (isNaN(andq))
{
if (typeof(DefaultToAnd) != "undefined" && DefaultToAnd == 1)
andq = 1;
else
andq = 0;
}
var cat = getParamArray("zoom_cat[]");
if (cat.length == 0)
{
cat[0] = parseInt(getParam("zoom_cat"));
if (isNaN(cat))
cat[0] = -1; // search all categories
}
var num_zoom_cats = cat.length;
// for sorting options. zero is default (relevance)
// 1 is sort by date (if date/time is available)
var sort = parseInt(getParam("zoom_sort"));
if (isNaN(sort)) sort = 0;
var SelfURL = "";
if (typeof(LinkBackURL) == "undefined")
{
SelfURL = document.location.href;
// strip off parameters and anchors
var paramIndex;
paramIndex = SelfURL.indexOf("?");
if (paramIndex > -1)
SelfURL = SelfURL.substr(0, paramIndex);
paramIndex = SelfURL.indexOf("#");
if (paramIndex > -1)
SelfURL = SelfURL.substr(0, paramIndex);
}
else
SelfURL = LinkBackURL;
// encode invalid URL characters
SelfURL = SelfURL.replace(/\</g, "<");
SelfURL = SelfURL.replace(/\"/g, """);
var data = new Array();
var output = new Array();
target = "";
if (UseLinkTarget == 1)
target = " target=\"" + LinkTarget + "\" ";
// ----------------------------------------------------------------------------
// Main search function starts here
// ----------------------------------------------------------------------------
function ZoomSearch()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -