From 145738c722d1aa602053ea4b6b1e331961b1eb2f Mon Sep 17 00:00:00 2001 From: alta88 Date: Sat, 1 Aug 2009 18:22:47 -0600 Subject: [PATCH] Search enhancements v4: implement NEAR searches, with ~. --- content/collections.js | 15 +++-- content/searchHelp.xhtml | 131 --------------------------------------- locale/en-US/search.dtd | 42 +++++++------ 3 files changed, 34 insertions(+), 154 deletions(-) delete mode 100644 content/searchHelp.xhtml diff --git a/content/collections.js b/content/collections.js index fb408db..940a8c9 100644 --- a/content/collections.js +++ b/content/collections.js @@ -361,9 +361,9 @@ this._log.info("onClick: START itemIds - " +this.itemIds.toSource()); let quotesClosed = (!quotes || quotes.length%2 == 0) ? true : false; let oneNegation = false; // XXX: It would be nice to do unicode properly, \p{L} - Bug 258974. - let invalidInitial = new RegExp("^[^\"\\w\\u0080-\\uFFFF]|\\\|(?=\\s*[\|\-])+"); + let invalidInitial = new RegExp("^[^\"\\w\\u0080-\\uFFFF]|\\\|(?=\\s*[\|\-])+|\~(?!\\d(?=$|\\s)|\\s|$)"); let invalidNegation = new RegExp("\-.*[^\\w\\u0080-\\uFFFF]"); - let invalidUnquoted = new RegExp("^[^\-|\\w\\u0080-\\uFFFF]{1}?|.(?=[^\\w\\u0080-\\uFFFF])"); + let invalidUnquoted = new RegExp("^[^\-|\~|\\w\\u0080-\\uFFFF]{1}?|.(?=[^\\w\\u0080-\\uFFFF])"); let invalidQuoted = new RegExp("\"(?=[^\'\\w\\u0080-\\uFFFF])"); if ((aValue != "" && aValue.match(invalidInitial)) || @@ -409,6 +409,10 @@ this._log.info("onClick: START itemIds - " +this.itemIds.toSource()); // Unquoted | means OR. We do not use OR because it is 1)twice the // typing, 2)english-centric. term = "OR" + else if (term[0] == "~") + // Unquoted ~ means NEAR. We do not use NEAR because it is 1)4x the + // typing, 2)english-centric. + term = "NEAR" + (term[1] ? "/" + term[1] : ""); else // Add asterisk to non quoted term for sqlite fts non-exact match. term = SnowlUtils.appendAsterisks(term); @@ -419,11 +423,14 @@ this._log.info("onClick: START itemIds - " +this.itemIds.toSource()); this._searchFilter.removeAttribute("invalid"); - if (aValue.charAt(aValue.length - 1).match(/\s|\|/) || + if (aValue.charAt(aValue.length - 1).match(/\s|\||\~/) || (aValue.charAt(aValue.length - 1).match(/-/) && aValue.charAt(aValue.length - 2).match(/\s/)) || + (aValue.charAt(aValue.length - 1).match(/\d/) && + aValue.charAt(aValue.length - 2).match(/\~/)) || !quotesClosed) - // Don't run search on a space, or OR |, or negation -, or unclosed quote ". + // Don't run search on a space, or OR |, or negation -, or unclosed quote ", + // or NEAR ~ number. return; // Save string. diff --git a/content/searchHelp.xhtml b/content/searchHelp.xhtml deleted file mode 100644 index 39d39c5..0000000 --- a/content/searchHelp.xhtml +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - %htmlDTD; - - %globalDTD; - - %browserDTD; - - %messageDTD; -]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
&search.header1;
&search.header2;
&search.example1;&search.explanation1;
&search.example2;&search.explanation2;
&search.example3;&search.explanation3;
&search.example4;&search.explanation4;
&search.example5;&search.explanation5;
&search.example6;&search.explanation6;
&search.header3;
&search.header4;
&search.example7;&search.explanation7;
&search.example8;&search.explanation8;
&search.example9;&search.explanation9;
&search.example10;&search.explanation10;
&search.header5;
&search.example11;&search.explanation11;
&search.example12;&search.explanation12;
&search.example13;&search.explanation13;
- - - diff --git a/locale/en-US/search.dtd b/locale/en-US/search.dtd index 898cbcf..c148912 100644 --- a/locale/en-US/search.dtd +++ b/locale/en-US/search.dtd @@ -5,33 +5,37 @@ - + - + - + - + - + + + + + - - - - - - - - + + + + + + + + - - - - - - + + + + + +