Created
February 27, 2017 23:02
-
-
Save dylanwh/5aa8fb27fab2a6dd0bd565939a144ca8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub suggest_users { | |
my ($self, $text) = @_; | |
my $field = 'suggest_user'; | |
if ($text =~ /^:(.+)$/) { | |
$text = $1; | |
$field = 'suggest_nick'; | |
} | |
my $result = eval { | |
$self->client->suggest( | |
index => $self->index_name, | |
body => { | |
$field => { | |
text => $text, | |
completion => { field => $field, size => 25 }, | |
} | |
} | |
); | |
}; | |
if (defined $result) { | |
return [ map { $_->{payload} } @{$result->{$field}[0]{options}} ]; | |
} | |
else { | |
warn "suggest_users error: $@"; | |
my $users = Bugzilla::User::match($text, 25, 0); | |
return [ map { { real_name => $_->name, name => $_->login } } @$users]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment