Skip to content

Improve no result page #1210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 9, 2014
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
21 changes: 21 additions & 0 deletions lib/MetaCPAN/Web/Controller/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ sub index : Path {

my $authors = $c->model('API::Author')->search( $query, $from );
( $results, $authors ) = ( $results->recv, $authors->recv );

if ( $results->{total} == 1 ) {
my $module_name
= $results->{results}->[0]->[0]->{module}->[0]->{name};
$c->res->redirect("/pod/$module_name");
$c->detach;
}
elsif ( !$results->{total} && !$authors->{total} ) {
my $suggest = $query;
$suggest =~ s/:+/::/g;
if ( $suggest ne $query ) {
$c->stash(
{
suggest => $suggest,
}
);
}
$c->stash( template => 'no_result.html' );
$c->detach;
}

$c->stash(
{
%$results,
Expand Down
20 changes: 20 additions & 0 deletions root/left_sidebar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<ul class="nav nav-list slidepanel">
<li class="visible-phone search">
<form action="<% IF req.uri.path == '/mirrors'; req.uri.path; ELSE; '/search'; END %>">
<input type="search" placeholder="Search" name="q"><input type="submit" class="hidden">
</form>
</li>
<!--<ul class="search-type">
<a href="/search?q="><li class="icon icon-module">Modules</li></a>
<a href="/search?q=author:<% query %>"><li class="icon icon-user">Authors</li></a>
<li class="icon icon-dist">Distributions</li>
<li class="icon icon-server">Mirrors</li>
</ul>
<hr>-->
<li class="nav-header">Something missing?</li>
<li>
<div>
<a href="/about/missing_modules">Find out why</a>
</div>
</li>
</ul>
24 changes: 24 additions & 0 deletions root/no_result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%- query = req.param('q').join(' '); title = 'Search for "' _ query _ '"' %>
<% IF suggest %>
<% INCLUDE left_sidebar.html %>
<div class="no-results">
<div class="alert alert-error">
Did you mean :
<a href="/search?q=<% suggest | uri %>"><% suggest %></a>
</div>
</div>
<% ELSE %>
<div class="hero-unit">
<p class="nav-header">Something missing?
<a href="/about/missing_modules">Find out why</a>
</p>
<h2>No result.</h2>
<p> Sorry, we didn't find a match, maybe look at Task::Kensho, <br> which is a list of recommended modules for Enlightened Perl development.
</p>
<p>
<a class="btn btn-primary btn-large" href="/pod/Task::Kensho">
Learn more
</a>
</p>
</div>
<% END %>
22 changes: 2 additions & 20 deletions root/search.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
<%- query = req.param('q').join(' '); title = 'Search for "' _ query _ '"' %>
<ul class="nav nav-list slidepanel">
<li class="visible-phone search">
<form action="<% IF req.uri.path == '/mirrors'; req.uri.path; ELSE; '/search'; END %>">
<input type="search" placeholder="Search" name="q"><input type="submit" class="hidden">
</form>
</li>
<!--<ul class="search-type">
<a href="/search?q="><li class="icon icon-module">Modules</li></a>
<a href="/search?q=author:<% query %>"><li class="icon icon-user">Authors</li></a>
<li class="icon icon-dist">Distributions</li>
<li class="icon icon-server">Mirrors</li>
</ul>
<hr>-->
<li class="nav-header">Something missing?</li>
<li>
<div>
<a href="/about/missing_modules">Find out why</a>
</div>
</li>
</ul>

<% INCLUDE left_sidebar.html %>

<div class="search-results">
<% IF authors.total %>
Expand Down
4 changes: 4 additions & 0 deletions root/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,7 @@ div.qtip-github table th {
#contributors .contributor * {
vertical-align: top;
}
.smaller {
font-size: 1.0em;
line-height: 2.5em;
}
2 changes: 1 addition & 1 deletion root/static/less/responsive.less
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
height: 15px;
}

.search-results, .pod, .content {
.search-results, .pod, .content, .no-results {
margin-left: 0px;
border-left-width: 0px;
padding: 0px;
Expand Down
17 changes: 17 additions & 0 deletions root/static/less/search.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
list-style: none;
}
}
.no-results {
margin-left: 175px;
border-left: 1px solid #e9e9e9;
padding-left: 15px;
margin-top: 15px;
}


.search-bar .search-type {
font-size: 1.1em
Expand Down Expand Up @@ -41,3 +48,13 @@
text-shadow: 0px 1px 1px rgba(255,255,255,1);
line-height: 1;
}

.hero-unit .nav-header {
padding-left: 0px;
}

.hero-unit .nav-header a {
text-transform: none;
font-size: 1.2em;
font-weight: normal;
}
3 changes: 2 additions & 1 deletion root/static/less/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ body {
}

.smaller {
font-size: 0.8em;
font-size: 1.0em;
line-height: 2.5em;
}

.btn.btn-slidepanel {
Expand Down
13 changes: 9 additions & 4 deletions t/controller/search.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ test_psgi app, sub {

ok( $res = $cb->( GET "/search?q=moose\">" ), 'GET /search?q=moose">' );
is( $res->code, 200, 'code 200' );
ok(
$res->content =~ /0\s+results/,
'0 results for an invalid search term'
);
ok( $res->content =~ /Task::Kensho/,
'get recommendation about Task::Kensho on No result page' );

ok( $res = $cb->( GET "/search?q=ctx_request" ),
'GET /search?q=ctx_request' );
is( $res->code, 302,
'code 302 get redirected to the module if there is 1 result' );
is( $res->headers->{location},
'/pod/Catalyst::Test', 'get new location to module page' );

ok( $res = $cb->( GET "/search?q=moose" ), 'GET /search?q=moose' );
is( $res->code, 200, 'code 200' );
Expand Down
25 changes: 25 additions & 0 deletions t/controller/search/suggestion.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use strict;
use warnings;
use Test::More;
use MetaCPAN::Web::Test;

my %tests = (
'DBIx:Class:::ResultSet' => 'DBIx::Class::ResultSet',
'DBIx::Class:ResultSet' => 'DBIx::Class::ResultSet',
'DBIx:Class' => 'DBIx::Class',
);

test_psgi app, sub {
my $cb = shift;
while ( my ( $k, $v ) = each %tests ) {
ok( my $res = $cb->( GET "/search?q=$k" ), 'search for ' . $k );
my $tx = tx($res);
my $module
= $tx->find_value(
'//div[@class="no-results"]//div[@class="alert alert-error"]//a[1]'
);
is( $module, $v, "get no result page with suggestion" );
}
};

done_testing;