Commit 518f2836b6e38cad3f777593f8ef54ab0207cada
1 parent
df8d2e9c
Exists in
master
and in
29 other branches
ActionItem562: fixed search for articles
reworked find_by_contents to use find_ids_with_ferret istead of find_with_ferret so that when you are searching Article.find_by_contents(query) it returns TinyMceArticles git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2277 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
24 additions
and
2 deletions
Show diff stats
lib/acts_as_searchable.rb
... | ... | @@ -2,8 +2,23 @@ class << ActiveRecord::Base |
2 | 2 | |
3 | 3 | def acts_as_searchable(options = {}) |
4 | 4 | acts_as_ferret({ :remote => true }.merge(options)) |
5 | - def find_by_contents(*args) | |
6 | - find_with_ferret(*args) | |
5 | + def find_by_contents(query, ferret_options = {}, db_options = {}) | |
6 | + if ferret_options[:page] | |
7 | + db_options[:page] = ferret_options.delete(:page) | |
8 | + end | |
9 | + if ferret_options[:per_page] | |
10 | + db_options[:per_page] = ferret_options.delete(:per_page) | |
11 | + end | |
12 | + | |
13 | + ids = find_ids_with_ferret(query, ferret_options)[1].map{|r|r[:id].to_i} | |
14 | + if db_options[:conditions] | |
15 | + db_options[:conditions] = sanitize_sql_for_conditions(db_options[:conditions]) + " and #{table_name}.id in (#{ids.join(', ')})" | |
16 | + else | |
17 | + db_options[:conditions] = "#{table_name}.id in (#{ids.join(', ')})" | |
18 | + end | |
19 | + | |
20 | + db_options[:page] ||= 1 | |
21 | + paginate(:all, db_options) | |
7 | 22 | end |
8 | 23 | end |
9 | 24 | ... | ... |
test/unit/tiny_mce_article_test.rb
... | ... | @@ -15,4 +15,11 @@ class TinyMceArticleTest < Test::Unit::TestCase |
15 | 15 | assert_kind_of String, TinyMceArticle.short_description |
16 | 16 | end |
17 | 17 | |
18 | + should 'be found when searching for articles by query' do | |
19 | + ze = create_user('zezinho').person | |
20 | + tma = TinyMceArticle.create!(:name => 'test tinymce article', :body => '---', :profile => ze) | |
21 | + assert_includes TinyMceArticle.find_by_contents('article'), tma | |
22 | + assert_includes Article.find_by_contents('article'), tma | |
23 | + end | |
24 | + | |
18 | 25 | end | ... | ... |