Skip to content

Commit

Permalink
Implement DuckDuckGo-like ! (or \\) syntax for IFL
Browse files Browse the repository at this point in the history
Instead of having to pass lucky=1 as a GET parameter you can now enter
a search term beginning with "!" or "\" to have MetaCPAN return the
first result to you.

E.g. searching for "!Plack" or "\Plack" will redirect you to
/module/Plack.

This is an alternative to pressing Shift+Enter on the site to go to
the first result, but the real value is being able to use
e.g. DuckDuckGo to search for "!cpan !Plack" to go to the first
MetaCPAN result.

See-Also: metacpan#269
  • Loading branch information
avar committed Aug 28, 2011
1 parent bcfec8c commit fe27944
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/MetaCPAN/Web/Controller/Search.pm
Expand Up @@ -23,7 +23,10 @@ sub index : Path {

my $model = $c->model('API::Module');
my $from = ( $req->page - 1 ) * 20;
if ( $req->parameters->{lucky} ) {
if ( $req->parameters->{lucky} or
# DuckDuckGo-like syntax for bangs that redirect to the first
# result.
$query =~ s[^ (?: \\ | ! ) ][]x) {
my $module = $model->first($query)->recv;
$c->detach('/not_found') unless ($module);
$c->res->redirect("/module/$module");
Expand Down

0 comments on commit fe27944

Please sign in to comment.