hydra-server: add limit parameter to the search path

This allows a client to set a limit to the search results it wants to
get:

    http://hydra.nixos.org/search?query=emacs&limit=1

This returns only 1 results (while the default is 500).
This commit is contained in:
Antoine Eiche 2019-06-19 12:33:25 +02:00
parent cb1fce21ba
commit d1e590af1f

View file

@ -391,7 +391,12 @@ sub search :Local Args(0) {
error($c, "Invalid character in query.") error($c, "Invalid character in query.")
unless $query =~ /^[a-zA-Z0-9_\-\/.]+$/; unless $query =~ /^[a-zA-Z0-9_\-\/.]+$/;
$c->stash->{limit} = 500; my $limit = trim $c->request->params->{"limit"};
if ($limit eq "") {
$c->stash->{limit} = 500;
} else {
$c->stash->{limit} = $limit;
}
$c->stash->{projects} = [ $c->model('DB::Projects')->search( $c->stash->{projects} = [ $c->model('DB::Projects')->search(
{ -and => { -and =>