Skip to content

Commit

Permalink
Merge pull request #1246 from CPAN-API/tsibley/module-name-search
Browse files Browse the repository at this point in the history
Search only by module name when a term is prefixed with "module:"
  • Loading branch information
oalders committed Jul 11, 2014
2 parents bd62213 + d385e52 commit 304bff2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/MetaCPAN/Web/Controller/Search.pm
Expand Up @@ -44,10 +44,11 @@ sub index : Path {

$query =~ s{author:([a-zA-Z]*)}{author:\U$1\E}g;
$query =~ s/dist(ribution)?:(\w+)/file.distribution:$2/g;
$query =~ s/module:([\w:]+)/module.name.analyzed:$1/g;

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

my @dists = $query =~ /distribution:(\S+)/g;
Expand Down
5 changes: 3 additions & 2 deletions lib/MetaCPAN/Web/Model/API/Module.pm
Expand Up @@ -61,10 +61,11 @@ sub autocomplete {
return $cv;
}

sub search_distribution {
sub search_expanded {
my ( $self, $query, $from, $user ) = @_;

# the distribution is included in the query and ES does the right thing
# When used for a distribution or module search, the limit is included in
# the query and ES does the right thing.
my $cv = $self->cv;
my ( $data, $total );
$data = $self->search(
Expand Down

0 comments on commit 304bff2

Please sign in to comment.