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;
# 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});

View File

@@ -14,7 +14,7 @@
<td>[% row.alias | html_entity %]</a>
<td>[% row.dns | html_entity %]</a>
<td class="nd_center-cell"><a class="nd_linkcell"
href="[% device_ports %]&q=[% params.q | uri %]&f=[% row.port | uri %]">[% row.port | html_entity %]</a></td>
href="[% device_ports %]&q=[% params.q | uri %]&f=%22[% row.port | uri %]%22">[% row.port | html_entity %]</a></td>
<td>[% row.device_port.name | html_entity %]</td>
<td><a class="nd_linkcell"
href="[% search_device %]&ip=[% row.subnet | uri %]">[% row.subnet | html_entity %]</a></td>

View File

@@ -61,7 +61,7 @@
<td nowrap>
[% END %]
<a class="nd_linkcell nd_this-port-only" href="[% uri_for('/device',
self_options) %]&q=[% params.q | uri %]&f=[% row.port | uri %]">
self_options) %]&q=[% params.q | uri %]&f=%22[% row.port | uri %]%22">
[% row.port | html_entity %]
</a></td>
[% END %]
@@ -211,7 +211,7 @@
[% IF params.c_neighbors AND (row.remote_ip OR row.is_uplink) %]
[% IF row.neighbor %]
<a href="[% uri_for('/device',
self_options) %]&q=[% row.neighbor.dns || row.neighbor.ip | uri %]&f=[% row.remote_port | uri %]">
self_options) %]&q=[% row.neighbor.dns || row.neighbor.ip | uri %]&f=%22[% row.remote_port | uri %]%22">
[% row.neighbor.dns.remove(settings.domain_suffix) || row.neighbor.ip | html_entity %]
([% row.remote_port | html_entity %]
[% ' id: '_ row.remote_id IF row.remote_id %]

View File

@@ -14,13 +14,13 @@
<tr>
<td class="nd_center-cell">[% row.left_dns || row.left_ip | html_entity %]</td>
<td class="nd_center-cell"><a class="nd_linkcell"
href="[% device_ports %]&q=[% row.left_dns || row.left_ip | uri %]&f=[% row.left_port | uri %]&c_duplex=on">
href="[% device_ports %]&q=[% row.left_dns || row.left_ip | uri %]&f=%22[% row.left_port | uri %]%22&c_duplex=on">
[% row.left_port | html_entity %]</a></td>
<td class="nd_center-cell">[% row.left_duplex.ucfirst | html_entity %]</td>
<td class="nd_center-cell">[% row.right_dns || row.right_ip | html_entity %]</a>
<td class="nd_center-cell"><a class="nd_linkcell"
href="[% device_ports %]&q=[% row.right_dns || row.right_ip | uri %]&f=[% row.right_port | uri %]&c_duplex=on">
href="[% device_ports %]&q=[% row.right_dns || row.right_ip | uri %]&f=%22[% row.right_port | uri %]%22&c_duplex=on">
[% row.right_port | html_entity %]</a></td>
<td class="nd_center-cell">[% row.right_duplex.ucfirst | html_entity %]</td>
</tr>

View File

@@ -12,7 +12,7 @@
<tr>
<td>[% row.device.dns || row.device.ip | html_entity %]</td>
<td class="nd_center-cell"><a class="nd_linkcell"
href="[% device_ports %]&q=[% row.device.dns || row.device.ip | uri %]&f=[% row.port | uri %]&c_duplex=on">
href="[% device_ports %]&q=[% row.device.dns || row.device.ip | uri %]&f=%22[% row.port | uri %]%22&c_duplex=on">
[% row.port | html_entity %]</a></td>
<td class="nd_center-cell">[% row.name | html_entity %]</td>
<td class="nd_center-cell">[% row.duplex.ucfirst | html_entity %]</td>

View File

@@ -40,7 +40,7 @@
[% END %]
<td>Switch Port</td>
<td><a class="nd_linkcell"
href="[% device_ports %]&q=[% node.device.dns || node.switch | uri %]&f=[% node.port | uri %]&c_nodes=on&c_neighbors=on">
href="[% device_ports %]&q=[% node.device.dns || node.switch | uri %]&f=%22[% node.port | uri %]%22&c_nodes=on&c_neighbors=on">
[% node.switch | html_entity %] - [% node.port | html_entity %]</a>
[% '&nbsp;<i class="icon-book text-warning"></i>&nbsp;' IF NOT node.active %]
[% IF node.device.dns AND node.device_port AND node.device_port.name %]

View File

@@ -69,7 +69,7 @@
[% END %]
<td>Switch Port</td>
<td><a class="nd_linkcell"
href="[% device_ports %]&q=[% node.device.dns || node.switch | uri %]&f=[% node.port | uri %]&c_nodes=on&c_neighbors=on">
href="[% device_ports %]&q=[% node.device.dns || node.switch | uri %]&f=%22[% node.port | uri %]%22&c_nodes=on&c_neighbors=on">
[% node.switch | html_entity %] - [% node.port | html_entity %]</a>
[% '&nbsp;<i class="icon-book text-warning"></i>&nbsp;' IF NOT node.active %]
[% IF node.device.dns AND node.device_port AND node.device_port.name %]
@@ -104,7 +104,7 @@
[% END %]
<td>Switch Port</td>
<td><a class="nd_linkcell"
href="[% device_ports %]&q=[% port.device.dns || port.ip | uri %]&f=[% port.port | uri %]&c_mac=on&c_nodes=on&c_neighbors=on">
href="[% device_ports %]&q=[% port.device.dns || port.ip | uri %]&f=%22[% port.port | uri %]%22&c_mac=on&c_nodes=on&c_neighbors=on">
[% port.ip | html_entity %] - [% port.descr | html_entity %]</a>
[% IF port.device.dns AND port.name %]
([% port.device.dns | html_entity %] - [% port.name | html_entity %])

View File

@@ -11,7 +11,7 @@
[% WHILE (row = results.next) %]
<tr>
<td>[% row.name | html_entity %]</td>
<td><a href="[% device_ports %]&q=[% row.device.dns || row.ip | uri %]&f=[% row.port | uri %]">
<td><a href="[% device_ports %]&q=[% row.device.dns || row.ip | uri %]&f=%22[% row.port | uri %]%22">
[% row.ip | html_entity %] [ [% row.port | html_entity %] ]</a>
[% ' (' _ row.device.dns _ ')' IF row.device.dns %]
</td>

View File

@@ -68,7 +68,7 @@
var port = $(this).text();
port = $.trim(port);
portfilter.val(port);
portfilter.val('"'+ port +'"');
$('.nd_field-clear-icon').show();
$('#ports_form').trigger('submit');