📄 zoom_search.js
字号:
var loadingmsg = document.getElementById("loadingmsg");
if (loadingmsg) loadingmsg.style.display = "None";
if (UseCats)
NumCats = catnames.length;
if (Timing == 1) {
timeStart = new Date();
}
// Display the form
if (FormFormat > 0) {
document.writeln("<form method=\"get\" action=\"" + SelfURL + "\" class=\"zoom_searchform\">");
document.writeln("<input type=\"text\" name=\"zoom_query\" size=\"20\" value=\"" + htmlspecialchars(query) + "\" class=\"zoom_searchbox\" />");
document.writeln("<input type=\"submit\" value=\"" + STR_FORM_SUBMIT_BUTTON + "\" class=\"zoom_button\" /><br />");
if (FormFormat == 2) {
document.writeln("<span class=\"zoom_results_per_page\">" + STR_FORM_RESULTS_PER_PAGE + "\n");
document.writeln("<select name=\"zoom_per_page\">");
for (i = 0; i < PerPageOptions.length; i++) {
document.write("<option");
if (PerPageOptions[i] == per_page)
document.write(" selected=\"selected\"");
document.writeln(">" + PerPageOptions[i] + "</option>");
}
document.writeln("</select><br /><br /></span>");
if (UseCats) {
document.writeln("<span class=\"zoom_categories\">");
document.write(STR_FORM_CATEGORY + " ");
if (SearchMultiCats)
{
document.writeln("<ul>");
document.write("<li><input type=\"checkbox\" name=\"zoom_cat[]\" value=\"-1\"");
if (cat[0] == -1)
document.write(" checked=\"checked\"");
document.writeln(">" + STR_FORM_CATEGORY_ALL + "</input></li>");
for (i = 0; i < NumCats; i++)
{
document.write("<li><input type=\"checkbox\" name=\"zoom_cat[]\" value=\"" +i+ "\"");
if (cat[0] != -1)
{
for (catit = 0; catit < num_zoom_cats; catit++)
{
if (i == cat[catit])
{
document.write(" checked=\"checked\"");
break;
}
}
}
document.writeln(">"+catnames[i]+"</input></li>");
}
document.writeln("</ul><br /><br />");
}
else
{
document.write("<select name='zoom_cat[]'>");
// 'all cats option
document.write("<option value=\"-1\">" + STR_FORM_CATEGORY_ALL + "</option>");
for (i = 0; i < NumCats; i++) {
document.write("<option value=\"" + i + "\"");
if (i == cat[0])
document.write(" selected=\"selected\"");
document.writeln(">" + catnames[i] + "</option>");
}
document.writeln("</select> ");
}
document.writeln("</span>");
}
document.writeln("<span class=\"zoom_match\">" + STR_FORM_MATCH + " ");
if (andq == 0) {
document.writeln("<input type=\"radio\" name=\"zoom_and\" value=\"0\" checked=\"checked\" />" + STR_FORM_ANY_SEARCH_WORDS);
document.writeln("<input type=\"radio\" name=\"zoom_and\" value=\"1\" />" + STR_FORM_ALL_SEARCH_WORDS);
} else {
document.writeln("<input type=\"radio\" name=\"zoom_and\" value=\"0\" />" + STR_FORM_ANY_SEARCH_WORDS);
document.writeln("<input type=\"radio\" name=\"zoom_and\" value=\"1\" checked=\"checked\" />" + STR_FORM_ALL_SEARCH_WORDS);
}
document.writeln("<input type=\"hidden\" name=\"zoom_sort\" value=\"" + sort + "\" />");
document.writeln("<br /><br /></span>");
}
else
{
document.writeln("<input type=\"hidden\" name=\"zoom_per_page\" value=\"" + per_page + "\" />");
document.writeln("<input type=\"hidden\" name=\"zoom_and\" value=\"" + andq + "\" />");
document.writeln("<input type=\"hidden\" name=\"zoom_sort\" value=\"" + sort + "\" />");
}
document.writeln("</form>");
}
// give up early if no search words provided
if (query.length == 0) {
//document.writeln("No search query entered.<br />");
if (ZoomInfo == 1)
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>");
return;
}
if (MapAccents == 1) {
for (i = 0; i < NormalChars.length; i++) {
query = query.replace(AccentChars[i], NormalChars[i]);
}
}
// Special query processing required when SearchAsSubstring is enabled
if (SearchAsSubstring == 1 && UseUTF8 == 1)
query = FixQueryForAsianWords(query);
// prepare search query, strip quotes, trim whitespace
if (WordJoinChars.indexOf(".") == -1)
query = query.replace(/[\.+]/g, " ");
if (WordJoinChars.indexOf("-") == -1)
query = query.replace(/(\S)\-/g, "$1 ");
if (WordJoinChars.indexOf("_") == -1)
query = query.replace(/[\_+]/g, " ");
if (WordJoinChars.indexOf("'") == -1)
query = query.replace(/[\'+]/g, " ");
if (WordJoinChars.indexOf("#") == -1)
query = query.replace(/[\#+]/g, " ");
if (WordJoinChars.indexOf("$") == -1)
query = query.replace(/[\$+]/g, " ");
if (WordJoinChars.indexOf("&") == -1)
query = query.replace(/[\&+]/g, " ");
if (WordJoinChars.indexOf(":") == -1)
query = query.replace(/[\:+]/g, " ");
if (WordJoinChars.indexOf(",") == -1)
query = query.replace(/[\,+]/g, " ");
if (WordJoinChars.indexOf("/") == -1)
query = query.replace(/[\/+]/g, " ");
if (WordJoinChars.indexOf("\\") == -1)
query = query.replace(/[\\+]/g, " ");
// substitute multiple whitespace chars to single character
// also strip any of the wordjoinchars if followed immediately by a space
query = query.replace(/[\s\(\)\^\[\]\|\+\{\}\%]+|[\-._',:&\/\\\\](\s|$)/g, " ");
// trim trailing/leading whitespace
query = query.replace(/^\s*|\s*$/g,"");
var queryForHTML = htmlspecialchars(query);
var queryForSearch;
if (ToLowerSearchWords == 1)
queryForSearch = query.toLowerCase();
else
queryForSearch = query;
queryForSearch = htmlspecialchars(queryForSearch);
// split search phrase into words
searchWords = queryForSearch.split(" "); // split by spaces.
// Sort search words if there are negative signs
if (queryForSearch.indexOf("-") != -1)
searchWords.sort(sw_compare);
var query_zoom_cats = "";
document.write("<div class=\"searchheading\">" + STR_RESULTS_FOR + " " + queryForHTML);
if (UseCats) {
if (cat[0] == -1)
{
document.writeln(" " + STR_RESULTS_IN_ALL_CATEGORIES);
query_zoom_cats = "&zoom_cat%5B%5D=-1";
}
else
{
document.writeln(" " + STR_RESULTS_IN_CATEGORY + " ");
for (catit = 0; catit < num_zoom_cats; catit++)
{
if (catit > 0)
document.write(", ");
document.write("\"" + catnames[cat[catit]] + "\"");
query_zoom_cats += "&zoom_cat%5B%5D="+cat[catit];
}
}
}
document.writeln("<br /><br /></div>");
document.writeln("<div class=\"results\">");
numwords = searchWords.length;
kw_ptr = 0;
outputline = 0;
ipage = 0;
matches = 0;
var SWord;
pagesCount = pageinfo.length;
exclude_count = 0;
ExcludeTerm = 0;
// Initialise a result table the size of all pages
res_table = new Array(pagesCount);
for (i = 0; i < pagesCount; i++)
{
res_table[i] = new Array(3);
res_table[i][0] = 0;
res_table[i][1] = 0;
res_table[i][2] = 0;
}
var UseWildCards = new Array(numwords);
for (sw = 0; sw < numwords; sw++) {
UseWildCards[sw] = 0;
if (skipwords) {
// check min length
if (searchWords[sw].length < MinWordLen) {
SkipSearchWord(sw);
continue;
}
// check skip word list
for (i = 0; i < skipwords.length; i++) {
if (searchWords[sw] == skipwords[i]) {
SkipSearchWord(sw);
break;
}
}
}
if (searchWords[sw].indexOf("*") == -1 && searchWords[sw].indexOf("?") == -1) {
UseWildCards[sw] = 0;
} else {
UseWildCards[sw] = 1;
RegExpSearchWords[sw] = pattern2regexp(searchWords[sw]);
}
if (Highlighting == 1 && UseWildCards[sw] == 0)
RegExpSearchWords[sw] = searchWords[sw];
}
// Begin searching...
for (sw = 0; sw < numwords; sw++) {
if (searchWords[sw] == "") {
SkippedWords++;
continue;
}
if (searchWords[sw].charAt(0) == '-')
{
searchWords[sw] = searchWords[sw].substr(1);
ExcludeTerm = 1;
exclude_count++;
}
if (UseWildCards[sw] == 1) {
if (SearchAsSubstring == 0)
pattern = "^" + RegExpSearchWords[sw] + "$";
else
pattern = RegExpSearchWords[sw];
re = new RegExp(pattern, "g");
}
for (kw_ptr = 0; kw_ptr < dictwords.length; kw_ptr++) {
data = dictwords[kw_ptr].split(" ");
if (UseWildCards[sw] == 0) {
if (SearchAsSubstring == 0)
match_result = wordcasecmp(data[0], searchWords[sw]);
else
match_result = data[0].indexOf(searchWords[sw]);
} else
match_result = data[0].search(re);
if (match_result != -1) {
// keyword found, include it in the output list
for (kw = 1; kw < data.length; kw += 2) {
// check if page is already in output list
pageexists = 0;
ipage = data[kw];
if (ExcludeTerm == 1)
{
// we clear out the score entry so that it'll be excluded in the filter stage
res_table[ipage][0] = 0;
}
else if (res_table[ipage][0] == 0) {
matches++;
res_table[ipage][0] += parseInt(data[kw+1]);
}
else {
if (res_table[ipage][0] > 10000) {
// take it easy if its too big to prevent gigantic scores
res_table[ipage][0] += 1;
} else {
res_table[ipage][0] += parseInt(data[kw+1]); // add in score
res_table[ipage][0] *= 2; // double score as we have two words matching
}
}
res_table[ipage][1] += 1;
// store the 'and' user search terms matched' value
if (res_table[ipage][2] == sw || res_table[ipage][2] == sw-SkippedWords-exclude_count)
res_table[ipage][2] += 1;
}
if (UseWildCards[sw] == 0 && SearchAsSubstring == 0)
break; // this search word was found, so skip to next
}
}
}
if (SkippedWords > 0)
document.writeln("<div class=\"summary\">" + STR_SKIPPED_FOLLOWING_WORDS + " " + SkippedOutputStr + ".<br /><br /></div>");
// Count number of output lines that match ALL search terms
oline = 0;
fullmatches = 0;
output = new Array();
var full_numwords = numwords - SkippedWords - exclude_count;
for (i = 0; i < pagesCount; i++) {
IsFiltered = false;
if (res_table[i][0] > 0) {
if (UseCats && cat[0] != -1) {
// using cats and not doing an "all cats" search
if (SearchMultiCats) {
for (cati = 0; cati < num_zoom_cats; cati++) {
if (pageinfo[i][PAGEINFO_CAT].charAt(cat[cati]) == "1")
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -