Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve autocompleter and channel search

  • Loading branch information...
commit cd65b73349706a5fc4c9f6a8ead3563983f01d4d 1 parent 8427723
@mutle authored
View
5 app/assets/javascripts/autocompleter.coffee
@@ -31,7 +31,10 @@ class Autocompleter
autocompleter.setHighlight autocompleter.list.find("li").first()
return false
input = $(this).val()
- autocompleter.query "#{input}" if input.length >= 2
+ if input.length >= 2
+ autocompleter.query "#{input}"
+ else if input.length == 0
+ autocompleter.list.hide()
@o.blur ->
window.console.log 'blur'
autocompleter.list.hide()
View
4 app/controllers/application_controller.rb
@@ -35,6 +35,10 @@ def notification(type, object)
$redis.publish 'fu2_live', {:type => type, :object => object.as_json}.to_json
end
+ def highlight_results(text, query)
+ query.split(" ").inject(text) { |s,q| s = highlight(s, q) }
+ end
+ helper_method :highlight_results
helper_method :current_user
end
View
2  app/controllers/channels_controller.rb
@@ -72,7 +72,7 @@ def search
respond_to do |format|
format.html
- format.json { render :json => @search.map { |r| {:title => r.title, :display_title => highlight(r.title, @query), :id => r.id} } }
+ format.json { render :json => @search.map { |r| {:title => r.title, :display_title => highlight_results(r.title, @query), :id => r.id} } }
end
end
View
6 app/models/channel.rb
@@ -48,8 +48,10 @@ def self.all_channels(_user, page)
def self.search_channels(title, page)
search :per_page => 25, :page => page, :load => true do
query do
- title.split(' ').each do |t|
- string "*#{t}*"
+ boolean do
+ title.split(' ').each do |t|
+ must { string "*#{t}*" }
+ end
end
end
end
View
2  app/views/channels/search.html.haml
@@ -13,6 +13,6 @@
-post_link = channel_path(post.channel, :anchor => "post_#{post.id}")
=link_to "Channel Title: #{post.channel.title}", post_link
%br/
- =link_to "Post: #{highlight h(post.body), @query}".html_safe, post_link
+ =link_to "Post: #{highlight_results h(post.body), @query}".html_safe, post_link
==by #{user_name(post.channel.user)}
=will_paginate(@search)
Please sign in to comment.
Something went wrong with that request. Please try again.