#624 device layers search should be OR (not AND)

This commit is contained in:
Oliver Gorwits
2019-08-18 11:19:34 +01:00
parent 8d863113d9
commit 1b89d20dc7

View File

@@ -226,21 +226,20 @@ sub search_by_field {
} }
# For Search on Layers # For Search on Layers
my @layer_search = ( '_', '_', '_', '_', '_', '_', '_' );
# @layer_search is computer indexed, left->right
my $layers = $p->{layers}; my $layers = $p->{layers};
my @layer_select = ();
if ( defined $layers && ref $layers ) { if ( defined $layers && ref $layers ) {
foreach my $layer (@$layers) { foreach my $layer (@$layers) {
next unless defined $layer and length($layer); next unless defined $layer and length($layer);
next if ( $layer < 1 || $layer > 7 ); 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 ) { 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 return $rs
->search_rs({}, $attrs) ->search_rs({}, $attrs)
@@ -252,8 +251,6 @@ sub search_by_field {
{ '-ilike' => "\%$p->{location}\%" }) : ()), { '-ilike' => "\%$p->{location}\%" }) : ()),
($p->{description} ? ('me.description' => ($p->{description} ? ('me.description' =>
{ '-ilike' => "\%$p->{description}\%" }) : ()), { '-ilike' => "\%$p->{description}\%" }) : ()),
($p->{layers} ? ('me.layers' =>
{ '-ilike' => "\%$layer_string" }) : ()),
($p->{model} ? ('me.model' => ($p->{model} ? ('me.model' =>
{ '-in' => $p->{model} }) : ()), { '-in' => $p->{model} }) : ()),
@@ -264,6 +261,8 @@ sub search_by_field {
($p->{vendor} ? ('me.vendor' => ($p->{vendor} ? ('me.vendor' =>
{ '-in' => $p->{vendor} }) : ()), { '-in' => $p->{vendor} }) : ()),
($p->{layers} ? (-or => \@layer_select) : ()),
($p->{dns} ? ( ($p->{dns} ? (
-or => [ -or => [
'me.dns' => { '-ilike' => "\%$p->{dns}\%" }, 'me.dns' => { '-ilike' => "\%$p->{dns}\%" },