<commit_before>
=head1 NAME

SGN::Controller::AJAX::People - a REST controller class to provide the
backend for the sgn_people schema

=head1 DESCRIPTION

REST interface for searching people, getting user data, etc. 

=head1 AUTHOR

<NAME> <<EMAIL>>


=cut

package SGN::Controller::AJAX::People;

use Moose;

use List::MoreUtils qw /any /;
use Try::Tiny;
#use CXGN::Phenome::Schema;



BEGIN { extends 'Catalyst::Controller::REST' }

__PACKAGE__->config(
    default   => 'application/json',
    stash_key => 'rest',
    map       => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
   );



=head2 autocomplete

Public Path: /ajax/people/autocomplete

Autocomplete a person name.  Takes a single GET param,
    C<person>, responds with a JSON array of completions for that term.

=cut

sub autocomplete : Local : ActionClass('REST') { }

sub autocomplete_GET :Args(0) {
    my ( $self, $c ) = @_;

    my $person = $c->req->param('term');
    # trim and regularize whitespace
    $person =~ s/(^\s+|\s+)$//g;
    $person =~ s/\s+/ /g;
    my $q = "SELECT sp_person_id, first_name, last_name FROM sgn_people.sp_person
             WHERE first_name ilike ? OR last_name ilike ?
             LIMIT 20";

    my $sth = $c->dbc->dbh->prepare($q);
    $sth->execute("\%$person\%" , "\%$person\%");
    my @results;
    while (my ($sp_person_id, $first_name, $last_name) = $sth->fetchrow_array ) {
        push @results , "$first_name, $last_name";
    }
    $c->{stash}->{rest} = \@results;
}


###
1;
<commit_msg>tweak solpeople autocomplete, just autocomplete using the beginnings of first names and last names, not the whole name<commit_after>
=head1 NAME

SGN::Controller::AJAX::People - a REST controller class to provide the
backend for the sgn_people schema

=head1 DESCRIPTION

REST interface for searching people, getting user data, etc. 

=head1 AUTHOR

<NAME> <<EMAIL>>


=cut

package SGN::Controller::AJAX::People;

use Moose;

use List::MoreUtils qw /any /;
use Try::Tiny;
#use CXGN::Phenome::Schema;



BEGIN { extends 'Catalyst::Controller::REST' }

__PACKAGE__->config(
    default   => 'application/json',
    stash_key => 'rest',
    map       => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
   );



=head2 autocomplete

Public Path: /ajax/people/autocomplete

Autocomplete a person name.  Takes a single GET param,
    C<person>, responds with a JSON array of completions for that term.

=cut

sub autocomplete : Local : ActionClass('REST') { }

sub autocomplete_GET :Args(0) {
    my ( $self, $c ) = @_;

    my $person = $c->req->param('term');
    # trim and regularize whitespace
    $person =~ s/(^\s+|\s+)$//g;
    $person =~ s/\s+/ /g;
    my $q = "SELECT sp_person_id, first_name, last_name FROM sgn_people.sp_person
             WHERE lower(first_name) like ? OR lower(last_name) like ?
             LIMIT 20";

    my $sth = $c->dbc->dbh->prepare($q);
    $sth->execute( lc "$person\%" , lc "$person\%" );
    my @results;
    while (my ($sp_person_id, $first_name, $last_name) = $sth->fetchrow_array ) {
        push @results , "$first_name, $last_name";
    }
    $c->{stash}->{rest} = \@results;
}


###
1;

{'fraction_non_alphanumeric': 0.15647766867279062, 'fraction_numerical': 0.005068102629078239, 'mean_word_length': 3.349862258953168, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1764519', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1092, 'n_words': 302}