Skip to content

Instantly share code, notes, and snippets.

@dylanwh
Created February 27, 2017 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanwh/5aa8fb27fab2a6dd0bd565939a144ca8 to your computer and use it in GitHub Desktop.
Save dylanwh/5aa8fb27fab2a6dd0bd565939a144ca8 to your computer and use it in GitHub Desktop.
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