Changeset 2393


Ignore:
Timestamp:
06/09/20 19:34:34 (4 years ago)
Author:
nanardon
Message:

Allow negative filter

!attr=... will remove from result any object macthing
-attr=a attr=b will act like all b without object matching a

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r2352 r2393  
    11041104    # foo=1 bar=1 => foo =1 and bar = 2 
    11051105    my $results = {}; 
     1106    my $NegResults = {}; 
    11061107    my $noalias = 0; 
    11071108 
     
    11161117        # attr=foo => no extra white space ! 
    11171118        # \W is false, it is possible to have two char 
    1118         my ($attr, $attrref, $operator, $val) = $item =~ /^(\w+)(?:\.([\.\w]+))?(?:([^\w*]+)(.+))?$/ or next; 
     1119        my ($NegFilter, $attr, $attrref, $operator, $val) = $item =~ /^([\!\-]?)(\w+)(?:\.([\.\w]+))?(?:([^\w*]+)(.+))?$/ or next; 
    11191120        if (!$operator) { 
    11201121            $operator = '~'; 
     
    11551156 
    11561157            if (!@results) { 
    1157                 $results->{$attrKey} ||= {}; 
     1158                if ($NegFilter eq '!') { 
     1159                    $NegResults->{$attrKey} ||= {}; 
     1160                } else { 
     1161                    $results->{$attrKey} ||= {}; 
     1162                } 
    11581163                next; 
    11591164            } 
     
    11651170 
    11661171        $base->log(LA_DEBUG, "Search result: %s: %s", $attr, join(' ', @results)); 
    1167         $results->{$attrKey} ||= {}; 
    1168         $results->{$attrKey}{$_} = 1 foreach (@results); 
     1172 
     1173        if ($NegFilter eq '!') { 
     1174            # Filter result to remove: 
     1175            $NegResults->{$_} = 1 foreach (@results); 
     1176        } elsif ($NegFilter eq '-') { 
     1177            # Filter result to filter from attribute result 
     1178            $results->{$attrKey} ||= {}; 
     1179            $results->{$attrKey}{$_} = -1 foreach (@results); 
     1180        } else { 
     1181            $results->{$attrKey} ||= {}; 
     1182            $results->{$attrKey}{$_} ||=  1 foreach (@results); 
     1183        } 
    11691184    } 
    11701185 
     
    11761191        my @values = keys %mresults; 
    11771192        foreach my $value (sort(@values)) { 
    1178             if (!$results->{$attr}{$value}) { 
     1193            my $v = $results->{$attr}{$value} || 0; 
     1194            if ($v < 1 || $NegResults->{$value}) { 
    11791195                delete($mresults{$value}); 
    11801196            } 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm

    r2386 r2393  
    129129                } else { 
    130130                    return( 
     131                        map { $_, "!$_", "-$_" } 
    131132                        map { ( $_ . '=', $_ . '~' ) } $_[0]->base->list_canonical_fields($_[2], 'r') 
    132133                    ); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Object.pm

    r2375 r2393  
    118118        completion => sub { 
    119119            return( 
     120                map { $_, "!$_", "-$_" } 
    120121                map { ( $_ . '=', $_ . '~' ) } $_[0]->base->list_canonical_fields($_[0]->{_otype}, 'r') 
    121122            ); 
Note: See TracChangeset for help on using the changeset viewer.