Commit 9b733e186fd8205ec1a5afc1ce933c8d877b60d7
1 parent
85198748
Exists in
master
and in
29 other branches
Adapt acts_as_searcheable to Solr
Change acts_as_searcheable to always index schema_path. If multitenancy if off or the database isn't PostgreSQL, then schema_path method returns an empty string and is not used at find_by_contents. Change find_by_contents adding options separating options from paginate, solr and rails's find. With Solr search capabilities, combined search (solr + rails find) won't be necessary in the future. Also change find_by_contents to return a hash where there are the facets found and also the results. Related tests pass with this change
Showing
19 changed files
with
124 additions
and
109 deletions
Show diff stats
app/controllers/my_profile/profile_members_controller.rb
... | ... | @@ -126,11 +126,11 @@ class ProfileMembersController < MyProfileController |
126 | 126 | if !params[:query] || params[:query].length <= 2 |
127 | 127 | @users_found = [] |
128 | 128 | elsif params[:scope] == 'all_users' |
129 | - @users_found = Person.find_by_contents(params[:query] + '*').select {|user| !profile.members.include?(user)} | |
129 | + @users_found = Person.find_by_contents(params[:query] + '*')[:results].select {|user| !profile.members.include?(user)} | |
130 | 130 | @button_alt = _('Add member') |
131 | 131 | @add_action = {:action => 'add_member'} |
132 | 132 | elsif params[:scope] == 'new_admins' |
133 | - @users_found = Person.find_by_contents(params[:query] + '*').select {|user| profile.members.include?(user) && !profile.admins.include?(user)} | |
133 | + @users_found = Person.find_by_contents(params[:query] + '*')[:results].select {|user| profile.members.include?(user) && !profile.admins.include?(user)} | |
134 | 134 | @button_alt = _('Add member') |
135 | 135 | @add_action = {:action => 'add_admin'} |
136 | 136 | end | ... | ... |
app/controllers/public/browse_controller.rb
... | ... | @@ -19,7 +19,7 @@ class BrowseController < PublicController |
19 | 19 | @results = @environment.people.visible.send(@filter) |
20 | 20 | |
21 | 21 | if !params[:query].blank? |
22 | - @results = @results.find_by_contents(params[:query]) | |
22 | + @results = @results.find_by_contents(params[:query])[:results] | |
23 | 23 | end |
24 | 24 | @results = @results.compact.paginate(:per_page => per_page, :page => params[:page]) |
25 | 25 | end |
... | ... | @@ -31,7 +31,7 @@ class BrowseController < PublicController |
31 | 31 | @results = @environment.communities.visible.send(@filter) |
32 | 32 | |
33 | 33 | if !params[:query].blank? |
34 | - @results = @results.find_by_contents(params[:query]) | |
34 | + @results = @results.find_by_contents(params[:query])[:results] | |
35 | 35 | end |
36 | 36 | @results = @results.compact.paginate(:per_page => per_page, :page => params[:page]) |
37 | 37 | end | ... | ... |
app/models/article.rb
app/models/category_finder.rb
... | ... | @@ -30,8 +30,8 @@ class CategoryFinder |
30 | 30 | if query.blank? |
31 | 31 | asset_class(asset).send(finder_method, :all, options_for_find(asset_class(asset), {:order => "#{asset_table(asset)}.name"}.merge(options), date_range)) |
32 | 32 | else |
33 | - ferret_options = {:page => options.delete(:page), :per_page => options.delete(:per_page)} | |
34 | - asset_class(asset).find_by_contents(query, ferret_options, options_for_find(asset_class(asset), options, date_range)) | |
33 | + pg_options = {:page => options.delete(:page), :per_page => options.delete(:per_page)} | |
34 | + asset_class(asset).find_by_contents(query, pg_options, {}, options_for_find(asset_class(asset), options, date_range))[:results] | |
35 | 35 | end |
36 | 36 | end |
37 | 37 | ... | ... |
app/models/enterprise.rb
app/models/environment_finder.rb
... | ... | @@ -48,14 +48,14 @@ class EnvironmentFinder |
48 | 48 | end |
49 | 49 | end |
50 | 50 | else |
51 | - ferret_options = {:page => options.delete(:page), :per_page => options.delete(:per_page)} | |
51 | + pg_options = {:page => options.delete(:page), :per_page => options.delete(:per_page)} | |
52 | 52 | if product_category && asset == :products |
53 | 53 | # SECURITY no risk of SQL injection, since product_category_ids comes from trusted source |
54 | - @environment.send(asset).find_by_contents(query, ferret_options, options.merge({:include => 'product_categorizations', :conditions => 'product_categorizations.category_id = (%s)' % product_category.id })) | |
54 | + @environment.send(asset).find_by_contents(query, pg_options, {}, options.merge({:include => 'product_categorizations', :conditions => 'product_categorizations.category_id = (%s)' % product_category.id }))[:results] | |
55 | 55 | elsif product_category && asset == :enterprises |
56 | - @environment.send(asset).find_by_contents(query, ferret_options, options.merge(:joins => 'inner join product_categorizations on (product_categorizations.product_id = products.id)', :include => 'products', :conditions => "product_categorizations.category_id = (#{product_category.id})")) | |
56 | + @environment.send(asset).find_by_contents(query, pg_options, {}, options.merge(:joins => 'inner join product_categorizations on (product_categorizations.product_id = products.id)', :include => 'products', :conditions => "product_categorizations.category_id = (#{product_category.id})"))[:results] | |
57 | 57 | else |
58 | - @environment.send(asset).find_by_contents(query, ferret_options, options) | |
58 | + @environment.send(asset).find_by_contents(query, pg_options, {}, options)[:results] | |
59 | 59 | end |
60 | 60 | end |
61 | 61 | end | ... | ... |
app/models/region.rb
... | ... | @@ -5,10 +5,9 @@ class Region < Category |
5 | 5 | require_dependency 'enterprise' # enterprises can also be validators |
6 | 6 | |
7 | 7 | # searches for organizations that could become validators for this region. |
8 | - # <tt>search</tt> is passed as is to ferret's find_by_contents on Organizatio | |
9 | - # find_by_contents on Organization class. | |
8 | + # <tt>search</tt> is passed as is to find_by_contents on Organization. | |
10 | 9 | def search_possible_validators(search) |
11 | - Organization.find_by_contents(search).reject {|item| self.validator_ids.include?(item.id) } | |
10 | + Organization.find_by_contents(search)[:results].reject {|item| self.validator_ids.include?(item.id) } | |
12 | 11 | end |
13 | 12 | |
14 | 13 | def has_validator? | ... | ... |
lib/acts_as_searchable.rb
... | ... | @@ -2,56 +2,59 @@ module ActsAsSearchable |
2 | 2 | |
3 | 3 | module ClassMethods |
4 | 4 | def acts_as_searchable(options = {}) |
5 | - if Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql? | |
6 | - options[:additional_fields] ||= {} | |
7 | - options[:additional_fields] = Hash[*options[:additional_fields].collect{ |v| [v, {}] }.flatten] if options[:additional_fields].is_a?(Array) | |
8 | - options[:additional_fields].merge!(:schema_name => { :index => :untokenized }) | |
5 | + if (!options[:fields]) | |
6 | + options[:additional_fields] |= [{:schema_name => :string}] | |
7 | + else | |
8 | + options[:fields] << {:schema_name => :string} | |
9 | 9 | end |
10 | - acts_as_ferret({ :remote => true }.merge(options)) | |
10 | + acts_as_solr options | |
11 | 11 | extend FindByContents |
12 | 12 | send :include, InstanceMethods |
13 | 13 | end |
14 | 14 | |
15 | 15 | module InstanceMethods |
16 | 16 | def schema_name |
17 | - ActiveRecord::Base.connection.schema_search_path | |
17 | + (Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql?) ? ActiveRecord::Base.connection.schema_search_path : '' | |
18 | 18 | end |
19 | 19 | end |
20 | 20 | |
21 | 21 | module FindByContents |
22 | 22 | |
23 | 23 | def schema_name |
24 | - ActiveRecord::Base.connection.schema_search_path | |
24 | + (Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql?) ? ActiveRecord::Base.connection.schema_search_path : '' | |
25 | 25 | end |
26 | 26 | |
27 | - def find_by_contents(query, ferret_options = {}, db_options = {}) | |
28 | - pg_options = {} | |
29 | - if ferret_options[:page] | |
30 | - pg_options[:page] = ferret_options.delete(:page) | |
31 | - end | |
32 | - if ferret_options[:per_page] | |
33 | - pg_options[:per_page] = ferret_options.delete(:per_page) | |
34 | - end | |
35 | - | |
36 | - ferret_options[:limit] = :all | |
37 | - | |
38 | - ferret_query = (Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql?) ? "+schema_name:\"#{schema_name}\" AND #{query}" : query | |
39 | - # FIXME this is a HORRIBLE HACK | |
40 | - ids = find_ids_with_ferret(ferret_query, ferret_options)[1][0..8000].map{|r|r[:id].to_i} | |
41 | - | |
42 | - if ids.empty? | |
43 | - ids << -1 | |
44 | - end | |
27 | + def find_by_contents(query, pg_options = {}, options = {}, db_options = {}) | |
28 | + pg_options[:page] ||= 1 | |
29 | + options[:limit] = 1000000; | |
30 | + options[:scores] = true; | |
45 | 31 | |
46 | - if db_options[:conditions] | |
47 | - db_options[:conditions] = sanitize_sql_for_conditions(db_options[:conditions]) + " and #{table_name}.id in (#{ids.join(', ')})" | |
32 | + query = !schema_name.empty? ? "+schema_name:\"#{schema_name}\" AND #{query}" : query | |
33 | + solr_result = find_by_solr(query, options) | |
34 | + if solr_result.nil? | |
35 | + results = facets = [] | |
48 | 36 | else |
49 | - db_options[:conditions] = "#{table_name}.id in (#{ids.join(', ')})" | |
37 | + facets = options.include?(:facets) ? solr_result.facets : {} | |
38 | + if db_options.empty? | |
39 | + results = solr_result.results.paginate(pg_options) | |
40 | + else | |
41 | + ids = solr_result.results.map{|r|r[:id].to_i} | |
42 | + if ids.empty? | |
43 | + ids << -1 | |
44 | + end | |
45 | + | |
46 | + if db_options[:conditions] | |
47 | + db_options[:conditions] = sanitize_sql_for_conditions(db_options[:conditions]) + " and #{table_name}.id in (#{ids.join(', ')})" | |
48 | + else | |
49 | + db_options[:conditions] = "#{table_name}.id in (#{ids.join(', ')})" | |
50 | + end | |
51 | + | |
52 | + result = find(:all, db_options) | |
53 | + results = result.paginate(pg_options) | |
54 | + end | |
50 | 55 | end |
51 | 56 | |
52 | - pg_options[:page] ||= 1 | |
53 | - result = find(:all, db_options) | |
54 | - result.paginate(pg_options) | |
57 | + {:results => results, :facets => facets} | |
55 | 58 | end |
56 | 59 | end |
57 | 60 | end | ... | ... |
test/test_helper.rb
... | ... | @@ -47,6 +47,10 @@ class Test::Unit::TestCase |
47 | 47 | include AuthenticatedTestHelper |
48 | 48 | |
49 | 49 | fixtures :environments, :roles |
50 | + | |
51 | + def self.setup | |
52 | + ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*')) | |
53 | + end | |
50 | 54 | |
51 | 55 | def self.all_fixtures |
52 | 56 | Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.yml')).each do |item| |
... | ... | @@ -190,7 +194,6 @@ class Test::Unit::TestCase |
190 | 194 | adapter.any_instance.stubs(:adapter_name).returns('PostgreSQL') |
191 | 195 | adapter.any_instance.stubs(:schema_search_path).returns(schema_name) |
192 | 196 | Noosfero::MultiTenancy.stubs(:on?).returns(true) |
193 | - reload_for_ferret | |
194 | 197 | end |
195 | 198 | |
196 | 199 | def uses_sqlite |
... | ... | @@ -199,20 +202,6 @@ class Test::Unit::TestCase |
199 | 202 | Noosfero::MultiTenancy.stubs(:on?).returns(false) |
200 | 203 | end |
201 | 204 | |
202 | - def reload_for_ferret | |
203 | - ActsAsFerret.send(:remove_const, :DEFAULT_FIELD_OPTIONS) | |
204 | - load File.join(RAILS_ROOT, 'lib', 'acts_as_searchable.rb') | |
205 | - load File.join(RAILS_ROOT, 'vendor', 'plugins', 'acts_as_ferret', 'lib', 'acts_as_ferret.rb') | |
206 | - [Article, Profile, Product].each do |clazz| | |
207 | - inst_meth = clazz.instance_methods.reject{ |m| m =~ /_to_ferret$/ } | |
208 | - clazz.stubs(:instance_methods).returns(inst_meth) | |
209 | - end | |
210 | - #FIXME Is there a way to avoid this replication from model code? | |
211 | - Article.acts_as_searchable :additional_fields => [ :comment_data ] | |
212 | - Profile.acts_as_searchable :additional_fields => [ :extra_data_for_index ] | |
213 | - Product.acts_as_searchable :fields => [ :name, :description, :category_full_name ] | |
214 | - end | |
215 | - | |
216 | 205 | end |
217 | 206 | |
218 | 207 | module NoosferoTestHelper | ... | ... |
test/unit/article_test.rb
... | ... | @@ -5,6 +5,7 @@ class ArticleTest < Test::Unit::TestCase |
5 | 5 | fixtures :environments |
6 | 6 | |
7 | 7 | def setup |
8 | + Test::Unit::TestCase::setup | |
8 | 9 | @profile = create_user('testing').person |
9 | 10 | end |
10 | 11 | attr_reader :profile |
... | ... | @@ -356,7 +357,7 @@ class ArticleTest < Test::Unit::TestCase |
356 | 357 | |
357 | 358 | should 'reindex when comments are changed' do |
358 | 359 | a = Article.new |
359 | - a.expects(:ferret_update) | |
360 | + a.expects(:solr_save) | |
360 | 361 | a.comments_updated |
361 | 362 | end |
362 | 363 | |
... | ... | @@ -365,7 +366,7 @@ class ArticleTest < Test::Unit::TestCase |
365 | 366 | art = owner.articles.build(:name => 'ytest'); art.save! |
366 | 367 | c1 = art.comments.build(:title => 'a nice comment', :body => 'anything', :author => owner); c1.save! |
367 | 368 | |
368 | - assert_includes Article.find_by_contents('nice'), art | |
369 | + assert_includes Article.find_by_contents('nice')[:results], art | |
369 | 370 | end |
370 | 371 | |
371 | 372 | should 'index comments body together with article' do |
... | ... | @@ -373,7 +374,7 @@ class ArticleTest < Test::Unit::TestCase |
373 | 374 | art = owner.articles.build(:name => 'ytest'); art.save! |
374 | 375 | c1 = art.comments.build(:title => 'test comment', :body => 'anything', :author => owner); c1.save! |
375 | 376 | |
376 | - assert_includes Article.find_by_contents('anything'), art | |
377 | + assert_includes Article.find_by_contents('anything')[:results], art | |
377 | 378 | end |
378 | 379 | |
379 | 380 | should 'cache children count' do |
... | ... | @@ -1506,24 +1507,24 @@ class ArticleTest < Test::Unit::TestCase |
1506 | 1507 | should 'index by schema name when database is postgresql' do |
1507 | 1508 | uses_postgresql 'schema_one' |
1508 | 1509 | art1 = Article.create!(:name => 'some thing', :profile_id => @profile.id) |
1509 | - assert_equal Article.find_by_contents('thing'), [art1] | |
1510 | + assert_equal Article.find_by_contents('thing')[:results], [art1] | |
1510 | 1511 | uses_postgresql 'schema_two' |
1511 | 1512 | art2 = Article.create!(:name => 'another thing', :profile_id => @profile.id) |
1512 | - assert_not_includes Article.find_by_contents('thing'), art1 | |
1513 | - assert_includes Article.find_by_contents('thing'), art2 | |
1513 | + assert_not_includes Article.find_by_contents('thing')[:results], art1 | |
1514 | + assert_includes Article.find_by_contents('thing')[:results], art2 | |
1514 | 1515 | uses_postgresql 'schema_one' |
1515 | - assert_includes Article.find_by_contents('thing'), art1 | |
1516 | - assert_not_includes Article.find_by_contents('thing'), art2 | |
1516 | + assert_includes Article.find_by_contents('thing')[:results], art1 | |
1517 | + assert_not_includes Article.find_by_contents('thing')[:results], art2 | |
1517 | 1518 | uses_sqlite |
1518 | 1519 | end |
1519 | 1520 | |
1520 | 1521 | should 'not index by schema name when database is not postgresql' do |
1521 | 1522 | uses_sqlite |
1522 | 1523 | art1 = Article.create!(:name => 'some thing', :profile_id => @profile.id) |
1523 | - assert_equal Article.find_by_contents('thing'), [art1] | |
1524 | + assert_equal Article.find_by_contents('thing')[:results], [art1] | |
1524 | 1525 | art2 = Article.create!(:name => 'another thing', :profile_id => @profile.id) |
1525 | - assert_includes Article.find_by_contents('thing'), art1 | |
1526 | - assert_includes Article.find_by_contents('thing'), art2 | |
1526 | + assert_includes Article.find_by_contents('thing')[:results], art1 | |
1527 | + assert_includes Article.find_by_contents('thing')[:results], art2 | |
1527 | 1528 | end |
1528 | 1529 | |
1529 | 1530 | should 'get images paths in article body' do | ... | ... |
test/unit/category_finder_test.rb
... | ... | @@ -3,11 +3,12 @@ require File.dirname(__FILE__) + '/../test_helper' |
3 | 3 | class CategoryFinderTest < ActiveSupport::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | + Test::Unit::TestCase::setup | |
6 | 7 | @category = Category.create!(:name => 'my category', :environment => Environment.default) |
7 | 8 | @finder = CategoryFinder.new(@category) |
8 | 9 | @product_category = fast_create(ProductCategory, :name => 'Products') |
9 | 10 | |
10 | - Profile.rebuild_index | |
11 | + Profile.rebuild_solr_index | |
11 | 12 | end |
12 | 13 | |
13 | 14 | should 'search for articles in a specific category' do | ... | ... |
test/unit/enterprise_test.rb
... | ... | @@ -4,6 +4,7 @@ class EnterpriseTest < Test::Unit::TestCase |
4 | 4 | fixtures :profiles, :environments, :users |
5 | 5 | |
6 | 6 | def setup |
7 | + Test::Unit::TestCase::setup | |
7 | 8 | @product_category = fast_create(ProductCategory, :name => 'Products') |
8 | 9 | end |
9 | 10 | |
... | ... | @@ -91,7 +92,7 @@ class EnterpriseTest < Test::Unit::TestCase |
91 | 92 | |
92 | 93 | ent2 = fast_create(Enterprise, :name => 'test2', :identifier => 'test2') |
93 | 94 | |
94 | - result = Enterprise.find_by_contents(prod_cat.name) | |
95 | + result = Enterprise.find_by_contents(prod_cat.name)[:results] | |
95 | 96 | |
96 | 97 | assert_includes result, ent1 |
97 | 98 | assert_not_includes result, ent2 |
... | ... | @@ -105,7 +106,7 @@ class EnterpriseTest < Test::Unit::TestCase |
105 | 106 | |
106 | 107 | ent2 = fast_create(Enterprise, :name => 'test2', :identifier => 'test2') |
107 | 108 | |
108 | - result = Enterprise.find_by_contents(prod_cat.name) | |
109 | + result = Enterprise.find_by_contents(prod_cat.name)[:results] | |
109 | 110 | |
110 | 111 | assert_includes result, ent1 |
111 | 112 | assert_not_includes result, ent2 |
... | ... | @@ -406,6 +407,12 @@ class EnterpriseTest < Test::Unit::TestCase |
406 | 407 | |
407 | 408 | assert_equal product.inputs, enterprise.inputs |
408 | 409 | end |
410 | + | |
411 | + should 'reindex when products are changed' do | |
412 | + a = Enterprise.new | |
413 | + a.expects(:solr_save) | |
414 | + a.product_updated | |
415 | + end | |
409 | 416 | |
410 | 417 | should "the followed_by? be true only to members" do |
411 | 418 | e = fast_create(Enterprise) | ... | ... |
test/unit/environment_finder_test.rb
test/unit/environment_test.rb
... | ... | @@ -3,6 +3,10 @@ require File.dirname(__FILE__) + '/../test_helper' |
3 | 3 | class EnvironmentTest < Test::Unit::TestCase |
4 | 4 | fixtures :environments |
5 | 5 | |
6 | + def setup | |
7 | + Test::Unit::TestCase::setup | |
8 | + end | |
9 | + | |
6 | 10 | def test_exists_default_and_it_is_unique |
7 | 11 | Environment.delete_all |
8 | 12 | vc = Environment.new(:name => 'Test Community') |
... | ... | @@ -444,7 +448,7 @@ class EnvironmentTest < Test::Unit::TestCase |
444 | 448 | should 'find by contents from articles' do |
445 | 449 | environment = fast_create(Environment) |
446 | 450 | assert_nothing_raised do |
447 | - environment.articles.find_by_contents('') | |
451 | + environment.articles.find_by_contents('')[:results] | |
448 | 452 | end |
449 | 453 | end |
450 | 454 | |
... | ... | @@ -561,7 +565,7 @@ class EnvironmentTest < Test::Unit::TestCase |
561 | 565 | Enterprise.create!(:name => 'test ' + n, :identifier => 'test_' + n) |
562 | 566 | end |
563 | 567 | |
564 | - assert_equal 20, env.enterprises.find_by_contents('test').total_entries | |
568 | + assert_equal 20, env.enterprises.find_by_contents('test')[:results].total_entries | |
565 | 569 | end |
566 | 570 | |
567 | 571 | should 'set replace_enterprise_template_when_enable on environment' do | ... | ... |
test/unit/event_test.rb
... | ... | @@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class EventTest < ActiveSupport::TestCase |
4 | 4 | |
5 | + def setup | |
6 | + Test::Unit::TestCase::setup | |
7 | + end | |
8 | + | |
5 | 9 | should 'be an article' do |
6 | 10 | assert_kind_of Article, Event.new |
7 | 11 | end |
... | ... | @@ -59,13 +63,13 @@ class EventTest < ActiveSupport::TestCase |
59 | 63 | should 'be indexed by title' do |
60 | 64 | profile = create_user('testuser').person |
61 | 65 | e = Event.create!(:name => 'my surprisingly nice event', :start_date => Date.new(2008, 06, 06), :profile => profile) |
62 | - assert_includes Event.find_by_contents('surprisingly'), e | |
66 | + assert_includes Event.find_by_contents('surprisingly')[:results], e | |
63 | 67 | end |
64 | 68 | |
65 | 69 | should 'be indexed by body' do |
66 | 70 | profile = create_user('testuser').person |
67 | 71 | e = Event.create!(:name => 'bli', :start_date => Date.new(2008, 06, 06), :profile => profile, :body => 'my surprisingly long description about my freaking nice event') |
68 | - assert_includes Event.find_by_contents('surprisingly'), e | |
72 | + assert_includes Event.find_by_contents('surprisingly')[:results], e | |
69 | 73 | end |
70 | 74 | |
71 | 75 | should 'use its own icon' do | ... | ... |
test/unit/product_test.rb
... | ... | @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' |
3 | 3 | class ProductTest < Test::Unit::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | + Test::Unit::TestCase::setup | |
6 | 7 | @product_category = fast_create(ProductCategory, :name => 'Products') |
7 | 8 | end |
8 | 9 | |
... | ... | @@ -92,7 +93,7 @@ class ProductTest < Test::Unit::TestCase |
92 | 93 | p.stubs(:category_full_name).returns('interesting category') |
93 | 94 | p.save! |
94 | 95 | |
95 | - assert_includes Product.find_by_contents('interesting'), p | |
96 | + assert_includes Product.find_by_contents('interesting')[:results], p | |
96 | 97 | end |
97 | 98 | |
98 | 99 | should 'have same lat and lng of its enterprise' do |
... | ... | @@ -355,24 +356,24 @@ class ProductTest < Test::Unit::TestCase |
355 | 356 | should 'index by schema name when database is postgresql' do |
356 | 357 | uses_postgresql 'schema_one' |
357 | 358 | p1 = Product.create!(:name => 'some thing', :product_category => @product_category) |
358 | - assert_equal Product.find_by_contents('thing'), [p1] | |
359 | + assert_equal Product.find_by_contents('thing')[:results], [p1] | |
359 | 360 | uses_postgresql 'schema_two' |
360 | 361 | p2 = Product.create!(:name => 'another thing', :product_category => @product_category) |
361 | - assert_not_includes Product.find_by_contents('thing'), p1 | |
362 | - assert_includes Product.find_by_contents('thing'), p2 | |
362 | + assert_not_includes Product.find_by_contents('thing')[:results], p1 | |
363 | + assert_includes Product.find_by_contents('thing')[:results], p2 | |
363 | 364 | uses_postgresql 'schema_one' |
364 | - assert_includes Product.find_by_contents('thing'), p1 | |
365 | - assert_not_includes Product.find_by_contents('thing'), p2 | |
365 | + assert_includes Product.find_by_contents('thing')[:results], p1 | |
366 | + assert_not_includes Product.find_by_contents('thing')[:results], p2 | |
366 | 367 | uses_sqlite |
367 | 368 | end |
368 | 369 | |
369 | 370 | should 'not index by schema name when database is not postgresql' do |
370 | 371 | uses_sqlite |
371 | 372 | p1 = Product.create!(:name => 'some thing', :product_category => @product_category) |
372 | - assert_equal Product.find_by_contents('thing'), [p1] | |
373 | + assert_equal Product.find_by_contents('thing')[:results], [p1] | |
373 | 374 | p2 = Product.create!(:name => 'another thing', :product_category => @product_category) |
374 | - assert_includes Product.find_by_contents('thing'), p1 | |
375 | - assert_includes Product.find_by_contents('thing'), p2 | |
375 | + assert_includes Product.find_by_contents('thing')[:results], p1 | |
376 | + assert_includes Product.find_by_contents('thing')[:results], p2 | |
376 | 377 | end |
377 | 378 | |
378 | 379 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -3,6 +3,10 @@ require File.dirname(__FILE__) + '/../test_helper' |
3 | 3 | class ProfileTest < Test::Unit::TestCase |
4 | 4 | fixtures :profiles, :environments, :users, :roles, :domains |
5 | 5 | |
6 | + def setup | |
7 | + Test::Unit::TestCase::setup | |
8 | + end | |
9 | + | |
6 | 10 | def test_identifier_validation |
7 | 11 | p = Profile.new |
8 | 12 | p.valid? |
... | ... | @@ -100,8 +104,8 @@ class ProfileTest < Test::Unit::TestCase |
100 | 104 | def test_find_by_contents |
101 | 105 | p = create(Profile, :name => 'wanted') |
102 | 106 | |
103 | - assert Profile.find_by_contents('wanted').include?(p) | |
104 | - assert ! Profile.find_by_contents('not_wanted').include?(p) | |
107 | + assert Profile.find_by_contents('wanted')[:results].include?(p) | |
108 | + assert ! Profile.find_by_contents('not_wanted')[:results].include?(p) | |
105 | 109 | end |
106 | 110 | |
107 | 111 | should 'remove pages when removing profile' do |
... | ... | @@ -192,10 +196,10 @@ class ProfileTest < Test::Unit::TestCase |
192 | 196 | small = create(Profile, :name => 'A small profile for testing') |
193 | 197 | big = create(Profile, :name => 'A big profile for testing') |
194 | 198 | |
195 | - assert Profile.find_by_contents('small').include?(small) | |
196 | - assert Profile.find_by_contents('big').include?(big) | |
199 | + assert Profile.find_by_contents('small')[:results].include?(small) | |
200 | + assert Profile.find_by_contents('big')[:results].include?(big) | |
197 | 201 | |
198 | - both = Profile.find_by_contents('profile testing') | |
202 | + both = Profile.find_by_contents('profile testing')[:results] | |
199 | 203 | assert both.include?(small) |
200 | 204 | assert both.include?(big) |
201 | 205 | end |
... | ... | @@ -517,18 +521,18 @@ class ProfileTest < Test::Unit::TestCase |
517 | 521 | should 'actually index by results of extra_data_for_index' do |
518 | 522 | profile = TestingExtraDataForIndex.create!(:name => 'testprofile', :identifier => 'testprofile') |
519 | 523 | |
520 | - assert_includes TestingExtraDataForIndex.find_by_contents('sample'), profile | |
524 | + assert_includes TestingExtraDataForIndex.find_by_contents('sample')[:results], profile | |
521 | 525 | end |
522 | 526 | |
523 | 527 | should 'index profile identifier for searching' do |
524 | 528 | Profile.destroy_all |
525 | 529 | p = create(Profile, :identifier => 'lalala') |
526 | - assert_includes Profile.find_by_contents('lalala'), p | |
530 | + assert_includes Profile.find_by_contents('lalala')[:results], p | |
527 | 531 | end |
528 | 532 | |
529 | 533 | should 'index profile name for searching' do |
530 | 534 | p = create(Profile, :name => 'Interesting Profile') |
531 | - assert_includes Profile.find_by_contents('interesting'), p | |
535 | + assert_includes Profile.find_by_contents('interesting')[:results], p | |
532 | 536 | end |
533 | 537 | |
534 | 538 | should 'enabled by default on creation' do |
... | ... | @@ -1671,24 +1675,24 @@ class ProfileTest < Test::Unit::TestCase |
1671 | 1675 | should 'index by schema name when database is postgresql' do |
1672 | 1676 | uses_postgresql 'schema_one' |
1673 | 1677 | p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing') |
1674 | - assert_equal Profile.find_by_contents('thing'), [p1] | |
1678 | + assert_equal Profile.find_by_contents('thing')[:results], [p1] | |
1675 | 1679 | uses_postgresql 'schema_two' |
1676 | 1680 | p2 = Profile.create!(:name => 'another thing', :identifier => 'another-thing') |
1677 | - assert_not_includes Profile.find_by_contents('thing'), p1 | |
1678 | - assert_includes Profile.find_by_contents('thing'), p2 | |
1681 | + assert_not_includes Profile.find_by_contents('thing')[:results], p1 | |
1682 | + assert_includes Profile.find_by_contents('thing')[:results], p2 | |
1679 | 1683 | uses_postgresql 'schema_one' |
1680 | - assert_includes Profile.find_by_contents('thing'), p1 | |
1681 | - assert_not_includes Profile.find_by_contents('thing'), p2 | |
1684 | + assert_includes Profile.find_by_contents('thing')[:results], p1 | |
1685 | + assert_not_includes Profile.find_by_contents('thing')[:results], p2 | |
1682 | 1686 | uses_sqlite |
1683 | 1687 | end |
1684 | 1688 | |
1685 | 1689 | should 'not index by schema name when database is not postgresql' do |
1686 | 1690 | uses_sqlite |
1687 | 1691 | p1 = Profile.create!(:name => 'some thing', :identifier => 'some-thing') |
1688 | - assert_equal Profile.find_by_contents('thing'), [p1] | |
1692 | + assert_equal Profile.find_by_contents('thing')[:results], [p1] | |
1689 | 1693 | p2 = Profile.create!(:name => 'another thing', :identifier => 'another-thing') |
1690 | - assert_includes Profile.find_by_contents('thing'), p1 | |
1691 | - assert_includes Profile.find_by_contents('thing'), p2 | |
1694 | + assert_includes Profile.find_by_contents('thing')[:results], p1 | |
1695 | + assert_includes Profile.find_by_contents('thing')[:results], p2 | |
1692 | 1696 | end |
1693 | 1697 | |
1694 | 1698 | should 'know if url is the profile homepage' do | ... | ... |
test/unit/tiny_mce_article_test.rb
... | ... | @@ -3,7 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper' |
3 | 3 | class TinyMceArticleTest < Test::Unit::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | - Article.rebuild_index | |
6 | + Test::Unit::TestCase::setup | |
7 | + Article.rebuild_solr_index | |
7 | 8 | @profile = create_user('zezinho').person |
8 | 9 | end |
9 | 10 | attr_reader :profile |
... | ... | @@ -23,8 +24,8 @@ class TinyMceArticleTest < Test::Unit::TestCase |
23 | 24 | |
24 | 25 | should 'be found when searching for articles by query' do |
25 | 26 | tma = TinyMceArticle.create!(:name => 'test tinymce article', :body => '---', :profile => profile) |
26 | - assert_includes TinyMceArticle.find_by_contents('article'), tma | |
27 | - assert_includes Article.find_by_contents('article'), tma | |
27 | + assert_includes TinyMceArticle.find_by_contents('article')[:results], tma | |
28 | + assert_includes Article.find_by_contents('article')[:results], tma | |
28 | 29 | end |
29 | 30 | |
30 | 31 | should 'not sanitize target attribute' do | ... | ... |
vendor/plugins/acts_as_solr/lib/parser_methods.rb
... | ... | @@ -87,7 +87,7 @@ module ActsAsSolr #:nodoc: |
87 | 87 | |
88 | 88 | def solr_type_condition |
89 | 89 | subclasses.inject("(#{solr_configuration[:type_field]}:#{self.name}") do |condition, subclass| |
90 | - condition << " OR #{solr_configuration[:type_field]}:#{subclass.name}" | |
90 | + condition << (subclass.name.empty? ? "" : " OR #{solr_configuration[:type_field]}:#{subclass.name}") | |
91 | 91 | end << ')' |
92 | 92 | end |
93 | 93 | |
... | ... | @@ -198,4 +198,4 @@ module ActsAsSolr #:nodoc: |
198 | 198 | end |
199 | 199 | |
200 | 200 | end |
201 | -end | |
202 | 201 | \ No newline at end of file |
202 | +end | ... | ... |