From 1b89d20dc7dcdf32e0989f2bd9022b4d9edada60 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 18 Aug 2019 11:19:34 +0100 Subject: [PATCH] #624 device layers search should be OR (not AND) --- lib/App/Netdisco/DB/ResultSet/Device.pm | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/App/Netdisco/DB/ResultSet/Device.pm b/lib/App/Netdisco/DB/ResultSet/Device.pm index 5520fedc..fa5ce923 100644 --- a/lib/App/Netdisco/DB/ResultSet/Device.pm +++ b/lib/App/Netdisco/DB/ResultSet/Device.pm @@ -226,21 +226,20 @@ sub search_by_field { } # For Search on Layers - my @layer_search = ( '_', '_', '_', '_', '_', '_', '_' ); - # @layer_search is computer indexed, left->right my $layers = $p->{layers}; + my @layer_select = (); if ( defined $layers && ref $layers ) { foreach my $layer (@$layers) { next unless defined $layer and length($layer); next if ( $layer < 1 || $layer > 7 ); - $layer_search[ $layer - 1 ] = 1; + push @layer_select, + \[ 'substring(me.layers,9-?, 1)::int = 1', $layer ]; } } elsif ( defined $layers ) { - $layer_search[ $layers - 1 ] = 1; + push @layer_select, + \[ 'substring(me.layers,9-?, 1)::int = 1', $layers ]; } - # the database field is in order 87654321 - my $layer_string = join( '', reverse @layer_search ); return $rs ->search_rs({}, $attrs) @@ -252,8 +251,6 @@ sub search_by_field { { '-ilike' => "\%$p->{location}\%" }) : ()), ($p->{description} ? ('me.description' => { '-ilike' => "\%$p->{description}\%" }) : ()), - ($p->{layers} ? ('me.layers' => - { '-ilike' => "\%$layer_string" }) : ()), ($p->{model} ? ('me.model' => { '-in' => $p->{model} }) : ()), @@ -264,6 +261,8 @@ sub search_by_field { ($p->{vendor} ? ('me.vendor' => { '-in' => $p->{vendor} }) : ()), + ($p->{layers} ? (-or => \@layer_select) : ()), + ($p->{dns} ? ( -or => [ 'me.dns' => { '-ilike' => "\%$p->{dns}\%" },