Fix for bug 65190: add comparison type "all words as substrings" and "any words…

Fix for bug 65190: add comparison type "all words as substrings" and "any words as substrings" to the text fields in query.cgi Patch by Andreas Franke <afranke@ags.uni-sb.de> r= justdave@syndicomm.com
parent a05fe502
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
# Contributor(s): Terry Weissman <terry@mozilla.org> # Contributor(s): Terry Weissman <terry@mozilla.org>
# Dan Mosedale <dmose@mozilla.org> # Dan Mosedale <dmose@mozilla.org>
# Stephan Niemz <st.n@gmx.net> # Stephan Niemz <st.n@gmx.net>
# Andreas Franke <afranke@mathweb.org>
use diagnostics; use diagnostics;
use strict; use strict;
...@@ -107,6 +108,21 @@ sub GetByWordList { ...@@ -107,6 +108,21 @@ sub GetByWordList {
return \@list; return \@list;
} }
#
# support for "any/all/nowordssubstr" comparison type ("words as substrings")
#
sub GetByWordListSubstr {
my ($field, $strs) = (@_);
my @list;
foreach my $word (split(/[\s,]+/, $strs)) {
if ($word ne "") {
push(@list, "INSTR(LOWER($field), " . lc(SqlQuote($word)) . ")");
}
}
return \@list;
}
sub Error { sub Error {
...@@ -491,6 +507,18 @@ sub GenerateSQL { ...@@ -491,6 +507,18 @@ sub GenerateSQL {
} }
$term = join(" OR ", @list); $term = join(" OR ", @list);
}, },
",anywordssubstr" => sub {
$term = join(" OR ", @{GetByWordListSubstr($ff, $v)});
},
",allwordssubstr" => sub {
$term = join(" AND ", @{GetByWordListSubstr($ff, $v)});
},
",nowordssubstr" => sub {
my @list = @{GetByWordListSubstr($ff, $v)};
if (@list) {
$term = "NOT (" . join(" OR ", @list) . ")";
}
},
",anywords" => sub { ",anywords" => sub {
$term = join(" OR ", @{GetByWordList($ff, $v)}); $term = join(" OR ", @{GetByWordList($ff, $v)});
}, },
......
...@@ -703,10 +703,12 @@ sub StringSearch { ...@@ -703,10 +703,12 @@ sub StringSearch {
<td><SELECT NAME=$type> <td><SELECT NAME=$type>
}; };
if ($default{$type} eq "") { if ($default{$type} eq "") {
$default{$type} = "substring"; $default{$type} = "allwordssubstr";
} }
foreach my $i (["substring", "case-insensitive substring"], foreach my $i (["substring", "case-insensitive substring"],
["casesubstring", "case-sensitive substring"], ["casesubstring", "case-sensitive substring"],
["allwordssubstr", "all words as substrings"],
["anywordssubstr", "any words as substrings"],
["allwords", "all words"], ["allwords", "all words"],
["anywords", "any words"], ["anywords", "any words"],
["regexp", "regular expression"], ["regexp", "regular expression"],
...@@ -780,6 +782,8 @@ my @types = ( ...@@ -780,6 +782,8 @@ my @types = (
["casesubstring", "contains (case-sensitive) substring"], ["casesubstring", "contains (case-sensitive) substring"],
["substring", "contains (case-insensitive) substring"], ["substring", "contains (case-insensitive) substring"],
["notsubstring", "does not contain (case-insensitive) substring"], ["notsubstring", "does not contain (case-insensitive) substring"],
["allwordssubstr", "all words as (case-insensitive) substrings"],
["anywordssubstr", "any words as (case-insensitive) substrings"],
["regexp", "contains regexp"], ["regexp", "contains regexp"],
["notregexp", "does not contain regexp"], ["notregexp", "does not contain regexp"],
["lessthan", "less than"], ["lessthan", "less than"],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment