Skip to content

Commit

Permalink
Added automatic author search to the search page
Browse files Browse the repository at this point in the history
  • Loading branch information
Clinton Gormley committed Jul 29, 2011
1 parent 10b152d commit c884a3b
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 19 deletions.
4 changes: 4 additions & 0 deletions lib/MetaCPAN/Web/Controller/Search.pm
Expand Up @@ -33,6 +33,10 @@ sub index : Path {
: $model->search_collapsed( $query, $from, $pause_id )->recv;
$c->stash({%$results, template => 'search.html'});
}

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

1;
35 changes: 35 additions & 0 deletions lib/MetaCPAN/Web/Model/API/Author.pm
Expand Up @@ -29,6 +29,41 @@ sub get {

}

sub search {
my ( $self, $query, $from ) = @_;

my $cv = $self->cv;
my $search = {
query => {
bool => {
should => [
{ text => { 'author.name.analyzed' => $query } },
{ text => { 'author.pauseid' => uc($query) } }
]
}
},
size => 10,
from => $from || 0,
};

$self->request( '/author/_search', $search )->(
sub {
my $results = shift->recv
|| { hits => { total => 0, hits => [] } };
$cv->send( {
results => [
map { +{ %{ $_->{_source} }, id => $_->{_id} } }
@{ $results->{hits}{hits} }
],
total => $results->{hits}{total} || 0,
took => $results->{took}
}
);
}
);
return $cv;
}

__PACKAGE__->meta->make_immutable;

1;
19 changes: 19 additions & 0 deletions root/search.html
Expand Up @@ -28,6 +28,25 @@
</div>

<div class="search-results">
<% IF authors.total %>
<div id="author-results">
<ul class="authors">
<% FOREACH author IN authors.results %>
<li>
<a href = "/author/<% author.id %>"
title = "Author page for <% author.name %>"
>
<% IF author.gravatar_url %>
<img src="<% author.gravatar_url %>" class="author-img">
<% END %>
<% author.name %> (<% author.pauseid %>)
</a>
</li>
<% END %>
</ul>
</div>
<% END %>

<% FOREACH group IN results; item = group.0 %>
<big><strong>
<% IF item.documentation -%>
Expand Down
80 changes: 61 additions & 19 deletions root/static/css/style.css
Expand Up @@ -15,10 +15,10 @@ hr {
border-top: 1px solid #e9e9e9;
}

html {
margin:0;
padding:0;
border:0;
html {
margin:0;
padding:0;
border:0;
overflow-y: scroll;
}

Expand All @@ -33,12 +33,12 @@ hgroup, nav, section {
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
font: inherit;
vertical-align: baseline;
}

/* This helps to make newer HTML5 elements behave like DIVs in older browers */
article, aside, details, figcaption, figure, dialog,
/* This helps to make newer HTML5 elements behave like DIVs in older browers */
article, aside, details, figcaption, figure, dialog,
footer, header, hgroup, menu, nav, section {
display:block;
}
Expand All @@ -50,22 +50,22 @@ pre {
/* Line-height should always be unitless! */
body {
line-height: 1.5;
background: white;
background: white;
}

/* Tables still need 'cellspacing="0"' in the markup. */
table {
border-collapse: separate;
border-spacing: 0;
table {
border-collapse: separate;
border-spacing: 0;
}
/* float:none prevents the span-x classes from breaking table-cell display */
caption, th, td {
text-align: left;
font-weight: normal;
float:none !important;
caption, th, td {
text-align: left;
font-weight: normal;
float:none !important;
}
table, th, td {
vertical-align: middle;
table, th, td {
vertical-align: middle;
}

/* Remove possible quote marks (") from <q>, <blockquote>. */
Expand Down Expand Up @@ -266,6 +266,47 @@ input.g-button:active, button.g-button:active, a.g-button:active {
line-height: 1;
}

#author-results ul {
display: inline-block;
margin: 10px 0;
}

#author-results li {
float: left;
width: 100px;
padding: 5px 5px 5px 45px;
margin-right: 10px;
border: 1px solid white;
overflow: hidden;
height: 50px;
}

#author-results li:hover {
border: 1px solid #eee;
-webkit-border-radius: 3px 3px;
-moz-border-radius: 3px 3px;
-moz-box-shadow: 3px 3px 5px #eee;
-webkit-box-shadow: 3px 3px 5px #eee;
box-shadow: 3px 3px 5px #eee;
}

#author-results a {
display: block;
}

#author-results a:hover {
text-decoration: none;
}

#author-results img {
width: 30px;
height: 30px;
margin-left: -40px;
float: left;
}



button.favorite, a.favorite {
padding: 1px 3px;
margin-left: 10px;
Expand Down Expand Up @@ -332,7 +373,7 @@ button.favorite:hover, button.favorite.active, a.favorite.active, a.favorite:hov
.account-bar a:hover {
text-decoration: none;
background-color: #f9f9f9;

}

.account-bar a.active {
Expand Down Expand Up @@ -491,6 +532,7 @@ ul#index, #index ul { list-style-type: none; }
background-color: #f9f9f9 !important;
}

.search-results img,
.author-img {
overflow:hidden;
width: 130px;
Expand Down Expand Up @@ -520,7 +562,7 @@ ul {
width: 160px;
padding-left: 10px;
overflow: auto;

}

a.ellipsis {
Expand Down

0 comments on commit c884a3b

Please sign in to comment.