new port-search wildcarding - bad idea?

* for an exact match use "quoting", a bit like what Google does
to enforce a search term

* otherwise terms are assumed to be wildcard bounded and case insensitive

* without quotes, * and ? characters are supported for multi and single
character wildcards.

we could revert this commit if we don't like it.
This commit is contained in:
Oliver Gorwits
2013-09-08 22:41:17 +01:00
parent e77a806f65
commit 947614ddd8
9 changed files with 24 additions and 14 deletions

View File

@@ -31,9 +31,19 @@ ajax '/ajax/content/device/ports' => require_login sub {
return unless $set->count;
}
else {
$f =~ s/\*/%/g if index($f, '*') >= 0;
$f =~ s/\?/_/g if index($f, '?') >= 0;
$f = { '-ilike' => $f };
# Google-style search. Quoted means exact, otherwise wildcard.
# but still supoort manual wildcarding.
if ($f =~ m/^['"]/ and $f =~ m/['"]$/) {
$f =~ s/^['"]//;
$f =~ s/['"]$//;
}
else {
$f =~ s/\*/%/g;
$f =~ s/\?/_/g;
$f =~ s/^\%*/%/;
$f =~ s/\%*$/%/;
$f = { '-ilike' => $f };
}
if ($set->search({'me.port' => $f})->count) {
$set = $set->search({'me.port' => $f});