#302 Device searching now searches on module serial numbers

This commit is contained in:
Oliver Gorwits
2017-04-19 21:30:47 +01:00
parent ca3ed44ca5
commit d1a7761fda
2 changed files with 13 additions and 1 deletions

View File

@@ -1,3 +1,9 @@
2.035000 -
[ENHANCEMENTS]
* #302 Device searching now searches on module serial numbers
2.034003 - 2017-04-14
[ENHANCEMENTS]

View File

@@ -283,6 +283,8 @@ The following fields are inspected for a match:
=item serial
=item module serials (exact)
=item location
=item name
@@ -303,6 +305,7 @@ sub search_fuzzy {
die "missing param to search_fuzzy\n"
unless $q;
$q = "\%$q\%" if $q !~ m/\%/;
(my $qc = $q) =~ s/\%//g;
# basic IP check is a string match
my $ip_clause = [
@@ -311,7 +314,6 @@ sub search_fuzzy {
];
# but also allow prefix search
(my $qc = $q) =~ s/\%//g;
if (my $ip = NetAddr::IP::Lite->new($qc)) {
$ip_clause = [
'me.ip' => { '<<=' => $ip->cidr },
@@ -327,6 +329,10 @@ sub search_fuzzy {
'me.location' => { '-ilike' => $q },
'me.name' => { '-ilike' => $q },
'me.description' => { '-ilike' => $q },
'me.ip' => { '-in' =>
$rs->search({ 'modules.serial' => $qc },
{ join => 'modules', columns => 'ip' })->as_query()
},
-or => [
'me.dns' => { '-ilike' => $q },
'device_ips.dns' => { '-ilike' => $q },