much better wildcard/partial port search

This does not require silly quoting. It adds a "partial"
checkbox in the ports sidebar. If this is ticked, simple
wildcarding * and ? are also supported.
This commit is contained in:
Oliver Gorwits
2013-09-10 23:26:08 +01:00
parent 282e2d9c7c
commit 77690513b8
3 changed files with 36 additions and 3 deletions

View File

@@ -31,9 +31,16 @@ 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 };
if (param('partial')) {
# change wildcard chars to SQL
$f =~ s/\*/%/g;
$f =~ s/\?/_/g;
# set wilcards at param boundaries
$f =~ s/^\%*/%/;
$f =~ s/\%*$/%/;
# enable ILIKE op
$f = { '-ilike' => $f };
}
if ($set->search({'me.port' => $f})->count) {
$set = $set->search({'me.port' => $f});