Changeset 2418


Ignore:
Timestamp:
06/25/20 11:22:38 (4 years ago)
Author:
nanardon
Message:

Change op. filter ! behavior

Now ! operator will eliminate from result any object not matching this
filter:

la-search memberOf=foo !memberOf=bar

will search all users member of foo only if they are member of bar

File:
1 edited

Legend:

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

    r2415 r2418  
    11061106    # foo=1 bar=1 => foo =1 and bar = 2 
    11071107    my $results = {}; 
    1108     my $NegResults = {}; 
    11091108    my $noalias = 0; 
    11101109 
     
    11161115    } 
    11171116 
     1117    my $FilterCounter = 0; 
    11181118    while (my $item = shift(@filter)) { 
     1119        $FilterCounter++; 
    11191120        # attr=foo => no extra white space ! 
    11201121        # \W is false, it is possible to have two char 
    1121         my ($NegFilter, $attr, $attrref, $operator, $val) = $item =~ /^([\!\+\-]?)(\w+)(?:\.([\.\w]+))?(?:([^\w*]+)(.+))?$/ or next; 
     1122        my ($OpFilter, $attr, $attrref, $operator, $val) = $item =~ /^([\!\+\-]?)(\w+)(?:\.([\.\w]+))?(?:([^\w*]+)(.+))?$/ or next; 
    11221123        if (!$operator) { 
    11231124            $operator = '~'; 
     
    11581159 
    11591160            if (!@results) { 
    1160                 if ($NegFilter eq '!') { 
    1161                     $NegResults->{$attrKey} ||= {}; 
     1161                if ($OpFilter eq '!') { 
     1162                    $results->{$attrKey} ||= {}; 
    11621163                } else { 
    11631164                    $results->{$attrKey} ||= {}; 
     
    11731174        $base->log(LA_DEBUG, "Search result: %s: %s", $attr, join(' ', @results)); 
    11741175 
    1175         if ($NegFilter eq '!') { 
    1176             # Filter result to remove: 
    1177             $NegResults->{$_} = 1 foreach (@results); 
    1178         } elsif ($NegFilter eq '-') { 
     1176        # ! Add a list of object included only if 
     1177        # we create a result list that will not be cumulated with same attribute 
     1178        if ( $OpFilter eq '!') { 
     1179            $attrKey .= '%' . $FilterCounter; 
     1180        } 
     1181 
     1182        if ($OpFilter eq '-') { 
    11791183            # Filter result to filter from attribute result 
    11801184            $results->{$attrKey} ||= {}; 
    11811185            $results->{$attrKey}{$_} = -1 foreach (@results); 
    1182         } elsif ($NegFilter eq '+') { 
     1186        } elsif ($OpFilter eq '+') { 
    11831187            # Filter result to filter from attribute result 
    11841188            $results->{$attrKey} ||= {}; 
     
    11981202        foreach my $value (sort(@values)) { 
    11991203            my $v = $results->{$attr}{$value} || 0; 
    1200             if ($v < 1 || $NegResults->{$value}) { 
    1201                 delete($mresults{$value}); 
     1204            if ( $v < 1 ) { 
     1205               delete($mresults{$value}); 
    12021206            } 
     1207 
    12031208        } 
    12041209    } 
Note: See TracChangeset for help on using the changeset viewer.