From e7184d8d29714057cd0f21c7f7a7ea69e0657665 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Fri, 25 Jul 2008 13:51:51 +0000 Subject: [PATCH] add "-foo" for negated search terms, fix occasional problem with aborted searches svn: r10911 --- collects/scribblings/main/private/search.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/collects/scribblings/main/private/search.js b/collects/scribblings/main/private/search.js index 9a69bb0b4c..eaad53dd9b 100644 --- a/collects/scribblings/main/private/search.js +++ b/collects/scribblings/main/private/search.js @@ -113,6 +113,8 @@ function InitializeSearch() { +'
  • Hit PageUp/PageDown and' +' C+Enter/S+C+Enter to scroll through the' +' results.
  • ' + +'
  • Search terms are all required, use' + +' “-str” to negate a term.' +'
  • Use “M:str” to match only' +' identifiers from modules that (partially) match' +' “str”; “M:” by' @@ -341,10 +343,18 @@ function UrlToManual(url) { // "L:schem" (only module names that match `schem') function CompileTerm(term) { - var flag = ((term.search(/^[LMT]:/)==0) && term.substring(0,1)); - if (flag) term = term.substring(2); + var op = false; + // the first part avoids a single "-" from removing everything + if (term != "-" && term.search(/^(-|[LMT]:)/) == 0) { + op = term.substring(0,1); + term = RegExp.rightContext; + } term = term.toLowerCase(); - switch(flag) { + switch(op) { + case "-": + op = CompileTerm(term); + // return C_exact if it's not found, so it doesn't disqualify exact matches + return function(x) { return (op(x) >= C_match) ? C_fail : C_exact; } case "L": return function(x) { if (!x[3]) return C_fail; @@ -414,7 +424,7 @@ function Search(data, term, is_pre, K) { // false otherwise var t = false; var killer = function() { if (t) clearTimeout(t); }; - // term comes with normalized spaces (trimmed, and no doubles) + // term comes with normalized spaces (trimmed, and no double spaces) var preds = (term=="") ? [] : term.split(/ /); for (var i=0; i