Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/MGRAST/lib/resources2/m5nr.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ sub info {
'request' => $self->cgi->url."/".$self->name,
'description' => "Returns description of parameters and attributes.",
'method' => "GET",
'type' => "synchronous",
'type' => "synchronous",
'attributes' => "self",
'parameters' => { 'options' => {},
'required' => {},
Expand Down Expand Up @@ -136,7 +136,8 @@ sub info {
'method' => "GET",
'type' => "synchronous",
'attributes' => $self->{attributes}{annotation},
'parameters' => { 'options' => { 'limit' => ['integer','maximum number of items requested'],
'parameters' => { 'options' => { 'source' => ['string','source name to restrict search by'],
'limit' => ['integer','maximum number of items requested'],
'offset' => ['integer','zero based index of the first data object to be returned'],
"order" => ["string","name of the attribute the returned data is ordered by"],
'sequence' => [ 'boolean', "if true return sequence output, else return annotation output. default is false." ]
Expand All @@ -150,7 +151,8 @@ sub info {
'method' => "GET",
'type' => "synchronous",
'attributes' => $self->{attributes}{annotation},
'parameters' => { 'options' => { 'limit' => ['integer','maximum number of items requested'],
'parameters' => { 'options' => { 'source' => ['string','source name to restrict search by'],
'limit' => ['integer','maximum number of items requested'],
'offset' => ['integer','zero based index of the first data object to be returned'],
"order" => ["string","name of the attribute the returned data is ordered by"],
'sequence' => [ 'boolean', "if true return sequence output, else return annotation output. default is false." ]
Expand All @@ -164,7 +166,8 @@ sub info {
'method' => "GET",
'type' => "synchronous",
'attributes' => $self->{attributes}{annotation},
'parameters' => { 'options' => { 'limit' => ['integer','maximum number of items requested'],
'parameters' => { 'options' => { 'source' => ['string','source name to restrict search by'],
'limit' => ['integer','maximum number of items requested'],
'offset' => ['integer','zero based index of the first data object to be returned'],
"order" => ["string","name of the attribute the returned data is ordered by"]
},
Expand All @@ -177,7 +180,8 @@ sub info {
'method' => "GET",
'type' => "synchronous",
'attributes' => $self->{attributes}{annotation},
'parameters' => { 'options' => { 'limit' => ['integer','maximum number of items requested'],
'parameters' => { 'options' => { 'source' => ['string','source name to restrict search by'],
'limit' => ['integer','maximum number of items requested'],
'offset' => ['integer','zero based index of the first data object to be returned'],
"order" => ["string","name of the attribute the returned data is ordered by"]
},
Expand All @@ -190,7 +194,8 @@ sub info {
'method' => "GET",
'type' => "synchronous",
'attributes' => $self->{attributes}{annotation},
'parameters' => { 'options' => { 'limit' => ['integer','maximum number of items requested'],
'parameters' => { 'options' => { 'source' => ['string','source name to restrict search by'],
'limit' => ['integer','maximum number of items requested'],
'offset' => ['integer','zero based index of the first data object to be returned'],
"order" => ["string","name of the attribute the returned data is ordered by"]
},
Expand Down Expand Up @@ -330,14 +335,18 @@ sub instance {
sub query {
my ($self, $type, $item) = @_;

# pagination
# paramaters
my $source = $self->cgi->param('source') ? $self->cgi->param('source') : undef;
my $limit = $self->cgi->param('limit') ? $self->cgi->param('limit') : 10;
my $offset = $self->cgi->param('offset') ? $self->cgi->param('offset') : 0;
my $order = $self->cgi->param('offset') ? $self->cgi->param('offset') : undef;

# build url
my $path = '/'.$type.'/'.$item;
my $url = $self->cgi->url.'/m5nr'.$path.'?limit='.$limit.'&offset='.$offset;
if ($source) {
$url .= '&source='.$source;
}

# strip wildcards
$item =~ s/\*//g;
Expand All @@ -353,9 +362,9 @@ sub query {
my ($data, $total);
if ($type eq 'md5') {
my $md5 = $self->clean_md5($item);
($data, $total) = $self->solr_data('md5', $md5, $offset, $limit, $order);
($data, $total) = $self->solr_data('md5', $md5, $source, $offset, $limit, $order);
} else {
($data, $total) = $self->solr_data($type, $item, $offset, $limit, $order, 1);
($data, $total) = $self->solr_data($type, $item, $source, $offset, $limit, $order, 1);
}
my $obj = $self->check_pagination($data, $total, $limit, $path);
$obj->{url} = $url;
Expand All @@ -378,15 +387,19 @@ sub clean_md5 {
}

sub solr_data {
my ($self, $field, $text, $offset, $limit, $order, $partial) = @_;
my ($self, $field, $text, $source, $offset, $limit, $order, $partial) = @_;
$text = uri_unescape($text);
$text = uri_escape($text);
if ($partial) {
$text = '*'.$text.'*';
}
my $sort = $order ? $order.'_sort+asc' : '';
my $sort = $order ? $order.'_sort+asc' : '';
my $fields = ['source', 'function', 'accession', 'organism', 'ncbi_tax_id', 'type', 'md5'];
return $self->get_solr_query($Conf::m5nr_solr, $Conf::m5nr_collect, $field.'%3A'.$text, $sort, $offset, $limit, $fields);
my $query = $field.'%3A'.$text;
if ($source) {
$query .= '+AND+source%3A'.$source;
}
return $self->get_solr_query($Conf::m5nr_solr, $Conf::m5nr_collect, $query, $sort, $offset, $limit, $fields);
}

1;
Expand Down
2 changes: 2 additions & 0 deletions src/MGRAST/lib/resources2/resource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,15 @@ sub check_pagination {
my $prev_offset = (($offset - $limit) < 0) ? 0 : $offset - $limit;
my $next_offset = $offset + $limit;

my $this = $self->cgi->url."/".$self->name.$path."?$additional_params&offset=$offset";
my $prev = ($offset > 0) ? $self->cgi->url."/".$self->name.$path."?$additional_params&offset=$prev_offset" : undef;
my $next = (($offset < $total_count) && ($total_count > $limit)) ? $self->cgi->url."/".$self->name.$path."?$additional_params&offset=$next_offset" : undef;
my $object = { "limit" => int($limit),
"offset" => int($offset),
"total_count" => int($total_count),
"next" => $next,
"prev" => $prev,
"url" => $this,
"data" => $data };

if ($order) {
Expand Down