Skip to content

Commit

Permalink
move the logic of choosing expanded/collapsed to the api
Browse files Browse the repository at this point in the history
  • Loading branch information
jberger committed Nov 20, 2016
1 parent 12f02d5 commit 5d129aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
18 changes: 2 additions & 16 deletions lib/MetaCPAN/Web/Controller/Search.pm
Expand Up @@ -66,21 +66,7 @@ sub index : Path : Args(0) {
}
}
else {
my $user = $c->user_exists ? $c->user->id : undef;

# these would be nicer if we had variable-length lookbehinds...
$query =~ s{(^|\s)author:([a-zA-Z]+)(?=\s|$)}{$1author:\U$2\E}g;
$query
=~ s/(^|\s)dist(ribution)?:([\w-]+)(?=\s|$)/$1distribution:$3/g;
$query
=~ s/(^|\s)module:(\w[\w:]*)(?=\s|$)/$1module.name.analyzed:$2/g;

my $results
= $query =~ /(distribution|module\.name\S*):/
? $model->search_expanded( $query, $from, $page_size, $user )
: $model->search_collapsed( $query, $from, $page_size, $user );

my @dists = $query =~ /distribution:(\S+)/g;
my $results = $model->search_web( $query, $from, $page_size );

my $authors = $c->model('API::Author')->search( $query, $from );
( $results, $authors ) = ( $results->recv, $authors->recv );
Expand All @@ -102,7 +88,7 @@ sub index : Path : Args(0) {
$c->stash(
{
%$results,
single_dist => @dists == 1,
single_dist => !$results->{collapsed},
authors => $authors,
template => 'search.html',
page_size => $page_size,
Expand Down
17 changes: 2 additions & 15 deletions lib/MetaCPAN/Web/Model/API/Module.pm
Expand Up @@ -50,23 +50,10 @@ sub autocomplete {
return $cv;
}

sub search_expanded {
sub search_web {
my ( $self, $query, $from, $page_size ) = @_;
my $cv = $self->cv;
$self->request( "/search/expanded", undef,
{ q => $query, size => $page_size // 20, from => $from // 0 } )->cb(
sub {
my $data = shift->recv;
$cv->send($data);
}
);
return $cv;
}

sub search_collapsed {
my ( $self, $query, $from, $page_size, $user ) = @_;
my $cv = $self->cv;
$self->request( "/search/collapsed", undef,
$self->request( "/search/web", undef,
{ q => $query, size => $page_size // 20, from => $from // 0 } )->cb(
sub {
my $data = shift->recv;
Expand Down

0 comments on commit 5d129aa

Please sign in to comment.