Commit 4b817d1d62fbb48c7a846c95986a52d4613c4587
1 parent
325ea765
Exists in
master
and in
29 other branches
ActionItem405: removing comments from search
Commiting now in the correct item Revert "ActionItem405: reverting commit in the wrong item" This reverts commit 3d9c3224059f6b81d666504a05581e3b68147fa9. git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1899 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
6 changed files
with
57 additions
and
21 deletions
Show diff stats
app/controllers/public/search_controller.rb
@@ -90,7 +90,6 @@ class SearchController < ApplicationController | @@ -90,7 +90,6 @@ class SearchController < ApplicationController | ||
90 | 90 | ||
91 | SEARCH_IN = [ | 91 | SEARCH_IN = [ |
92 | [ :articles, N_('Articles') ], | 92 | [ :articles, N_('Articles') ], |
93 | - [ :comments, N_('Comments') ], | ||
94 | [ :enterprises, N_('Enterprises') ], | 93 | [ :enterprises, N_('Enterprises') ], |
95 | [ :people, N_('People') ], | 94 | [ :people, N_('People') ], |
96 | [ :communities, N_('Communities') ], | 95 | [ :communities, N_('Communities') ], |
app/helpers/assets_helper.rb
@@ -9,7 +9,6 @@ module AssetsHelper | @@ -9,7 +9,6 @@ module AssetsHelper | ||
9 | [ options.merge(:asset => 'products'), "icon-menu-product", _('Products') ], | 9 | [ options.merge(:asset => 'products'), "icon-menu-product", _('Products') ], |
10 | [ options.merge(:asset => 'enterprises'), "icon-menu-enterprise", _('Enterprises') ], | 10 | [ options.merge(:asset => 'enterprises'), "icon-menu-enterprise", _('Enterprises') ], |
11 | [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ], | 11 | [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ], |
12 | - [ options.merge(:asset => 'comments'), "icon-menu-comments", _('Comments') ], | ||
13 | [ options.merge(:asset => 'events'), "icon-menu-events", _('Events') ], | 12 | [ options.merge(:asset => 'events'), "icon-menu-events", _('Events') ], |
14 | 13 | ||
15 | ].map do |target,css_class,name| | 14 | ].map do |target,css_class,name| |
app/models/article.rb
@@ -21,7 +21,11 @@ class Article < ActiveRecord::Base | @@ -21,7 +21,11 @@ class Article < ActiveRecord::Base | ||
21 | 21 | ||
22 | acts_as_versioned | 22 | acts_as_versioned |
23 | 23 | ||
24 | - acts_as_searchable | 24 | + acts_as_searchable :additional_fields => [ :comment_data ] |
25 | + | ||
26 | + def comment_data | ||
27 | + comments.map {|item| [item.title, item.body].join(' ') }.join(' ') | ||
28 | + end | ||
25 | 29 | ||
26 | before_update do |article| | 30 | before_update do |article| |
27 | article.advertise = true | 31 | article.advertise = true |
@@ -120,6 +124,10 @@ class Article < ActiveRecord::Base | @@ -120,6 +124,10 @@ class Article < ActiveRecord::Base | ||
120 | end | 124 | end |
121 | end | 125 | end |
122 | 126 | ||
127 | + def comments_updated | ||
128 | + ferret_update | ||
129 | + end | ||
130 | + | ||
123 | private | 131 | private |
124 | 132 | ||
125 | def sanitize_tag_list | 133 | def sanitize_tag_list |
app/models/comment.rb
1 | class Comment < ActiveRecord::Base | 1 | class Comment < ActiveRecord::Base |
2 | 2 | ||
3 | - acts_as_searchable :fields => [:title, :body] | ||
4 | - | ||
5 | validates_presence_of :title, :body | 3 | validates_presence_of :title, :body |
6 | belongs_to :article, :counter_cache => true | 4 | belongs_to :article, :counter_cache => true |
7 | belongs_to :author, :class_name => 'Person', :foreign_key => 'author_id' | 5 | belongs_to :author, :class_name => 'Person', :foreign_key => 'author_id' |
@@ -45,4 +43,10 @@ class Comment < ActiveRecord::Base | @@ -45,4 +43,10 @@ class Comment < ActiveRecord::Base | ||
45 | self.find(:all, :order => 'comments.title', :conditions => ['comments.title like (?) or comments.title like (?)', initial + '%', initial.upcase + '%']) | 43 | self.find(:all, :order => 'comments.title', :conditions => ['comments.title like (?) or comments.title like (?)', initial + '%', initial.upcase + '%']) |
46 | end | 44 | end |
47 | 45 | ||
46 | + after_save :notify_article | ||
47 | + after_destroy :notify_article | ||
48 | + def notify_article | ||
49 | + article.comments_updated | ||
50 | + end | ||
51 | + | ||
48 | end | 52 | end |
test/unit/article_test.rb
@@ -286,5 +286,26 @@ class ArticleTest < Test::Unit::TestCase | @@ -286,5 +286,26 @@ class ArticleTest < Test::Unit::TestCase | ||
286 | assert_equal true, a1.display_to?(member) | 286 | assert_equal true, a1.display_to?(member) |
287 | end | 287 | end |
288 | 288 | ||
289 | + should 'reindex when comments are changed' do | ||
290 | + a = Article.new | ||
291 | + a.expects(:ferret_update) | ||
292 | + a.comments_updated | ||
293 | + end | ||
294 | + | ||
295 | + should 'index comments title together with article' do | ||
296 | + owner = create_user('testuser').person | ||
297 | + art = owner.articles.build(:name => 'ytest'); art.save! | ||
298 | + c1 = art.comments.build(:title => 'a nice comment', :body => 'anything', :author => owner); c1.save! | ||
299 | + | ||
300 | + assert_includes Article.find_by_contents('nice'), art | ||
301 | + end | ||
302 | + | ||
303 | + should 'index comments body together with article' do | ||
304 | + owner = create_user('testuser').person | ||
305 | + art = owner.articles.build(:name => 'ytest'); art.save! | ||
306 | + c1 = art.comments.build(:title => 'test comment', :body => 'anything', :author => owner); c1.save! | ||
307 | + | ||
308 | + assert_includes Article.find_by_contents('anything'), art | ||
309 | + end | ||
289 | 310 | ||
290 | end | 311 | end |
test/unit/comment_test.rb
@@ -93,22 +93,6 @@ class CommentTest < Test::Unit::TestCase | @@ -93,22 +93,6 @@ class CommentTest < Test::Unit::TestCase | ||
93 | assert_equal 'comment-4321', comment.anchor | 93 | assert_equal 'comment-4321', comment.anchor |
94 | end | 94 | end |
95 | 95 | ||
96 | - should 'be searched by contents of title' do | ||
97 | - owner = create_user('testuser').person | ||
98 | - art = owner.articles.build(:name => 'ytest'); art.save! | ||
99 | - c1 = art.comments.build(:title => 'a nice comment', :body => 'anything', :author => owner); c1.save! | ||
100 | - | ||
101 | - assert_includes Comment.find_by_contents('nice'), c1 | ||
102 | - end | ||
103 | - | ||
104 | - should 'be searched by contents of body' do | ||
105 | - owner = create_user('testuser').person | ||
106 | - art = owner.articles.build(:name => 'ytest'); art.save! | ||
107 | - c1 = art.comments.build(:title => 'test comment', :body => 'anything', :author => owner); c1.save! | ||
108 | - | ||
109 | - assert_includes Comment.find_by_contents('anything'), c1 | ||
110 | - end | ||
111 | - | ||
112 | should 'be able to find recent comments' do | 96 | should 'be able to find recent comments' do |
113 | Comment.delete_all | 97 | Comment.delete_all |
114 | 98 | ||
@@ -155,4 +139,25 @@ class CommentTest < Test::Unit::TestCase | @@ -155,4 +139,25 @@ class CommentTest < Test::Unit::TestCase | ||
155 | assert_not_includes list, c2 | 139 | assert_not_includes list, c2 |
156 | end | 140 | end |
157 | 141 | ||
142 | + should 'notify article to reindex after saving' do | ||
143 | + owner = create_user('testuser').person | ||
144 | + article = owner.articles.create!(:name => 'test', :body => '...') | ||
145 | + | ||
146 | + article.expects(:comments_updated) | ||
147 | + | ||
148 | + c1 = article.comments.new(:title => "A comment", :body => '...', :author => owner) | ||
149 | + c1.stubs(:article).returns(article) | ||
150 | + c1.save! | ||
151 | + end | ||
152 | + | ||
153 | + should 'notify article to reindex after being removed' do | ||
154 | + owner = create_user('testuser').person | ||
155 | + article = owner.articles.create!(:name => 'test', :body => '...') | ||
156 | + c1 = article.comments.create!(:title => "A comment", :body => '...', :author => owner) | ||
157 | + | ||
158 | + c1.stubs(:article).returns(article) | ||
159 | + article.expects(:comments_updated) | ||
160 | + c1.destroy | ||
161 | + end | ||
162 | + | ||
158 | end | 163 | end |