Commit b1f54f79c73f175068d48f38c22663d64705fedf
1 parent
9c9311bd
Exists in
master
and in
29 other branches
[pluginize-solr] Moving acts_as_[searchable,faceted] to the plugin
Showing
18 changed files
with
487 additions
and
531 deletions
Show diff stats
app/models/article.rb
@@ -647,80 +647,12 @@ class Article < ActiveRecord::Base | @@ -647,80 +647,12 @@ class Article < ActiveRecord::Base | ||
647 | Forum | 647 | Forum |
648 | Event | 648 | Event |
649 | 649 | ||
650 | - def self.f_type_proc(klass) | ||
651 | - klass.constantize.type_name | ||
652 | - end | ||
653 | - | ||
654 | - def self.f_profile_type_proc(klass) | ||
655 | - klass.constantize.type_name | ||
656 | - end | ||
657 | - | ||
658 | - def f_type | ||
659 | - #join common types | ||
660 | - case self.class.name | ||
661 | - when 'TinyMceArticle', 'TextileArticle' | ||
662 | - TextArticle.name | ||
663 | - else | ||
664 | - self.class.name | ||
665 | - end | ||
666 | - end | ||
667 | - | ||
668 | - def f_profile_type | ||
669 | - self.profile.class.name | ||
670 | - end | ||
671 | - | ||
672 | - def f_published_at | ||
673 | - self.published_at | ||
674 | - end | ||
675 | - | ||
676 | - def f_category | ||
677 | - self.categories.collect(&:name) | ||
678 | - end | ||
679 | - | ||
680 | delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true | 650 | delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true |
681 | def name_sortable # give a different name for solr | 651 | def name_sortable # give a different name for solr |
682 | name | 652 | name |
683 | end | 653 | end |
684 | 654 | ||
685 | - def public | ||
686 | - self.public? | ||
687 | - end | ||
688 | - | ||
689 | - def category_filter | ||
690 | - categories_including_virtual_ids | ||
691 | - end | ||
692 | - | ||
693 | public | 655 | public |
694 | - | ||
695 | - acts_as_faceted :fields => { | ||
696 | - :f_type => {:label => _('Type'), :proc => proc{|klass| f_type_proc(klass)}}, | ||
697 | - :f_published_at => {:type => :date, :label => _('Published date'), :queries => {'[* TO NOW-1YEARS/DAY]' => _("Older than one year"), | ||
698 | - '[NOW-1YEARS TO NOW/DAY]' => _("In the last year"), '[NOW-1MONTHS TO NOW/DAY]' => _("In the last month"), '[NOW-7DAYS TO NOW/DAY]' => _("In the last week"), '[NOW-1DAYS TO NOW/DAY]' => _("In the last day")}, | ||
699 | - :queries_order => ['[NOW-1DAYS TO NOW/DAY]', '[NOW-7DAYS TO NOW/DAY]', '[NOW-1MONTHS TO NOW/DAY]', '[NOW-1YEARS TO NOW/DAY]', '[* TO NOW-1YEARS/DAY]']}, | ||
700 | - :f_profile_type => {:label => _('Profile'), :proc => proc{|klass| f_profile_type_proc(klass)}}, | ||
701 | - :f_category => {:label => _('Categories')}, | ||
702 | - }, :category_query => proc { |c| "category_filter:\"#{c.id}\"" }, | ||
703 | - :order => [:f_type, :f_published_at, :f_profile_type, :f_category] | ||
704 | - | ||
705 | - acts_as_searchable :fields => facets_fields_for_solr + [ | ||
706 | - # searched fields | ||
707 | - {:name => {:type => :text, :boost => 2.0}}, | ||
708 | - {:slug => :text}, {:body => :text}, | ||
709 | - {:abstract => :text}, {:filename => :text}, | ||
710 | - # filtered fields | ||
711 | - {:public => :boolean}, {:environment_id => :integer}, | ||
712 | - {:profile_id => :integer}, :language, | ||
713 | - {:category_filter => :integer}, | ||
714 | - # ordered/query-boosted fields | ||
715 | - {:name_sortable => :string}, :last_changed_by_id, :published_at, :is_image, | ||
716 | - :updated_at, :created_at, | ||
717 | - ], :include => [ | ||
718 | - {:profile => {:fields => [:name, :identifier, :address, :nickname, :region_id, :lat, :lng]}}, | ||
719 | - {:comments => {:fields => [:title, :body, :author_name, :author_email]}}, | ||
720 | - {:categories => {:fields => [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, | ||
721 | - ], :facets => facets_option_for_solr, | ||
722 | - :boost => proc { |a| 10 if a.profile && a.profile.enabled }, | ||
723 | - :if => proc{ |a| ! ['RssFeed'].include?(a.class.name) } | ||
724 | handle_asynchronously :solr_save | 656 | handle_asynchronously :solr_save |
725 | 657 | ||
726 | private | 658 | private |
app/models/category.rb
@@ -95,17 +95,6 @@ class Category < ActiveRecord::Base | @@ -95,17 +95,6 @@ class Category < ActiveRecord::Base | ||
95 | name | 95 | name |
96 | end | 96 | end |
97 | public | 97 | public |
98 | - | ||
99 | - acts_as_searchable :fields => [ | ||
100 | - # searched fields | ||
101 | - {:name => {:type => :text, :boost => 2.0}}, | ||
102 | - {:path => :text}, {:slug => :text}, | ||
103 | - {:abbreviation => :text}, {:acronym => :text}, | ||
104 | - # filtered fields | ||
105 | - :parent_id, | ||
106 | - # ordered/query-boosted fields | ||
107 | - {:name_sortable => :string}, | ||
108 | - ] | ||
109 | handle_asynchronously :solr_save | 98 | handle_asynchronously :solr_save |
110 | 99 | ||
111 | end | 100 | end |
app/models/product.rb
@@ -212,87 +212,20 @@ class Product < ActiveRecord::Base | @@ -212,87 +212,20 @@ class Product < ActiveRecord::Base | ||
212 | end | 212 | end |
213 | 213 | ||
214 | private | 214 | private |
215 | - def f_category | ||
216 | - self.product_category.name | ||
217 | - end | ||
218 | - def f_region | ||
219 | - self.enterprise.region.id if self.enterprise.region | ||
220 | - end | ||
221 | - def self.f_region_proc(id) | ||
222 | - c = Region.find(id) | ||
223 | - s = c.parent | ||
224 | - if c and c.kind_of?(City) and s and s.kind_of?(State) and s.acronym | ||
225 | - [c.name, ', ' + s.acronym] | ||
226 | - else | ||
227 | - c.name | ||
228 | - end | ||
229 | - end | ||
230 | - def self.f_qualifier_proc(ids) | ||
231 | - array = ids.split | ||
232 | - qualifier = Qualifier.find_by_id array[0] | ||
233 | - certifier = Certifier.find_by_id array[1] | ||
234 | - certifier ? [qualifier.name, _(' cert. ') + certifier.name] : qualifier.name | ||
235 | - end | ||
236 | - def f_qualifier | ||
237 | - product_qualifiers.map do |pq| | ||
238 | - "#{pq.qualifier_id} #{pq.certifier_id}" | ||
239 | - end | ||
240 | - end | ||
241 | 215 | ||
242 | - alias_method :name_sortable, :name | ||
243 | delegate :enabled, :region, :region_id, :environment, :environment_id, :to => :enterprise | 216 | delegate :enabled, :region, :region_id, :environment, :environment_id, :to => :enterprise |
217 | + | ||
218 | + alias_method :name_sortable, :name | ||
244 | def name_sortable # give a different name for solr | 219 | def name_sortable # give a different name for solr |
245 | name | 220 | name |
246 | end | 221 | end |
247 | - def public | ||
248 | - self.public? | ||
249 | - end | 222 | + |
250 | def price_sortable | 223 | def price_sortable |
251 | (price.nil? or price.zero?) ? nil : price | 224 | (price.nil? or price.zero?) ? nil : price |
252 | end | 225 | end |
253 | - def category_filter | ||
254 | - enterprise.categories_including_virtual_ids << product_category_id | ||
255 | - end | 226 | + |
256 | public | 227 | public |
257 | 228 | ||
258 | - acts_as_faceted :fields => { | ||
259 | - :f_category => {:label => _('Related products')}, | ||
260 | - :f_region => {:label => _('City'), :proc => proc { |id| f_region_proc(id) }}, | ||
261 | - :f_qualifier => {:label => _('Qualifiers'), :proc => proc { |id| f_qualifier_proc(id) }}, | ||
262 | - }, :category_query => proc { |c| "category_filter:#{c.id}" }, | ||
263 | - :order => [:f_category, :f_region, :f_qualifier] | ||
264 | - | ||
265 | - Boosts = [ | ||
266 | - [:image, 0.55, proc{ |p| p.image ? 1 : 0}], | ||
267 | - [:qualifiers, 0.45, proc{ |p| p.product_qualifiers.count > 0 ? 1 : 0}], | ||
268 | - [:open_price, 0.45, proc{ |p| p.price_described? ? 1 : 0}], | ||
269 | - [:solidarity, 0.45, proc{ |p| p.percentage_from_solidarity_economy[0].to_f/100 }], | ||
270 | - [:available, 0.35, proc{ |p| p.available ? 1 : 0}], | ||
271 | - [:price, 0.35, proc{ |p| (!p.price.nil? and p.price > 0) ? 1 : 0}], | ||
272 | - [:new_product, 0.35, proc{ |p| (p.updated_at.to_i - p.created_at.to_i) < 24*3600 ? 1 : 0}], | ||
273 | - [:description, 0.3, proc{ |p| !p.description.blank? ? 1 : 0}], | ||
274 | - [:enabled, 0.2, proc{ |p| p.enterprise.enabled ? 1 : 0}], | ||
275 | - ] | ||
276 | - | ||
277 | - acts_as_searchable :fields => facets_fields_for_solr + [ | ||
278 | - # searched fields | ||
279 | - {:name => {:type => :text, :boost => 2.0}}, | ||
280 | - {:description => :text}, {:category_full_name => :text}, | ||
281 | - # filtered fields | ||
282 | - {:public => :boolean}, {:environment_id => :integer}, | ||
283 | - {:enabled => :boolean}, {:category_filter => :integer}, | ||
284 | - # ordered/query-boosted fields | ||
285 | - {:price_sortable => :decimal}, {:name_sortable => :string}, | ||
286 | - {:lat => :float}, {:lng => :float}, | ||
287 | - :updated_at, :created_at, | ||
288 | - ], :include => [ | ||
289 | - {:product_category => {:fields => [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, | ||
290 | - {:region => {:fields => [:name, :path, :slug, :lat, :lng]}}, | ||
291 | - {:enterprise => {:fields => [:name, :identifier, :address, :nickname, :lat, :lng]}}, | ||
292 | - {:qualifiers => {:fields => [:name]}}, | ||
293 | - {:certifiers => {:fields => [:name]}}, | ||
294 | - ], :facets => facets_option_for_solr, | ||
295 | - :boost => proc{ |p| boost = 1; Boosts.each{ |b| boost = boost * (1 - ((1 - b[2].call(p)) * b[1])) }; boost} | ||
296 | handle_asynchronously :solr_save | 229 | handle_asynchronously :solr_save |
297 | 230 | ||
298 | end | 231 | end |
app/models/profile.rb
@@ -887,82 +887,12 @@ private :generate_url, :url_options | @@ -887,82 +887,12 @@ private :generate_url, :url_options | ||
887 | end | 887 | end |
888 | 888 | ||
889 | private | 889 | private |
890 | - def self.f_categories_label_proc(environment) | ||
891 | - ids = environment.top_level_category_as_facet_ids | ||
892 | - r = Category.find(ids) | ||
893 | - map = {} | ||
894 | - ids.map{ |id| map[id.to_s] = r.detect{|c| c.id == id}.name } | ||
895 | - map | ||
896 | - end | ||
897 | - def self.f_categories_proc(facet, id) | ||
898 | - id = id.to_i | ||
899 | - return if id.zero? | ||
900 | - c = Category.find(id) | ||
901 | - c.name if c.top_ancestor.id == facet[:label_id].to_i or facet[:label_id] == 0 | ||
902 | - end | ||
903 | - def f_categories | ||
904 | - category_ids - [region_id] | ||
905 | - end | ||
906 | - | ||
907 | - def f_region | ||
908 | - self.region_id | ||
909 | - end | ||
910 | - def self.f_region_proc(id) | ||
911 | - c = Region.find(id) | ||
912 | - s = c.parent | ||
913 | - if c and c.kind_of?(City) and s and s.kind_of?(State) and s.acronym | ||
914 | - [c.name, ', ' + s.acronym] | ||
915 | - else | ||
916 | - c.name | ||
917 | - end | ||
918 | - end | ||
919 | - | ||
920 | - def self.f_enabled_proc(enabled) | ||
921 | - enabled = enabled == "true" ? true : false | ||
922 | - enabled ? s_('facets|Enabled') : s_('facets|Not enabled') | ||
923 | - end | ||
924 | - def f_enabled | ||
925 | - self.enabled | ||
926 | - end | ||
927 | 890 | ||
928 | def name_sortable # give a different name for solr | 891 | def name_sortable # give a different name for solr |
929 | name | 892 | name |
930 | end | 893 | end |
931 | - def public | ||
932 | - self.public? | ||
933 | - end | ||
934 | - def category_filter | ||
935 | - categories_including_virtual_ids | ||
936 | - end | ||
937 | - public | ||
938 | 894 | ||
939 | - acts_as_faceted :fields => { | ||
940 | - :f_enabled => {:label => _('Situation'), :type_if => proc { |klass| klass.kind_of?(Enterprise) }, | ||
941 | - :proc => proc { |id| f_enabled_proc(id) }}, | ||
942 | - :f_region => {:label => _('City'), :proc => proc { |id| f_region_proc(id) }}, | ||
943 | - :f_categories => {:multi => true, :proc => proc {|facet, id| f_categories_proc(facet, id)}, | ||
944 | - :label => proc { |env| f_categories_label_proc(env) }, :label_abbrev => proc{ |env| f_categories_label_abbrev_proc(env) }}, | ||
945 | - }, :category_query => proc { |c| "category_filter:#{c.id}" }, | ||
946 | - :order => [:f_region, :f_categories, :f_enabled] | ||
947 | - | ||
948 | - acts_as_searchable :fields => facets_fields_for_solr + [:extra_data_for_index, | ||
949 | - # searched fields | ||
950 | - {:name => {:type => :text, :boost => 2.0}}, | ||
951 | - {:identifier => :text}, {:nickname => :text}, | ||
952 | - # filtered fields | ||
953 | - {:public => :boolean}, {:environment_id => :integer}, | ||
954 | - {:category_filter => :integer}, | ||
955 | - # ordered/query-boosted fields | ||
956 | - {:name_sortable => :string}, {:user_id => :integer}, | ||
957 | - :enabled, :active, :validated, :public_profile, | ||
958 | - {:lat => :float}, {:lng => :float}, | ||
959 | - :updated_at, :created_at, | ||
960 | - ], | ||
961 | - :include => [ | ||
962 | - {:region => {:fields => [:name, :path, :slug, :lat, :lng]}}, | ||
963 | - {:categories => {:fields => [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, | ||
964 | - ], :facets => facets_option_for_solr, | ||
965 | - :boost => proc{ |p| 10 if p.enabled } | 895 | + public |
966 | 896 | ||
967 | handle_asynchronously :solr_save | 897 | handle_asynchronously :solr_save |
968 | 898 |
config/initializers/dependencies.rb
1 | # locally-developed modules | 1 | # locally-developed modules |
2 | -require 'acts_as_faceted' | ||
3 | require 'acts_as_filesystem' | 2 | require 'acts_as_filesystem' |
4 | require 'acts_as_having_settings' | 3 | require 'acts_as_having_settings' |
5 | -require 'acts_as_searchable' | ||
6 | require 'acts_as_having_boxes' | 4 | require 'acts_as_having_boxes' |
7 | require 'acts_as_having_image' | 5 | require 'acts_as_having_image' |
8 | require 'acts_as_having_posts' | 6 | require 'acts_as_having_posts' |
plugins/solr/lib/ext/article.rb
@@ -4,4 +4,74 @@ class Article | @@ -4,4 +4,74 @@ class Article | ||
4 | def solr_plugin_comments_updated | 4 | def solr_plugin_comments_updated |
5 | solr_save | 5 | solr_save |
6 | end | 6 | end |
7 | + | ||
8 | + acts_as_faceted :fields => { | ||
9 | + :solr_plugin_f_type => {:label => _('Type'), :proc => proc{|klass| solr_plugin_f_type_proc(klass)}}, | ||
10 | + :solr_plugin_f_published_at => {:type => :date, :label => _('Published date'), :queries => {'[* TO NOW-1YEARS/DAY]' => _("Older than one year"), | ||
11 | + '[NOW-1YEARS TO NOW/DAY]' => _("In the last year"), '[NOW-1MONTHS TO NOW/DAY]' => _("In the last month"), '[NOW-7DAYS TO NOW/DAY]' => _("In the last week"), '[NOW-1DAYS TO NOW/DAY]' => _("In the last day")}, | ||
12 | + :queries_order => ['[NOW-1DAYS TO NOW/DAY]', '[NOW-7DAYS TO NOW/DAY]', '[NOW-1MONTHS TO NOW/DAY]', '[NOW-1YEARS TO NOW/DAY]', '[* TO NOW-1YEARS/DAY]']}, | ||
13 | + :solr_plugin_f_profile_type => {:label => _('Profile'), :proc => proc{|klass| solr_plugin_f_profile_type_proc(klass)}}, | ||
14 | + :solr_plugin_f_category => {:label => _('Categories')}, | ||
15 | + }, :category_query => proc { |c| "solr_plugin_category_filter:\"#{c.id}\"" }, | ||
16 | + :order => [:solr_plugin_f_type, :solr_plugin_f_published_at, :solr_plugin_f_profile_type, :solr_plugin_f_category] | ||
17 | + | ||
18 | + acts_as_searchable :fields => facets_fields_for_solr + [ | ||
19 | + # searched fields | ||
20 | + {:name => {:type => :text, :boost => 2.0}}, | ||
21 | + {:slug => :text}, {:body => :text}, | ||
22 | + {:abstract => :text}, {:filename => :text}, | ||
23 | + # filtered fields | ||
24 | + {:solr_plugin_public => :boolean}, {:environment_id => :integer}, | ||
25 | + {:profile_id => :integer}, :language, | ||
26 | + {:solr_plugin_category_filter => :integer}, | ||
27 | + # ordered/query-boosted fields | ||
28 | + {:name_sortable => :string}, :last_changed_by_id, :published_at, :is_image, | ||
29 | + :updated_at, :created_at, | ||
30 | + ], :include => [ | ||
31 | + {:profile => {:fields => [:name, :identifier, :address, :nickname, :region_id, :lat, :lng]}}, | ||
32 | + {:comments => {:fields => [:title, :body, :author_name, :author_email]}}, | ||
33 | + {:categories => {:fields => [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, | ||
34 | + ], :facets => facets_option_for_solr, | ||
35 | + :boost => proc { |a| 10 if a.profile && a.profile.enabled }, | ||
36 | + :if => proc{ |a| ! ['RssFeed'].include?(a.class.name) } | ||
37 | + | ||
38 | + private | ||
39 | + | ||
40 | + def self.solr_plugin_f_type_proc(klass) | ||
41 | + klass.constantize.type_name | ||
42 | + end | ||
43 | + | ||
44 | + def self.solr_plugin_f_profile_type_proc(klass) | ||
45 | + klass.constantize.type_name | ||
46 | + end | ||
47 | + | ||
48 | + def solr_plugin_f_type | ||
49 | + #join common types | ||
50 | + case self.class.name | ||
51 | + when 'TinyMceArticle', 'TextileArticle' | ||
52 | + TextArticle.name | ||
53 | + else | ||
54 | + self.class.name | ||
55 | + end | ||
56 | + end | ||
57 | + | ||
58 | + def solr_plugin_f_profile_type | ||
59 | + self.profile.class.name | ||
60 | + end | ||
61 | + | ||
62 | + def solr_plugin_f_published_at | ||
63 | + self.published_at | ||
64 | + end | ||
65 | + | ||
66 | + def solr_plugin_f_category | ||
67 | + self.categories.collect(&:name) | ||
68 | + end | ||
69 | + | ||
70 | + def solr_plugin_public | ||
71 | + self.public? | ||
72 | + end | ||
73 | + | ||
74 | + def solr_plugin_category_filter | ||
75 | + categories_including_virtual_ids | ||
76 | + end | ||
7 | end | 77 | end |
plugins/solr/lib/ext/category.rb
@@ -2,4 +2,15 @@ require_dependency 'category' | @@ -2,4 +2,15 @@ require_dependency 'category' | ||
2 | 2 | ||
3 | class Category | 3 | class Category |
4 | after_save_reindex [:articles, :profiles], :with => :delayed_job | 4 | after_save_reindex [:articles, :profiles], :with => :delayed_job |
5 | + | ||
6 | + acts_as_searchable :fields => [ | ||
7 | + # searched fields | ||
8 | + {:name => {:type => :text, :boost => 2.0}}, | ||
9 | + {:path => :text}, {:slug => :text}, | ||
10 | + {:abbreviation => :text}, {:acronym => :text}, | ||
11 | + # filtered fields | ||
12 | + :parent_id, | ||
13 | + # ordered/query-boosted fields | ||
14 | + {:name_sortable => :string}, | ||
15 | + ] | ||
5 | end | 16 | end |
plugins/solr/lib/ext/product.rb
@@ -2,4 +2,84 @@ require_dependency 'product' | @@ -2,4 +2,84 @@ require_dependency 'product' | ||
2 | 2 | ||
3 | class Product | 3 | class Product |
4 | after_save_reindex [:enterprise], :with => :delayed_job | 4 | after_save_reindex [:enterprise], :with => :delayed_job |
5 | + | ||
6 | + acts_as_faceted :fields => { | ||
7 | + :solr_plugin_f_category => {:label => _('Related products')}, | ||
8 | + :solr_plugin_f_region => {:label => _('City'), :proc => proc { |id| solr_plugin_f_region_proc(id) }}, | ||
9 | + :solr_plugin_f_qualifier => {:label => _('Qualifiers'), :proc => proc { |id| solr_plugin_f_qualifier_proc(id) }}, | ||
10 | + }, :category_query => proc { |c| "solr_plugin_category_filter:#{c.id}" }, | ||
11 | + :order => [:solr_plugin_f_category, :solr_plugin_f_region, :solr_plugin_f_qualifier] | ||
12 | + | ||
13 | + SolrPlugin::Boosts = [ | ||
14 | + [:image, 0.55, proc{ |p| p.image ? 1 : 0}], | ||
15 | + [:qualifiers, 0.45, proc{ |p| p.product_qualifiers.count > 0 ? 1 : 0}], | ||
16 | + [:open_price, 0.45, proc{ |p| p.price_described? ? 1 : 0}], | ||
17 | + [:solidarity, 0.45, proc{ |p| p.percentage_from_solidarity_economy[0].to_f/100 }], | ||
18 | + [:available, 0.35, proc{ |p| p.available ? 1 : 0}], | ||
19 | + [:price, 0.35, proc{ |p| (!p.price.nil? and p.price > 0) ? 1 : 0}], | ||
20 | + [:new_product, 0.35, proc{ |p| (p.updated_at.to_i - p.created_at.to_i) < 24*3600 ? 1 : 0}], | ||
21 | + [:description, 0.3, proc{ |p| !p.description.blank? ? 1 : 0}], | ||
22 | + [:enabled, 0.2, proc{ |p| p.enterprise.enabled ? 1 : 0}], | ||
23 | + ] | ||
24 | + | ||
25 | + acts_as_searchable :fields => facets_fields_for_solr + [ | ||
26 | + # searched fields | ||
27 | + {:name => {:type => :text, :boost => 2.0}}, | ||
28 | + {:description => :text}, {:category_full_name => :text}, | ||
29 | + # filtered fields | ||
30 | + {:solr_plugin_public => :boolean}, {:environment_id => :integer}, | ||
31 | + {:enabled => :boolean}, {:solr_plugin_category_filter => :integer}, | ||
32 | + # ordered/query-boosted fields | ||
33 | + {:price_sortable => :decimal}, {:name_sortable => :string}, | ||
34 | + {:lat => :float}, {:lng => :float}, | ||
35 | + :updated_at, :created_at, | ||
36 | + ], :include => [ | ||
37 | + {:product_category => {:fields => [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, | ||
38 | + {:region => {:fields => [:name, :path, :slug, :lat, :lng]}}, | ||
39 | + {:enterprise => {:fields => [:name, :identifier, :address, :nickname, :lat, :lng]}}, | ||
40 | + {:qualifiers => {:fields => [:name]}}, | ||
41 | + {:certifiers => {:fields => [:name]}}, | ||
42 | + ], :facets => facets_option_for_solr, | ||
43 | + :boost => proc{ |p| boost = 1; SolrPlugin::Boosts.each{ |b| boost = boost * (1 - ((1 - b[2].call(p)) * b[1])) }; boost} | ||
44 | + | ||
45 | + private | ||
46 | + | ||
47 | + def solr_plugin_f_category | ||
48 | + self.product_category.name | ||
49 | + end | ||
50 | + | ||
51 | + def solr_plugin_f_region | ||
52 | + self.enterprise.region.id if self.enterprise.region | ||
53 | + end | ||
54 | + | ||
55 | + def self.solr_plugin_f_region_proc(id) | ||
56 | + c = Region.find(id) | ||
57 | + s = c.parent | ||
58 | + if c and c.kind_of?(City) and s and s.kind_of?(State) and s.acronym | ||
59 | + [c.name, ', ' + s.acronym] | ||
60 | + else | ||
61 | + c.name | ||
62 | + end | ||
63 | + end | ||
64 | + | ||
65 | + def self.solr_plugin_f_qualifier_proc(ids) | ||
66 | + array = ids.split | ||
67 | + qualifier = Qualifier.find_by_id array[0] | ||
68 | + certifier = Certifier.find_by_id array[1] | ||
69 | + certifier ? [qualifier.name, _(' cert. ') + certifier.name] : qualifier.name | ||
70 | + end | ||
71 | + | ||
72 | + def solr_plugin_f_qualifier | ||
73 | + product_qualifiers.map do |pq| | ||
74 | + "#{pq.qualifier_id} #{pq.certifier_id}" | ||
75 | + end | ||
76 | + end | ||
77 | + | ||
78 | + def solr_plugin_category_filter | ||
79 | + enterprise.categories_including_virtual_ids << product_category_id | ||
80 | + end | ||
81 | + | ||
82 | + def solr_plugin_public | ||
83 | + self.public? | ||
84 | + end | ||
5 | end | 85 | end |
plugins/solr/lib/ext/profile.rb
@@ -2,4 +2,84 @@ require_dependency 'profile' | @@ -2,4 +2,84 @@ require_dependency 'profile' | ||
2 | 2 | ||
3 | class Profile | 3 | class Profile |
4 | after_save_reindex [:articles], :with => :delayed_job | 4 | after_save_reindex [:articles], :with => :delayed_job |
5 | + | ||
6 | + acts_as_faceted :fields => { | ||
7 | + :solr_plugin_f_enabled => {:label => _('Situation'), :type_if => proc { |klass| klass.kind_of?(Enterprise) }, | ||
8 | + :proc => proc { |id| solr_plugin_f_enabled_proc(id) }}, | ||
9 | + :solr_plugin_f_region => {:label => _('City'), :proc => proc { |id| solr_plugin_f_region_proc(id) }}, | ||
10 | + :solr_plugin_f_categories => {:multi => true, :proc => proc {|facet, id| solr_plugin_f_categories_proc(facet, id)}, | ||
11 | + :label => proc { |env| solr_plugin_f_categories_label_proc(env) }, :label_abbrev => proc{ |env| solr_plugin_f_categories_label_abbrev_proc(env) }}, | ||
12 | + }, :category_query => proc { |c| "solr_plugin_category_filter:#{c.id}" }, | ||
13 | + :order => [:solr_plugin_f_region, :solr_plugin_f_categories, :solr_plugin_f_enabled] | ||
14 | + | ||
15 | + acts_as_searchable :fields => facets_fields_for_solr + [:extra_data_for_index, | ||
16 | + # searched fields | ||
17 | + {:name => {:type => :text, :boost => 2.0}}, | ||
18 | + {:identifier => :text}, {:nickname => :text}, | ||
19 | + # filtered fields | ||
20 | + {:solr_plugin_public => :boolean}, {:environment_id => :integer}, | ||
21 | + {:solr_plugin_category_filter => :integer}, | ||
22 | + # ordered/query-boosted fields | ||
23 | + {:name_sortable => :string}, {:user_id => :integer}, | ||
24 | + :enabled, :active, :validated, :public_profile, | ||
25 | + {:lat => :float}, {:lng => :float}, | ||
26 | + :updated_at, :created_at, | ||
27 | + ], | ||
28 | + :include => [ | ||
29 | + {:region => {:fields => [:name, :path, :slug, :lat, :lng]}}, | ||
30 | + {:categories => {:fields => [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, | ||
31 | + ], :facets => facets_option_for_solr, | ||
32 | + :boost => proc{ |p| 10 if p.enabled } | ||
33 | + | ||
34 | + private | ||
35 | + | ||
36 | + def self.solr_plugin_f_categories_label_proc(environment) | ||
37 | + ids = environment.top_level_category_as_facet_ids | ||
38 | + r = Category.find(ids) | ||
39 | + map = {} | ||
40 | + ids.map{ |id| map[id.to_s] = r.detect{|c| c.id == id}.name } | ||
41 | + map | ||
42 | + end | ||
43 | + | ||
44 | + def self.solr_plugin_f_categories_proc(facet, id) | ||
45 | + id = id.to_i | ||
46 | + return if id.zero? | ||
47 | + c = Category.find(id) | ||
48 | + c.name if c.top_ancestor.id == facet[:label_id].to_i or facet[:label_id] == 0 | ||
49 | + end | ||
50 | + | ||
51 | + def solr_plugin_f_categories | ||
52 | + category_ids - [region_id] | ||
53 | + end | ||
54 | + | ||
55 | + def solr_plugin_f_region | ||
56 | + self.region_id | ||
57 | + end | ||
58 | + | ||
59 | + def self.solr_plugin_f_region_proc(id) | ||
60 | + c = Region.find(id) | ||
61 | + s = c.parent | ||
62 | + if c and c.kind_of?(City) and s and s.kind_of?(State) and s.acronym | ||
63 | + [c.name, ', ' + s.acronym] | ||
64 | + else | ||
65 | + c.name | ||
66 | + end | ||
67 | + end | ||
68 | + | ||
69 | + def self.solr_plugin_f_enabled_proc(enabled) | ||
70 | + enabled = enabled == "true" ? true : false | ||
71 | + enabled ? s_('facets|Enabled') : s_('facets|Not enabled') | ||
72 | + end | ||
73 | + | ||
74 | + def solr_plugin_f_enabled | ||
75 | + self.enabled | ||
76 | + end | ||
77 | + | ||
78 | + def solr_plugin_public | ||
79 | + self.public? | ||
80 | + end | ||
81 | + | ||
82 | + def solr_plugin_category_filter | ||
83 | + categories_including_virtual_ids | ||
84 | + end | ||
5 | end | 85 | end |
plugins/solr/test/unit/category_test.rb
@@ -9,7 +9,7 @@ class CategoryTest < ActiveSupport::TestCase | @@ -9,7 +9,7 @@ class CategoryTest < ActiveSupport::TestCase | ||
9 | attr_accessor :environment | 9 | attr_accessor :environment |
10 | 10 | ||
11 | should 'reindex articles after saving' do | 11 | should 'reindex articles after saving' do |
12 | - cat = Category.create!(:name => 'category 1', :environment_id => Environment.default.id) | 12 | + cat = Category.create!(:name => 'category 1', :environment_id => environment.id) |
13 | art = Article.create!(:name => 'something', :profile_id => fast_create(Person).id) | 13 | art = Article.create!(:name => 'something', :profile_id => fast_create(Person).id) |
14 | art.add_category cat | 14 | art.add_category cat |
15 | cat.reload | 15 | cat.reload |
@@ -18,4 +18,26 @@ class CategoryTest < ActiveSupport::TestCase | @@ -18,4 +18,26 @@ class CategoryTest < ActiveSupport::TestCase | ||
18 | Article.any_instance.expects(:to_solr_doc).returns(solr_doc) | 18 | Article.any_instance.expects(:to_solr_doc).returns(solr_doc) |
19 | cat.save! | 19 | cat.save! |
20 | end | 20 | end |
21 | + | ||
22 | + should 'act as searchable' do | ||
23 | + TestSolr.enable | ||
24 | + parent = fast_create(Category, :name => 'books') | ||
25 | + c = Category.create!(:name => "science fiction", :acronym => "sf", :abbreviation => "sci-fi", | ||
26 | + :environment_id => environment.id, :parent_id => parent.id) | ||
27 | + | ||
28 | + # fields | ||
29 | + assert_includes Category.find_by_contents('fiction')[:results].docs, c | ||
30 | + assert_includes Category.find_by_contents('sf')[:results].docs, c | ||
31 | + assert_includes Category.find_by_contents('sci-fi')[:results].docs, c | ||
32 | + # filters | ||
33 | + assert_includes Category.find_by_contents('science', {}, { | ||
34 | + :filter_queries => ["parent_id:#{parent.id}"]})[:results].docs, c | ||
35 | + end | ||
36 | + | ||
37 | + should 'boost name matches' do | ||
38 | + TestSolr.enable | ||
39 | + c_abbr = Category.create!(:name => "something else", :abbreviation => "science", :environment_id => environment.id) | ||
40 | + c_name = Category.create!(:name => "science fiction", :environment_id => environment.id) | ||
41 | + assert_equal [c_name, c_abbr], Category.find_by_contents("science")[:results].docs | ||
42 | + end | ||
21 | end | 43 | end |
plugins/solr/test/unit/product_test.rb
@@ -4,9 +4,11 @@ class ProductTest < ActiveSupport::TestCase | @@ -4,9 +4,11 @@ class ProductTest < ActiveSupport::TestCase | ||
4 | def setup | 4 | def setup |
5 | @environment = Environment.default | 5 | @environment = Environment.default |
6 | @environment.enable_plugin(SolrPlugin) | 6 | @environment.enable_plugin(SolrPlugin) |
7 | + @product_category = fast_create(ProductCategory, :name => 'Products') | ||
8 | + @profile = fast_create(Enterprise) | ||
7 | end | 9 | end |
8 | 10 | ||
9 | - attr_accessor :environment | 11 | + attr_accessor :environment, :product_category, :profile |
10 | 12 | ||
11 | should 'reindex enterprise after saving' do | 13 | should 'reindex enterprise after saving' do |
12 | ent = fast_create(Enterprise) | 14 | ent = fast_create(Enterprise) |
@@ -15,5 +17,177 @@ class ProductTest < ActiveSupport::TestCase | @@ -15,5 +17,177 @@ class ProductTest < ActiveSupport::TestCase | ||
15 | Product.expects(:solr_batch_add).with([ent]) | 17 | Product.expects(:solr_batch_add).with([ent]) |
16 | prod.save! | 18 | prod.save! |
17 | end | 19 | end |
20 | + | ||
21 | + should 'act as faceted' do | ||
22 | + s = fast_create(State, :acronym => 'XZ') | ||
23 | + c = fast_create(City, :name => 'Tabajara', :parent_id => s.id) | ||
24 | + ent = fast_create(Enterprise, :region_id => c.id) | ||
25 | + cat = fast_create(ProductCategory, :name => 'hardcore') | ||
26 | + p = Product.create!(:name => 'black flag', :enterprise_id => ent.id, :product_category_id => cat.id) | ||
27 | + pq = p.product_qualifiers.create!(:qualifier => fast_create(Qualifier, :name => 'qualifier'), | ||
28 | + :certifier => fast_create(Certifier, :name => 'certifier')) | ||
29 | + assert_equal 'Related products', Product.facet_by_id(:solr_plugin_f_category)[:label] | ||
30 | + assert_equal ['Tabajara', ', XZ'], Product.facet_by_id(:solr_plugin_f_region)[:proc].call(p.send(:solr_plugin_f_region)) | ||
31 | + assert_equal ['qualifier', ' cert. certifier'], Product.facet_by_id(:solr_plugin_f_qualifier)[:proc].call(p.send(:solr_plugin_f_qualifier).last) | ||
32 | + assert_equal 'hardcore', p.send(:solr_plugin_f_category) | ||
33 | + assert_equal "solr_plugin_category_filter:#{cat.id}", Product.facet_category_query.call(cat) | ||
34 | + end | ||
35 | + | ||
36 | + should 'act as searchable' do | ||
37 | + TestSolr.enable | ||
38 | + s = fast_create(State, :acronym => 'XZ') | ||
39 | + c = fast_create(City, :name => 'Tabajara', :parent_id => s.id) | ||
40 | + ent = fast_create(Enterprise, :region_id => c.id, :name => "Black Sun") | ||
41 | + category = fast_create(ProductCategory, :name => "homemade", :acronym => "hm", :abbreviation => "homey") | ||
42 | + p = Product.create!(:name => 'bananas syrup', :description => 'surrounded by mosquitos', :enterprise_id => ent.id, | ||
43 | + :product_category_id => category.id) | ||
44 | + qual = Qualifier.create!(:name => 'qualificador', :environment_id => Environment.default.id) | ||
45 | + cert = Certifier.create!(:name => 'certificador', :environment_id => Environment.default.id) | ||
46 | + pq = p.product_qualifiers.create!(:qualifier => qual, :certifier => cert) | ||
47 | + p.qualifiers.reload | ||
48 | + p.certifiers.reload | ||
49 | + p.save! | ||
50 | + # fields | ||
51 | + assert_includes Product.find_by_contents('bananas')[:results].docs, p | ||
52 | + assert_includes Product.find_by_contents('mosquitos')[:results].docs, p | ||
53 | + assert_includes Product.find_by_contents('homemade')[:results].docs, p | ||
54 | + # filters | ||
55 | + assert_includes Product.find_by_contents('bananas', {}, { :filter_queries => ["solr_plugin_public:true"]})[:results].docs, p | ||
56 | + assert_not_includes Product.find_by_contents('bananas', {}, { :filter_queries => ["solr_plugin_public:false"]})[:results].docs, p | ||
57 | + assert_includes Product.find_by_contents('bananas', {}, { :filter_queries => ["environment_id:\"#{Environment.default.id}\""]})[:results].docs, p | ||
58 | + # includes | ||
59 | + assert_includes Product.find_by_contents("homemade")[:results].docs, p | ||
60 | + assert_includes Product.find_by_contents(category.slug)[:results].docs, p | ||
61 | + assert_includes Product.find_by_contents("hm")[:results].docs, p | ||
62 | + assert_includes Product.find_by_contents("homey")[:results].docs, p | ||
63 | + assert_includes Product.find_by_contents("Tabajara")[:results].docs, p | ||
64 | + assert_includes Product.find_by_contents("Black Sun")[:results].docs, p | ||
65 | + assert_includes Product.find_by_contents("qualificador")[:results].docs, p | ||
66 | + assert_includes Product.find_by_contents("certificador")[:results].docs, p | ||
67 | + end | ||
68 | + | ||
69 | + should 'boost name matches' do | ||
70 | + TestSolr.enable | ||
71 | + ent = fast_create(Enterprise) | ||
72 | + cat = fast_create(ProductCategory) | ||
73 | + in_desc = Product.create!(:name => 'something', :enterprise_id => ent.id, :description => 'bananas in the description!', | ||
74 | + :product_category_id => cat.id) | ||
75 | + in_name = Product.create!(:name => 'bananas in the name!', :enterprise_id => ent.id, :product_category_id => cat.id) | ||
76 | + assert_equal [in_name, in_desc], Product.find_by_contents('bananas')[:results].docs | ||
77 | + end | ||
78 | + | ||
79 | + should 'boost search results that include an image' do | ||
80 | + TestSolr.enable | ||
81 | + product_without_image = Product.create!(:name => 'product without image', :product_category => product_category, | ||
82 | + :enterprise_id => profile.id) | ||
83 | + product_with_image = Product.create!(:name => 'product with image', :product_category => product_category, | ||
84 | + :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, | ||
85 | + :enterprise_id => profile.id) | ||
86 | + assert_equal [product_with_image, product_without_image], Product.find_by_contents('product image')[:results].docs | ||
87 | + end | ||
88 | + | ||
89 | + should 'boost search results that include qualifier' do | ||
90 | + TestSolr.enable | ||
91 | + product_without_q = Product.create!(:name => 'product without qualifier', :product_category => product_category, | ||
92 | + :enterprise_id => profile.id) | ||
93 | + product_with_q = Product.create!(:name => 'product with qualifier', :product_category => product_category, | ||
94 | + :enterprise_id => profile.id) | ||
95 | + product_with_q.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) | ||
96 | + product_with_q.save! | ||
97 | + | ||
98 | + assert_equal [product_with_q, product_without_q], Product.find_by_contents('product qualifier')[:results].docs | ||
99 | + end | ||
100 | + | ||
101 | + should 'boost search results with open price' do | ||
102 | + TestSolr.enable | ||
103 | + product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id, :price => 100) | ||
104 | + open_price = Product.new(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id, :price => 100) | ||
105 | + open_price.inputs << Input.new(:product => open_price, :product_category_id => product_category.id, :amount_used => 10, :price_per_unit => 10) | ||
106 | + open_price.save! | ||
107 | + | ||
108 | + assert_equal [open_price, product], Product.find_by_contents('product')[:results].docs | ||
109 | + end | ||
110 | + | ||
111 | + should 'boost search results with solidarity inputs' do | ||
112 | + TestSolr.enable | ||
113 | + product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id) | ||
114 | + perc_50 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) | ||
115 | + Input.create!(:product_id => perc_50.id, :product_category_id => product_category.id, | ||
116 | + :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) | ||
117 | + Input.create!(:product_id => perc_50.id, :product_category_id => product_category.id, | ||
118 | + :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) | ||
119 | + perc_50.save! | ||
120 | + perc_75 = Product.create!(:name => 'product 3', :product_category => product_category, :enterprise_id => profile.id) | ||
121 | + Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id, | ||
122 | + :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) | ||
123 | + Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id, | ||
124 | + :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) | ||
125 | + Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id, | ||
126 | + :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) | ||
127 | + Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id, | ||
128 | + :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) | ||
129 | + perc_75.save! | ||
130 | + | ||
131 | + assert_equal [perc_75, perc_50, product], Product.find_by_contents('product')[:results].docs | ||
132 | + end | ||
133 | + | ||
134 | + should 'boost available search results' do | ||
135 | + TestSolr.enable | ||
136 | + product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id) | ||
137 | + product.available = false | ||
138 | + product.save! | ||
139 | + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) | ||
140 | + product2.available = true | ||
141 | + product2.save! | ||
142 | + | ||
143 | + assert_equal [product2, product], Product.find_by_contents('product')[:results].docs | ||
144 | + end | ||
145 | + | ||
146 | + should 'boost search results created updated recently' do | ||
147 | + TestSolr.enable | ||
148 | + product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id) | ||
149 | + product.update_attribute :created_at, Time.now - 10.day | ||
150 | + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) | ||
151 | + | ||
152 | + assert_equal [product2, product], Product.find_by_contents('product')[:results].docs | ||
153 | + end | ||
154 | + | ||
155 | + should 'boost search results with description' do | ||
156 | + TestSolr.enable | ||
157 | + product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id, | ||
158 | + :description => '') | ||
159 | + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id, | ||
160 | + :description => 'a small description') | ||
161 | + | ||
162 | + assert_equal [product2, product], Product.find_by_contents('product')[:results].docs | ||
163 | + end | ||
164 | + | ||
165 | + should 'boost if enterprise is enabled' do | ||
166 | + TestSolr.enable | ||
167 | + ent = Enterprise.create!(:name => 'ent', :identifier => 'ent', :enabled => false) | ||
168 | + product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => ent.id) | ||
169 | + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) | ||
170 | + | ||
171 | + assert_equal [product2, product], Product.find_by_contents('product')[:results].docs | ||
172 | + end | ||
173 | + | ||
174 | + should 'combine different boost types' do | ||
175 | + TestSolr.enable | ||
176 | + product = Product.create!(:name => 'product', :product_category => product_category, :enterprise_id => profile.id) | ||
177 | + image_only = Product.create!(:name => 'product with image', :product_category => product_category, | ||
178 | + :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, | ||
179 | + :enterprise_id => profile.id) | ||
180 | + qual_only = Product.create!(:name => 'product with qualifier', :product_category => product_category, | ||
181 | + :enterprise_id => profile.id) | ||
182 | + img_and_qual = Product.create!(:name => 'product with image and qualifier', :product_category => product_category, | ||
183 | + :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, | ||
184 | + :enterprise_id => profile.id) | ||
185 | + qual_only.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) | ||
186 | + img_and_qual.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) | ||
187 | + qual_only.save! | ||
188 | + img_and_qual.save! | ||
189 | + | ||
190 | + assert_equal [img_and_qual, image_only, qual_only, product], Product.find_by_contents('product')[:results].docs | ||
191 | + end | ||
18 | end | 192 | end |
19 | 193 |
plugins/solr/test/unit/profile_test.rb
@@ -14,4 +14,45 @@ class ProfileTest < ActiveSupport::TestCase | @@ -14,4 +14,45 @@ class ProfileTest < ActiveSupport::TestCase | ||
14 | Profile.expects(:solr_batch_add).with(includes(art)) | 14 | Profile.expects(:solr_batch_add).with(includes(art)) |
15 | profile.save! | 15 | profile.save! |
16 | end | 16 | end |
17 | + | ||
18 | + should 'act as faceted' do | ||
19 | + st = fast_create(State, :acronym => 'XZ') | ||
20 | + city = fast_create(City, :name => 'Tabajara', :parent_id => st.id) | ||
21 | + cat = fast_create(Category) | ||
22 | + prof = fast_create(Person, :region_id => city.id) | ||
23 | + prof.add_category(cat, true) | ||
24 | + assert_equal ['Tabajara', ', XZ'], Profile.facet_by_id(:solr_plugin_f_region)[:proc].call(prof.send(:solr_plugin_f_region)) | ||
25 | + assert_equal "solr_plugin_category_filter:#{cat.id}", Person.facet_category_query.call(cat) | ||
26 | + end | ||
27 | + | ||
28 | + should 'act as searchable' do | ||
29 | + TestSolr.enable | ||
30 | + st = create(State, :name => 'California', :acronym => 'CA', :environment_id => Environment.default.id) | ||
31 | + city = create(City, :name => 'Inglewood', :parent_id => st.id, :environment_id => Environment.default.id) | ||
32 | + p = create(Person, :name => "Hiro", :address => 'U-Stor-It', :nickname => 'Protagonist', | ||
33 | + :user_id => fast_create(User).id, :region_id => city.id) | ||
34 | + cat = create(Category, :name => "Science Fiction", :acronym => "sf", :abbreviation => "sci-fi") | ||
35 | + p.add_category cat | ||
36 | + | ||
37 | + # fields | ||
38 | + assert_includes Profile.find_by_contents('Hiro')[:results].docs, p | ||
39 | + assert_includes Profile.find_by_contents('Protagonist')[:results].docs, p | ||
40 | + # filters | ||
41 | + assert_includes Profile.find_by_contents('Hiro', {}, { :filter_queries => ["solr_plugin_public:true"]})[:results].docs, p | ||
42 | + assert_not_includes Profile.find_by_contents('Hiro', {}, { :filter_queries => ["solr_plugin_public:false"]})[:results].docs, p | ||
43 | + assert_includes Profile.find_by_contents('Hiro', {}, { :filter_queries => ["environment_id:\"#{Environment.default.id}\""]})[:results].docs, p | ||
44 | + # includes | ||
45 | + assert_includes Profile.find_by_contents("Inglewood")[:results].docs, p | ||
46 | + assert_includes Profile.find_by_contents("California")[:results].docs, p | ||
47 | + assert_includes Profile.find_by_contents("Science")[:results].docs, p | ||
48 | + # not includes | ||
49 | + assert_not_includes Profile.find_by_contents('Stor')[:results].docs, p | ||
50 | + end | ||
51 | + | ||
52 | + should 'boost name matches' do | ||
53 | + TestSolr.enable | ||
54 | + in_addr = create(Person, :name => 'something', :address => 'bananas in the address!', :user_id => fast_create(User).id) | ||
55 | + in_name = create(Person, :name => 'bananas in the name!', :user_id => fast_create(User).id) | ||
56 | + assert_equal [in_name], Person.find_by_contents('bananas')[:results].docs | ||
57 | + end | ||
17 | end | 58 | end |
test/unit/acts_as_faceted_test.rb
test/unit/acts_as_searchable_test.rb
test/unit/article_test.rb
@@ -1588,76 +1588,6 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1588,76 +1588,6 @@ class ArticleTest < ActiveSupport::TestCase | ||
1588 | article.environment_id | 1588 | article.environment_id |
1589 | end | 1589 | end |
1590 | 1590 | ||
1591 | - should 'act as faceted' do | ||
1592 | - person = fast_create(Person) | ||
1593 | - cat = Category.create!(:name => 'hardcore', :environment_id => Environment.default.id) | ||
1594 | - a = Article.create!(:name => 'black flag review', :profile_id => person.id) | ||
1595 | - a.add_category(cat, true) | ||
1596 | - a.save! | ||
1597 | - assert_equal Article.type_name, Article.facet_by_id(:f_type)[:proc].call(a.send(:f_type)) | ||
1598 | - assert_equal Person.type_name, Article.facet_by_id(:f_profile_type)[:proc].call(a.send(:f_profile_type)) | ||
1599 | - assert_equal a.published_at, a.send(:f_published_at) | ||
1600 | - assert_equal ['hardcore'], a.send(:f_category) | ||
1601 | - assert_equal "category_filter:\"#{cat.id}\"", Article.facet_category_query.call(cat) | ||
1602 | - end | ||
1603 | - | ||
1604 | - should 'act as searchable' do | ||
1605 | - TestSolr.enable | ||
1606 | - person = fast_create(Person, :name => "Hiro", :address => 'U-Stor-It @ Inglewood, California', | ||
1607 | - :nickname => 'Protagonist') | ||
1608 | - person2 = fast_create(Person, :name => "Raven") | ||
1609 | - category = fast_create(Category, :name => "science fiction", :acronym => "sf", :abbreviation => "sci-fi") | ||
1610 | - a = Article.create!(:name => 'a searchable article about bananas', :profile_id => person.id, | ||
1611 | - :body => 'the body talks about mosquitos', :abstract => 'and the abstract is about beer', | ||
1612 | - :filename => 'not_a_virus.exe') | ||
1613 | - a.add_category(category) | ||
1614 | - c = a.comments.build(:title => 'snow crash', :author => person2, :body => 'wanna try some?') | ||
1615 | - c.save! | ||
1616 | - | ||
1617 | - # fields | ||
1618 | - assert_includes Article.find_by_contents('bananas')[:results].docs, a | ||
1619 | - assert_includes Article.find_by_contents('mosquitos')[:results].docs, a | ||
1620 | - assert_includes Article.find_by_contents('beer')[:results].docs, a | ||
1621 | - assert_includes Article.find_by_contents('not_a_virus.exe')[:results].docs, a | ||
1622 | - # filters | ||
1623 | - assert_includes Article.find_by_contents('bananas', {}, {:filter_queries => ["public:true"]})[:results].docs, a | ||
1624 | - assert_not_includes Article.find_by_contents('bananas', {}, {:filter_queries => ["public:false"]})[:results].docs, a | ||
1625 | - assert_includes Article.find_by_contents('bananas', {}, {:filter_queries => ["environment_id:\"#{Environment.default.id}\""]})[:results].docs, a | ||
1626 | - assert_includes Article.find_by_contents('bananas', {}, {:filter_queries => ["profile_id:\"#{person.id}\""]})[:results].docs, a | ||
1627 | - # includes | ||
1628 | - assert_includes Article.find_by_contents('Hiro')[:results].docs, a | ||
1629 | - assert_includes Article.find_by_contents("person-#{person.id}")[:results].docs, a | ||
1630 | - assert_includes Article.find_by_contents("California")[:results].docs, a | ||
1631 | - assert_includes Article.find_by_contents("Protagonist")[:results].docs, a | ||
1632 | -# FIXME: After merging with AI1826, searching on comments is not working | ||
1633 | -# assert_includes Article.find_by_contents("snow")[:results].docs, a | ||
1634 | -# assert_includes Article.find_by_contents("try some")[:results].docs, a | ||
1635 | -# assert_includes Article.find_by_contents("Raven")[:results].docs, a | ||
1636 | -# | ||
1637 | -# FIXME: After merging with AI1826, searching on categories is not working | ||
1638 | -# assert_includes Article.find_by_contents("science")[:results].docs, a | ||
1639 | -# assert_includes Article.find_by_contents(category.slug)[:results].docs, a | ||
1640 | -# assert_includes Article.find_by_contents("sf")[:results].docs, a | ||
1641 | -# assert_includes Article.find_by_contents("sci-fi")[:results].docs, a | ||
1642 | - end | ||
1643 | - | ||
1644 | - should 'boost name matches' do | ||
1645 | - TestSolr.enable | ||
1646 | - person = fast_create(Person) | ||
1647 | - in_body = Article.create!(:name => 'something', :profile_id => person.id, :body => 'bananas in the body!') | ||
1648 | - in_name = Article.create!(:name => 'bananas in the name!', :profile_id => person.id) | ||
1649 | - assert_equal [in_name, in_body], Article.find_by_contents('bananas')[:results].docs | ||
1650 | - end | ||
1651 | - | ||
1652 | - should 'boost if profile is enabled' do | ||
1653 | - TestSolr.enable | ||
1654 | - person2 = fast_create(Person, :enabled => false) | ||
1655 | - art_profile_disabled = Article.create!(:name => 'profile disabled', :profile_id => person2.id) | ||
1656 | - person1 = fast_create(Person, :enabled => true) | ||
1657 | - art_profile_enabled = Article.create!(:name => 'profile enabled', :profile_id => person1.id) | ||
1658 | - assert_equal [art_profile_enabled, art_profile_disabled], Article.find_by_contents('profile')[:results].docs | ||
1659 | - end | ||
1660 | - | ||
1661 | should 'remove all categorizations when destroyed' do | 1591 | should 'remove all categorizations when destroyed' do |
1662 | art = Article.create!(:name => 'article 1', :profile_id => fast_create(Person).id) | 1592 | art = Article.create!(:name => 'article 1', :profile_id => fast_create(Person).id) |
1663 | cat = Category.create!(:name => 'category 1', :environment_id => Environment.default.id) | 1593 | cat = Category.create!(:name => 'category 1', :environment_id => Environment.default.id) |
test/unit/category_test.rb
@@ -513,28 +513,6 @@ class CategoryTest < ActiveSupport::TestCase | @@ -513,28 +513,6 @@ class CategoryTest < ActiveSupport::TestCase | ||
513 | assert p.categories.reload.empty? | 513 | assert p.categories.reload.empty? |
514 | end | 514 | end |
515 | 515 | ||
516 | - should 'act as searchable' do | ||
517 | - TestSolr.enable | ||
518 | - parent = fast_create(Category, :name => 'books') | ||
519 | - c = Category.create!(:name => "science fiction", :acronym => "sf", :abbreviation => "sci-fi", | ||
520 | - :environment_id => Environment.default.id, :parent_id => parent.id) | ||
521 | - | ||
522 | - # fields | ||
523 | - assert_includes Category.find_by_contents('fiction')[:results].docs, c | ||
524 | - assert_includes Category.find_by_contents('sf')[:results].docs, c | ||
525 | - assert_includes Category.find_by_contents('sci-fi')[:results].docs, c | ||
526 | - # filters | ||
527 | - assert_includes Category.find_by_contents('science', {}, { | ||
528 | - :filter_queries => ["parent_id:#{parent.id}"]})[:results].docs, c | ||
529 | - end | ||
530 | - | ||
531 | - should 'boost name matches' do | ||
532 | - TestSolr.enable | ||
533 | - c_abbr = Category.create!(:name => "something else", :abbreviation => "science", :environment_id => Environment.default.id) | ||
534 | - c_name = Category.create!(:name => "science fiction", :environment_id => Environment.default.id) | ||
535 | - assert_equal [c_name, c_abbr], Category.find_by_contents("science")[:results].docs | ||
536 | - end | ||
537 | - | ||
538 | should 'solr save' do | 516 | should 'solr save' do |
539 | c = @env.categories.build(:name => 'my category'); | 517 | c = @env.categories.build(:name => 'my category'); |
540 | c.expects(:solr_save) | 518 | c.expects(:solr_save) |
test/unit/product_test.rb
@@ -578,178 +578,6 @@ class ProductTest < ActiveSupport::TestCase | @@ -578,178 +578,6 @@ class ProductTest < ActiveSupport::TestCase | ||
578 | product.environment_id | 578 | product.environment_id |
579 | end | 579 | end |
580 | 580 | ||
581 | - should 'act as faceted' do | ||
582 | - s = fast_create(State, :acronym => 'XZ') | ||
583 | - c = fast_create(City, :name => 'Tabajara', :parent_id => s.id) | ||
584 | - ent = fast_create(Enterprise, :region_id => c.id) | ||
585 | - cat = fast_create(ProductCategory, :name => 'hardcore') | ||
586 | - p = Product.create!(:name => 'black flag', :enterprise_id => ent.id, :product_category_id => cat.id) | ||
587 | - pq = p.product_qualifiers.create!(:qualifier => fast_create(Qualifier, :name => 'qualifier'), | ||
588 | - :certifier => fast_create(Certifier, :name => 'certifier')) | ||
589 | - assert_equal 'Related products', Product.facet_by_id(:f_category)[:label] | ||
590 | - assert_equal ['Tabajara', ', XZ'], Product.facet_by_id(:f_region)[:proc].call(p.send(:f_region)) | ||
591 | - assert_equal ['qualifier', ' cert. certifier'], Product.facet_by_id(:f_qualifier)[:proc].call(p.send(:f_qualifier).last) | ||
592 | - assert_equal 'hardcore', p.send(:f_category) | ||
593 | - assert_equal "category_filter:#{cat.id}", Product.facet_category_query.call(cat) | ||
594 | - end | ||
595 | - | ||
596 | - should 'act as searchable' do | ||
597 | - TestSolr.enable | ||
598 | - s = fast_create(State, :acronym => 'XZ') | ||
599 | - c = fast_create(City, :name => 'Tabajara', :parent_id => s.id) | ||
600 | - ent = fast_create(Enterprise, :region_id => c.id, :name => "Black Sun") | ||
601 | - category = fast_create(ProductCategory, :name => "homemade", :acronym => "hm", :abbreviation => "homey") | ||
602 | - p = Product.create!(:name => 'bananas syrup', :description => 'surrounded by mosquitos', :enterprise_id => ent.id, | ||
603 | - :product_category_id => category.id) | ||
604 | - qual = Qualifier.create!(:name => 'qualificador', :environment_id => Environment.default.id) | ||
605 | - cert = Certifier.create!(:name => 'certificador', :environment_id => Environment.default.id) | ||
606 | - pq = p.product_qualifiers.create!(:qualifier => qual, :certifier => cert) | ||
607 | - p.qualifiers.reload | ||
608 | - p.certifiers.reload | ||
609 | - p.save! | ||
610 | - # fields | ||
611 | - assert_includes Product.find_by_contents('bananas')[:results].docs, p | ||
612 | - assert_includes Product.find_by_contents('mosquitos')[:results].docs, p | ||
613 | - assert_includes Product.find_by_contents('homemade')[:results].docs, p | ||
614 | - # filters | ||
615 | - assert_includes Product.find_by_contents('bananas', {}, { :filter_queries => ["public:true"]})[:results].docs, p | ||
616 | - assert_not_includes Product.find_by_contents('bananas', {}, { :filter_queries => ["public:false"]})[:results].docs, p | ||
617 | - assert_includes Product.find_by_contents('bananas', {}, { :filter_queries => ["environment_id:\"#{Environment.default.id}\""]})[:results].docs, p | ||
618 | - # includes | ||
619 | - assert_includes Product.find_by_contents("homemade")[:results].docs, p | ||
620 | - assert_includes Product.find_by_contents(category.slug)[:results].docs, p | ||
621 | - assert_includes Product.find_by_contents("hm")[:results].docs, p | ||
622 | - assert_includes Product.find_by_contents("homey")[:results].docs, p | ||
623 | - assert_includes Product.find_by_contents("Tabajara")[:results].docs, p | ||
624 | - assert_includes Product.find_by_contents("Black Sun")[:results].docs, p | ||
625 | - assert_includes Product.find_by_contents("qualificador")[:results].docs, p | ||
626 | - assert_includes Product.find_by_contents("certificador")[:results].docs, p | ||
627 | - end | ||
628 | - | ||
629 | - should 'boost name matches' do | ||
630 | - TestSolr.enable | ||
631 | - ent = fast_create(Enterprise) | ||
632 | - cat = fast_create(ProductCategory) | ||
633 | - in_desc = Product.create!(:name => 'something', :enterprise_id => ent.id, :description => 'bananas in the description!', | ||
634 | - :product_category_id => cat.id) | ||
635 | - in_name = Product.create!(:name => 'bananas in the name!', :enterprise_id => ent.id, :product_category_id => cat.id) | ||
636 | - assert_equal [in_name, in_desc], Product.find_by_contents('bananas')[:results].docs | ||
637 | - end | ||
638 | - | ||
639 | - should 'boost search results that include an image' do | ||
640 | - TestSolr.enable | ||
641 | - product_without_image = Product.create!(:name => 'product without image', :product_category => @product_category, | ||
642 | - :enterprise_id => @profile.id) | ||
643 | - product_with_image = Product.create!(:name => 'product with image', :product_category => @product_category, | ||
644 | - :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, | ||
645 | - :enterprise_id => @profile.id) | ||
646 | - assert_equal [product_with_image, product_without_image], Product.find_by_contents('product image')[:results].docs | ||
647 | - end | ||
648 | - | ||
649 | - should 'boost search results that include qualifier' do | ||
650 | - TestSolr.enable | ||
651 | - product_without_q = Product.create!(:name => 'product without qualifier', :product_category => @product_category, | ||
652 | - :enterprise_id => @profile.id) | ||
653 | - product_with_q = Product.create!(:name => 'product with qualifier', :product_category => @product_category, | ||
654 | - :enterprise_id => @profile.id) | ||
655 | - product_with_q.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) | ||
656 | - product_with_q.save! | ||
657 | - | ||
658 | - assert_equal [product_with_q, product_without_q], Product.find_by_contents('product qualifier')[:results].docs | ||
659 | - end | ||
660 | - | ||
661 | - should 'boost search results with open price' do | ||
662 | - TestSolr.enable | ||
663 | - product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id, :price => 100) | ||
664 | - open_price = Product.new(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id, :price => 100) | ||
665 | - open_price.inputs << Input.new(:product => open_price, :product_category_id => @product_category.id, :amount_used => 10, :price_per_unit => 10) | ||
666 | - open_price.save! | ||
667 | - | ||
668 | - assert_equal [open_price, product], Product.find_by_contents('product')[:results].docs | ||
669 | - end | ||
670 | - | ||
671 | - should 'boost search results with solidarity inputs' do | ||
672 | - TestSolr.enable | ||
673 | - product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id) | ||
674 | - perc_50 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id) | ||
675 | - Input.create!(:product_id => perc_50.id, :product_category_id => @product_category.id, | ||
676 | - :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) | ||
677 | - Input.create!(:product_id => perc_50.id, :product_category_id => @product_category.id, | ||
678 | - :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) | ||
679 | - perc_50.save! | ||
680 | - perc_75 = Product.create!(:name => 'product 3', :product_category => @product_category, :enterprise_id => @profile.id) | ||
681 | - Input.create!(:product_id => perc_75.id, :product_category_id => @product_category.id, | ||
682 | - :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) | ||
683 | - Input.create!(:product_id => perc_75.id, :product_category_id => @product_category.id, | ||
684 | - :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) | ||
685 | - Input.create!(:product_id => perc_75.id, :product_category_id => @product_category.id, | ||
686 | - :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) | ||
687 | - Input.create!(:product_id => perc_75.id, :product_category_id => @product_category.id, | ||
688 | - :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) | ||
689 | - perc_75.save! | ||
690 | - | ||
691 | - assert_equal [perc_75, perc_50, product], Product.find_by_contents('product')[:results].docs | ||
692 | - end | ||
693 | - | ||
694 | - should 'boost available search results' do | ||
695 | - TestSolr.enable | ||
696 | - product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id) | ||
697 | - product.available = false | ||
698 | - product.save! | ||
699 | - product2 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id) | ||
700 | - product2.available = true | ||
701 | - product2.save! | ||
702 | - | ||
703 | - assert_equal [product2, product], Product.find_by_contents('product')[:results].docs | ||
704 | - end | ||
705 | - | ||
706 | - should 'boost search results created updated recently' do | ||
707 | - TestSolr.enable | ||
708 | - product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id) | ||
709 | - product.update_attribute :created_at, Time.now - 10.day | ||
710 | - product2 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id) | ||
711 | - | ||
712 | - assert_equal [product2, product], Product.find_by_contents('product')[:results].docs | ||
713 | - end | ||
714 | - | ||
715 | - should 'boost search results with description' do | ||
716 | - TestSolr.enable | ||
717 | - product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => @profile.id, | ||
718 | - :description => '') | ||
719 | - product2 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id, | ||
720 | - :description => 'a small description') | ||
721 | - | ||
722 | - assert_equal [product2, product], Product.find_by_contents('product')[:results].docs | ||
723 | - end | ||
724 | - | ||
725 | - should 'boost if enterprise is enabled' do | ||
726 | - TestSolr.enable | ||
727 | - ent = Enterprise.create!(:name => 'ent', :identifier => 'ent', :enabled => false) | ||
728 | - product = Product.create!(:name => 'product 1', :product_category => @product_category, :enterprise_id => ent.id) | ||
729 | - product2 = Product.create!(:name => 'product 2', :product_category => @product_category, :enterprise_id => @profile.id) | ||
730 | - | ||
731 | - assert_equal [product2, product], Product.find_by_contents('product')[:results].docs | ||
732 | - end | ||
733 | - | ||
734 | - should 'combine different boost types' do | ||
735 | - TestSolr.enable | ||
736 | - product = Product.create!(:name => 'product', :product_category => @product_category, :enterprise_id => @profile.id) | ||
737 | - image_only = Product.create!(:name => 'product with image', :product_category => @product_category, | ||
738 | - :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, | ||
739 | - :enterprise_id => @profile.id) | ||
740 | - qual_only = Product.create!(:name => 'product with qualifier', :product_category => @product_category, | ||
741 | - :enterprise_id => @profile.id) | ||
742 | - img_and_qual = Product.create!(:name => 'product with image and qualifier', :product_category => @product_category, | ||
743 | - :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, | ||
744 | - :enterprise_id => @profile.id) | ||
745 | - qual_only.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) | ||
746 | - img_and_qual.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) | ||
747 | - qual_only.save! | ||
748 | - img_and_qual.save! | ||
749 | - | ||
750 | - assert_equal [img_and_qual, image_only, qual_only, product], Product.find_by_contents('product')[:results].docs | ||
751 | - end | ||
752 | - | ||
753 | should 'return more recent products' do | 581 | should 'return more recent products' do |
754 | Product.destroy_all | 582 | Product.destroy_all |
755 | 583 |
test/unit/profile_test.rb
@@ -1868,47 +1868,6 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1868,47 +1868,6 @@ class ProfileTest < ActiveSupport::TestCase | ||
1868 | assert profile.errors.invalid?(:identifier) | 1868 | assert profile.errors.invalid?(:identifier) |
1869 | end | 1869 | end |
1870 | 1870 | ||
1871 | - should 'act as faceted' do | ||
1872 | - st = fast_create(State, :acronym => 'XZ') | ||
1873 | - city = fast_create(City, :name => 'Tabajara', :parent_id => st.id) | ||
1874 | - cat = fast_create(Category) | ||
1875 | - prof = fast_create(Person, :region_id => city.id) | ||
1876 | - prof.add_category(cat, true) | ||
1877 | - assert_equal ['Tabajara', ', XZ'], Profile.facet_by_id(:f_region)[:proc].call(prof.send(:f_region)) | ||
1878 | - assert_equal "category_filter:#{cat.id}", Person.facet_category_query.call(cat) | ||
1879 | - end | ||
1880 | - | ||
1881 | - should 'act as searchable' do | ||
1882 | - TestSolr.enable | ||
1883 | - st = create(State, :name => 'California', :acronym => 'CA', :environment_id => Environment.default.id) | ||
1884 | - city = create(City, :name => 'Inglewood', :parent_id => st.id, :environment_id => Environment.default.id) | ||
1885 | - p = create(Person, :name => "Hiro", :address => 'U-Stor-It', :nickname => 'Protagonist', | ||
1886 | - :user_id => fast_create(User).id, :region_id => city.id) | ||
1887 | - cat = create(Category, :name => "Science Fiction", :acronym => "sf", :abbreviation => "sci-fi") | ||
1888 | - p.add_category cat | ||
1889 | - | ||
1890 | - # fields | ||
1891 | - assert_includes Profile.find_by_contents('Hiro')[:results].docs, p | ||
1892 | - assert_includes Profile.find_by_contents('Protagonist')[:results].docs, p | ||
1893 | - # filters | ||
1894 | - assert_includes Profile.find_by_contents('Hiro', {}, { :filter_queries => ["public:true"]})[:results].docs, p | ||
1895 | - assert_not_includes Profile.find_by_contents('Hiro', {}, { :filter_queries => ["public:false"]})[:results].docs, p | ||
1896 | - assert_includes Profile.find_by_contents('Hiro', {}, { :filter_queries => ["environment_id:\"#{Environment.default.id}\""]})[:results].docs, p | ||
1897 | - # includes | ||
1898 | - assert_includes Profile.find_by_contents("Inglewood")[:results].docs, p | ||
1899 | - assert_includes Profile.find_by_contents("California")[:results].docs, p | ||
1900 | - assert_includes Profile.find_by_contents("Science")[:results].docs, p | ||
1901 | - # not includes | ||
1902 | - assert_not_includes Profile.find_by_contents('Stor')[:results].docs, p | ||
1903 | - end | ||
1904 | - | ||
1905 | - should 'boost name matches' do | ||
1906 | - TestSolr.enable | ||
1907 | - in_addr = create(Person, :name => 'something', :address => 'bananas in the address!', :user_id => fast_create(User).id) | ||
1908 | - in_name = create(Person, :name => 'bananas in the name!', :user_id => fast_create(User).id) | ||
1909 | - assert_equal [in_name], Person.find_by_contents('bananas')[:results].docs | ||
1910 | - end | ||
1911 | - | ||
1912 | should 'respond to redirection_after_login' do | 1871 | should 'respond to redirection_after_login' do |
1913 | assert_respond_to Profile.new, :redirection_after_login | 1872 | assert_respond_to Profile.new, :redirection_after_login |
1914 | end | 1873 | end |