Skip to content

Commit

Permalink
Highlight search
Browse files Browse the repository at this point in the history
  • Loading branch information
dritoshi committed May 21, 2012
1 parent 7654fe1 commit 1f7817b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
16 changes: 13 additions & 3 deletions search/app/controllers/codes_controller.rb
Expand Up @@ -2,7 +2,18 @@ class CodesController < ApplicationController
# GET /codes
# GET /codes.json
def index

if params[:query] != ""
@search = Code.search do
fulltext params[:query] do
highlight :code
end
paginate :page => params[:page], :per_page => 30
end
else
@search = []
end
return @search
=begin
if params[:query] != ""
@search = Code.search do
fulltext params[:query] do
Expand All @@ -13,7 +24,7 @@ def index
else
@codes = []
end

=end
end

# GET /codes/1
Expand All @@ -26,6 +37,5 @@ def show
format.json { render json: @code }
end
end


end
16 changes: 13 additions & 3 deletions search/app/controllers/codes_controller.rb~
Expand Up @@ -2,7 +2,17 @@ class CodesController < ApplicationController
# GET /codes
# GET /codes.json
def index

if params[:query] != ""
@search = Code.search do
fulltext params[:query] do
highlight :code
end
end
else
@search = []
end

=begin
if params[:query] != ""
@search = Code.search do
fulltext params[:query] do
Expand All @@ -11,9 +21,9 @@ class CodesController < ApplicationController
end
@codes = @search.results
else
@codes = nil
@codes = []
end

=end
end

# GET /codes/1
Expand Down
37 changes: 20 additions & 17 deletions search/app/views/codes/index.html.erb
Expand Up @@ -6,31 +6,34 @@
<%= submit_tag "Search", :name => nil %>
<% end %>
<% if @codes == [] %>
<% if @search == [] %>
<div class="row">
Results: 0
</div>
<% else %>

<div class="row">
Results:
Results: <%= @search.hits.total_entries %>
</div>

<p>
<% @codes.each_with_index do |code, id| %>
<div class="row">
<h2><!--<%= id %>: --><%= link_to code.file, code_path(code) %> - <%= code.file_path %><br/></h2>
Package: <%= link_to code.package, "http://bioconductor.jp/packages/2.11/bioc/html/#{code.package}.html" %> -
Version: <%= code.version %> -
Language: <%= code.language %>
</div>

<div class="row">
<% cache do %>
<%== Pygments.highlight(CGI.unescapeHTML(code.code)) %>
<% end %>
</div>
<% @search.each_hit_with_result do |hit, code| %>
<% hit.highlights.each do |highlight| %>
<div class="row">
<h2>
<%= link_to code.file, code_path(code) %> - <%= code.file_path %><br/>
</h2>
Package: <%= link_to code.package, "http://bioconductor.jp/packages/2.11/bioc/html/#{code.package}.html" %> -
Version: <%= code.version %> -
Language: <%= code.language %>
</div>
<div class="row">
<% cache do %>
<%== Pygments.highlight(CGI.unescapeHTML(highlight.format {|word| word })) %>
<% end %>
</div>
<% end %>
<% end %>
<%= will_paginate(@codes, :renderer => WillPaginate::ActionView::LinkRenderer) %>
<% end %>
<%= will_paginate(@search.hits, :renderer => WillPaginate::ActionView::LinkRenderer) %>
<% end %>

0 comments on commit 1f7817b

Please sign in to comment.