put exact binding matches first in results
svn: r10039
This commit is contained in:
parent
fb665f2012
commit
f8f3ec3b90
|
@ -179,9 +179,8 @@
|
||||||
+'</table>';
|
+'</table>';
|
||||||
// get the query box
|
// get the query box
|
||||||
query = document.getElementById("search_box");
|
query = document.getElementById("search_box");
|
||||||
// status should point to the text object
|
// status line
|
||||||
status = document.getElementById("search_status");
|
status = document.getElementById("search_status");
|
||||||
if (status.childNodes.length == 1) status = status.firstChild;
|
|
||||||
// result_links is the array of result link <container,link> pairs
|
// result_links is the array of result link <container,link> pairs
|
||||||
result_links = new Array();
|
result_links = new Array();
|
||||||
n = document.getElementById("search_result");
|
n = document.getElementById("search_result");
|
||||||
|
@ -217,36 +216,44 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var last_search_term_raw, last_search_terms;
|
var last_search_term, last_search_term_raw;
|
||||||
var search_results, first_search_result;
|
var search_results, first_search_result, exact_results_num;
|
||||||
function DoSearch() {
|
function DoSearch() {
|
||||||
var terms = query.value;
|
var term = query.value;
|
||||||
if (terms == last_search_term_raw) return;
|
if (term == last_search_term_raw) return;
|
||||||
last_search_term_raw = terms;
|
last_search_term_raw = term;
|
||||||
terms= terms.toLowerCase()
|
term = term.toLowerCase()
|
||||||
.replace(/\s\s*/g," ") // single spaces
|
.replace(/\s\s*/g," ") // single spaces
|
||||||
.replace(/^\s/g,"").replace(/\s$/g,""); // trim edge spaces
|
.replace(/^\s/g,"").replace(/\s$/g,""); // trim edge spaces
|
||||||
if (terms == last_search_terms) return;
|
if (term == last_search_term) return;
|
||||||
last_search_terms = terms;
|
last_search_term = term;
|
||||||
status.nodeValue = "Searching " + plt_search_data.length + " entries";
|
status.innerHTML = "Searching " + plt_search_data.length + " entries";
|
||||||
terms = (terms=="") ? [] : terms.split(/ /);
|
var terms = (term=="") ? [] : term.split(/ /);
|
||||||
if (terms.length == 0) {
|
if (terms.length == 0) {
|
||||||
search_results = plt_search_data;
|
search_results = plt_search_data;
|
||||||
} else {
|
} else {
|
||||||
search_results = new Array();
|
search_results = new Array();
|
||||||
|
exact_results = new Array();
|
||||||
for (var i=0@";" i<plt_search_data.length@";" i++) {
|
for (var i=0@";" i<plt_search_data.length@";" i++) {
|
||||||
var show = true, curtext = plt_search_data[i][0];
|
var show = true, curtext = plt_search_data[i][0];
|
||||||
for (var j=0@";" j<terms.length@";" j++) {
|
if (plt_search_data[i][3] && (term == curtext)) {
|
||||||
if (curtext.indexOf(terms[j]) < 0) {
|
exact_results.push(plt_search_data[i]);
|
||||||
show = false;
|
} else {
|
||||||
break;
|
for (var j=0@";" j<terms.length@";" j++) {
|
||||||
|
if (curtext.indexOf(terms[j]) < 0) {
|
||||||
|
show = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (show) search_results.push(plt_search_data[i]);
|
||||||
}
|
}
|
||||||
if (show) search_results.push(plt_search_data[i]);
|
|
||||||
}
|
}
|
||||||
|
exact_results_num = exact_results.length;
|
||||||
|
while (exact_results.length > 0)
|
||||||
|
search_results.unshift(exact_results.pop());
|
||||||
}
|
}
|
||||||
first_search_result = 0;
|
first_search_result = 0;
|
||||||
status.nodeValue = "" + search_results.length + " entries found";
|
status.innerHTML = "" + search_results.length + " entries found";
|
||||||
query.style.backgroundColor =
|
query.style.backgroundColor =
|
||||||
(search_results.length == 0) ? "#ffe0e0" : "white";
|
(search_results.length == 0) ? "#ffe0e0" : "white";
|
||||||
UpdateResults();
|
UpdateResults();
|
||||||
|
@ -292,22 +299,30 @@
|
||||||
'<a href="'
|
'<a href="'
|
||||||
+ UncompactUrl(search_results[n][1]) + '" class="indexlink">'
|
+ UncompactUrl(search_results[n][1]) + '" class="indexlink">'
|
||||||
+ UncompactHtml(search_results[n][2]) + '</a>' + desc;
|
+ UncompactHtml(search_results[n][2]) + '</a>' + desc;
|
||||||
|
result_links[i].style.backgroundColor =
|
||||||
|
(i < exact_results_num) ? "#ffffc0" : "white";
|
||||||
result_links[i].style.display = "block";
|
result_links[i].style.display = "block";
|
||||||
} else {
|
} else {
|
||||||
result_links[i].style.display = "none";
|
result_links[i].style.display = "none";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (search_results.length == 0)
|
if (search_results.length == 0)
|
||||||
status.nodeValue = "No matches found";
|
status.innerHTML = "No matches found";
|
||||||
else if (search_results.length <= results_num)
|
else if (search_results.length <= results_num)
|
||||||
status.nodeValue = "Showing all " + search_results.length + " matches";
|
status.innerHTML = "Showing all matches";
|
||||||
else
|
else
|
||||||
status.nodeValue =
|
status.innerHTML =
|
||||||
"Showing "
|
"Showing "
|
||||||
+ (first_search_result+1) + "-"
|
+ (first_search_result+1) + "-"
|
||||||
+ Math.min(first_search_result+results_num,search_results.length)
|
+ Math.min(first_search_result+results_num,search_results.length)
|
||||||
+ " of " + search_results.length
|
+ " of " + search_results.length
|
||||||
+ ((search_results.length==plt_search_data.length) ? "" : " matches");
|
+ ((search_results.length==plt_search_data.length) ? "" : " matches");
|
||||||
|
if (exact_results_num > 0)
|
||||||
|
status.innerHTML +=
|
||||||
|
" (<span style=\"background-color: #ffffc0;\">"
|
||||||
|
+ ((exact_results_num == search_results.length)
|
||||||
|
? "all" : exact_results_num)
|
||||||
|
+ " exact</span>)";
|
||||||
}
|
}
|
||||||
|
|
||||||
var search_timer = null;
|
var search_timer = null;
|
||||||
|
@ -342,7 +357,7 @@
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
search_timer = setTimeout(DoSearch, 400);
|
search_timer = setTimeout(DoSearch, 300);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user