From f8f3ec3b90e9047bd18c146d77dee19554f1d56c Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Fri, 30 May 2008 15:14:32 +0000 Subject: [PATCH] put exact binding matches first in results svn: r10039 --- .../scribblings/main/private/make-search.ss | 63 ++++++++++++------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/collects/scribblings/main/private/make-search.ss b/collects/scribblings/main/private/make-search.ss index cddc0e96aa..260a6854af 100644 --- a/collects/scribblings/main/private/make-search.ss +++ b/collects/scribblings/main/private/make-search.ss @@ -179,9 +179,8 @@ +''; // get the query box query = document.getElementById("search_box"); - // status should point to the text object + // status line status = document.getElementById("search_status"); - if (status.childNodes.length == 1) status = status.firstChild; // result_links is the array of result link pairs result_links = new Array(); n = document.getElementById("search_result"); @@ -217,36 +216,44 @@ } } - var last_search_term_raw, last_search_terms; - var search_results, first_search_result; + var last_search_term, last_search_term_raw; + var search_results, first_search_result, exact_results_num; function DoSearch() { - var terms = query.value; - if (terms == last_search_term_raw) return; - last_search_term_raw = terms; - terms= terms.toLowerCase() - .replace(/\s\s*/g," ") // single spaces - .replace(/^\s/g,"").replace(/\s$/g,""); // trim edge spaces - if (terms == last_search_terms) return; - last_search_terms = terms; - status.nodeValue = "Searching " + plt_search_data.length + " entries"; - terms = (terms=="") ? [] : terms.split(/ /); + var term = query.value; + if (term == last_search_term_raw) return; + last_search_term_raw = term; + term = term.toLowerCase() + .replace(/\s\s*/g," ") // single spaces + .replace(/^\s/g,"").replace(/\s$/g,""); // trim edge spaces + if (term == last_search_term) return; + last_search_term = term; + status.innerHTML = "Searching " + plt_search_data.length + " entries"; + var terms = (term=="") ? [] : term.split(/ /); if (terms.length == 0) { search_results = plt_search_data; } else { search_results = new Array(); + exact_results = new Array(); for (var i=0@";" i 0) + search_results.unshift(exact_results.pop()); } first_search_result = 0; - status.nodeValue = "" + search_results.length + " entries found"; + status.innerHTML = "" + search_results.length + " entries found"; query.style.backgroundColor = (search_results.length == 0) ? "#ffe0e0" : "white"; UpdateResults(); @@ -292,22 +299,30 @@ '' + UncompactHtml(search_results[n][2]) + '' + desc; + result_links[i].style.backgroundColor = + (i < exact_results_num) ? "#ffffc0" : "white"; result_links[i].style.display = "block"; } else { result_links[i].style.display = "none"; } } if (search_results.length == 0) - status.nodeValue = "No matches found"; + status.innerHTML = "No matches found"; else if (search_results.length <= results_num) - status.nodeValue = "Showing all " + search_results.length + " matches"; + status.innerHTML = "Showing all matches"; else - status.nodeValue = + status.innerHTML = "Showing " + (first_search_result+1) + "-" + Math.min(first_search_result+results_num,search_results.length) + " of " + search_results.length + ((search_results.length==plt_search_data.length) ? "" : " matches"); + if (exact_results_num > 0) + status.innerHTML += + " (" + + ((exact_results_num == search_results.length) + ? "all" : exact_results_num) + + " exact)"; } var search_timer = null; @@ -342,7 +357,7 @@ } return false; } - search_timer = setTimeout(DoSearch, 400); + search_timer = setTimeout(DoSearch, 300); return true; }