Search enhancements v4: implement NEAR searches, with ~.

This commit is contained in:
alta88 2009-08-01 18:22:47 -06:00
Родитель 141e4efda7
Коммит 145738c722
3 изменённых файлов: 34 добавлений и 154 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -1,131 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is Snowl.
-
- The Initial Developer of the Original Code is Mozilla.
- Portions created by the Initial Developer are Copyright (C) 2008
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- alta88 <alta88@gmail.com>
-
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the GPL or the LGPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE HTML [
<!ENTITY % htmlDTD PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
%htmlDTD;
<!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
%globalDTD;
<!ENTITY % browserDTD SYSTEM "chrome://browser/locale/browser.dtd">
%browserDTD;
<!ENTITY % messageDTD SYSTEM "chrome://snowl/locale/search.dtd">
%messageDTD;
]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" media="all"
href="chrome://snowl/content/preferences.css"/>
</head>
<!-- -->
<body id="body"
dir="&locale.dir;">
<table>
<tr>
<td colspan="2">&search.header1;</td>
</tr>
<tr>
<td colspan="2"><u>&search.header2;</u></td>
</tr>
<tr>
<td class="column1" valign="top">&search.example1;</td>
<td>&search.explanation1;</td>
</tr>
<tr>
<td class="column1" valign="top">&search.example2;</td>
<td>&search.explanation2;</td>
</tr>
<tr>
<td class="column1" valign="top">&search.example3;</td>
<td>&search.explanation3;</td>
</tr>
<tr>
<td class="column1" valign="top">&search.example4;</td>
<td>&search.explanation4;</td>
</tr>
<tr>
<td class="column1" valign="top">&search.example5;</td>
<td>&search.explanation5;</td>
</tr>
<tr>
<td class="column1" valign="top">&search.example6;</td>
<td>&search.explanation6;</td>
</tr>
<tr><td colspan="2"/></tr>
<tr>
<td colspan="2">&search.header3;</td>
</tr>
<tr>
<td colspan="2"><u>&search.header4;</u></td>
</tr>
<tr>
<td class="column1" valign="top">&search.example7;</td>
<td>&search.explanation7;</td>
</tr>
<tr>
<td class="column1" valign="top">&search.example8;</td>
<td>&search.explanation8;</td>
</tr>
<tr>
<td class="column1" valign="top">&search.example9;</td>
<td>&search.explanation9;</td>
</tr>
<tr>
<td class="column1" valign="top">&search.example10;</td>
<td>&search.explanation10;</td>
</tr>
<tr><td colspan="2"/></tr>
<tr>
<td colspan="2">&search.header5;</td>
</tr>
<tr>
<td class="column1" valign="top">&search.example11;</td>
<td>&search.explanation11;</td>
</tr>
<tr>
<td class="column1" valign="top">&search.example12;</td>
<td>&search.explanation12;</td>
</tr>
<tr>
<td class="column1" valign="top">&search.example13;</td>
<td>&search.explanation13;</td>
</tr>
</table>
</body>
</html>

Просмотреть файл

@ -5,33 +5,37 @@
<!ENTITY search.header1 "Search is based on SQLite's Full Text Search (FTS) capabilities and limitations.">
<!ENTITY search.header2 "Valid Syntax:">
<!ENTITY search.example1 'foo, "foo*"'>
<!ENTITY search.explanation1 "Match all items starting with 'foo'; both 'foo' and 'foobar'">
<!ENTITY search.explanation1 "Match all items starting with 'foo'; both 'foo' and 'foobar'.">
<!ENTITY search.example2 '"foo"'>
<!ENTITY search.explanation2 "Match all items containing exactly 'foo'; 'foo' but not 'foobar'">
<!ENTITY search.explanation2 "Match all items containing exactly 'foo'; 'foo' but not 'foobar'.">
<!ENTITY search.example3 "foo bar">
<!ENTITY search.explanation3 "Match all items with both 'foo' AND 'bar'">
<!ENTITY search.explanation3 "Match all items with both 'foo' AND 'bar'.">
<!ENTITY search.example4 "foo | bar">
<!ENTITY search.explanation4 "Match all items with either 'foo' OR 'bar'">
<!ENTITY search.explanation4 "Match all items with either 'foo' OR 'bar'.">
<!ENTITY search.example5 "foo bar -baz">
<!ENTITY search.explanation5 "Match all items with 'foo' AND 'bar' but NOT 'baz'">
<!ENTITY search.explanation5 "Match all items with 'foo' AND 'bar' but NOT 'baz'.">
<!ENTITY search.example6 "">
<!ENTITY search.explanation6 "Note: there can only be ONE negation term and it must be the LAST term in the search query.">
<!ENTITY search.example7 "foo ~N bar">
<!ENTITY search.explanation7 "Match all items where 'foo' is NEAR 'bar', meaning within N words of 'bar'. Valid values for N are 0-9 (default is 10 if N is blank).">
<!ENTITY search.example8 'foo ~2 bar ~ "baz biff"'>
<!ENTITY search.explanation8 "Match all items where 'foo' is within 2 words of 'bar' and 'bar' is within 10 words of ''baz biff''.">
<!ENTITY search.header3 "Syntax errors are indicated by a red background.">
<!ENTITY search.header4 "Invalid syntax:">
<!ENTITY search.example7 '"*foo bar", *bar'>
<!ENTITY search.explanation7 "Wildcard prefixing is invalid.">
<!ENTITY search.example8 '" foo bar "'>
<!ENTITY search.explanation8 "Leading and trailing spaces are invalid in a quoted string.">
<!ENTITY search.example9 ".foo-bar?">
<!ENTITY search.explanation9 "Non alphanumeric symbols are invalid in nonquoted strings.">
<!ENTITY search.example10 '-"foo bar"'>
<!ENTITY search.explanation10 "Quoted strings cannot be negated.">
<!ENTITY search.example9 '"*foo bar", *bar'>
<!ENTITY search.explanation9 "Wildcard prefixing is invalid.">
<!ENTITY search.example10 '" foo bar "'>
<!ENTITY search.explanation10 "Leading and trailing spaces are invalid in a quoted string.">
<!ENTITY search.example11 ".foo-bar?">
<!ENTITY search.explanation11 "Non alphanumeric symbols are invalid in nonquoted strings.">
<!ENTITY search.example12 '-"foo bar"'>
<!ENTITY search.explanation12 "Quoted strings cannot be negated.">
<!ENTITY search.header5 "Searching for symbols in quoted strings returns unexpected results. In addition, wildcards are not supported within words.">
<!ENTITY search.example11 '"foo-----bar"'>
<!ENTITY search.explanation11 'Finds "foo bar", "foo-bar"'>
<!ENTITY search.example12 '"foo-bar"'>
<!ENTITY search.explanation12 'Finds "foo bar"'>
<!ENTITY search.example13 '"foo b*r"'>
<!ENTITY search.explanation13 'Finds "foo b r", "foo b=r", etc. but not "foo bar"'>
<!ENTITY search.example13 '"foo-----bar"'>
<!ENTITY search.explanation13 'Finds "foo bar", "foo-bar".'>
<!ENTITY search.example14 '"foo-bar"'>
<!ENTITY search.explanation14 'Finds "foo bar".'>
<!ENTITY search.example15 '"foo b*r"'>
<!ENTITY search.explanation15 'Finds "foo b r", "foo b=r", etc. but not "foo bar".'>