-my $users = RT::Users->new( $CurrentUser );
-$users->RowsPerPage( $max );
-
-$users->LimitToPrivileged() if $privileged;
-
-while (my ($name, $op) = each %fields) {
- $op = 'STARTSWITH'
- unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;
-
- $users->Limit(
- FIELD => $name,
- OPERATOR => $op,
- VALUE => $term,
- ENTRYAGGREGATOR => 'OR',
- SUBCLAUSE => 'autocomplete',
- );
-}
-
-# Exclude users we don't want
-foreach (split /\s*,\s*/, $exclude) {
- $users->Limit(FIELD => 'id', VALUE => $_, OPERATOR => '!=', ENTRYAGGREGATOR => 'AND');
-}
+my $users = RT::Users->new($CurrentUser);
+$users->SimpleSearch( Privileged => $privileged,
+ Return => $return,
+ Term => $term,
+ Max => $max,
+ Exclude => \@exclude,
+ # If an operator is provided, check against only
+ # the returned field using that operator
+ $op ? ( Fields => { $return => $op } ) : (),
+ );