Commit 10a5b12eec26175ae2abd2330d0c0872ff2671b8
1 parent
fc5d5b0e
Exists in
master
and in
23 other branches
Search fixes for Product and Profile
* named_scope on update * removed facet 'type' * added facet 'region'
Showing
2 changed files
with
18 additions
and
9 deletions
Show diff stats
app/models/product.rb
| ... | ... | @@ -19,6 +19,8 @@ class Product < ActiveRecord::Base |
| 19 | 19 | validates_numericality_of :price, :allow_nil => true |
| 20 | 20 | validates_numericality_of :discount, :allow_nil => true |
| 21 | 21 | |
| 22 | + named_scope :more_recent, :order => "updated_at DESC" | |
| 23 | + | |
| 22 | 24 | after_update :save_image |
| 23 | 25 | |
| 24 | 26 | before_create do |p| | ... | ... |
app/models/profile.rb
| ... | ... | @@ -87,7 +87,7 @@ class Profile < ActiveRecord::Base |
| 87 | 87 | named_scope :more_popular |
| 88 | 88 | named_scope :more_active |
| 89 | 89 | |
| 90 | - named_scope :more_recent, :order => "created_at DESC" | |
| 90 | + named_scope :more_recent, :order => "updated_at DESC" | |
| 91 | 91 | |
| 92 | 92 | acts_as_trackable :dependent => :destroy |
| 93 | 93 | |
| ... | ... | @@ -847,12 +847,17 @@ private :generate_url, :url_options |
| 847 | 847 | def f_categories |
| 848 | 848 | category_ids |
| 849 | 849 | end |
| 850 | - | |
| 851 | - def f_type | |
| 852 | - self.class.name | |
| 850 | + def f_region | |
| 851 | + self.region.id if self.region | |
| 853 | 852 | end |
| 854 | - def self.f_type_proc(klass) | |
| 855 | - klass.constantize.type_name | |
| 853 | + def self.f_region_proc(id) | |
| 854 | + c = Region.find(id) | |
| 855 | + s = c.parent | |
| 856 | + if c and c.kind_of?(City) and s and s.kind_of?(State) and s.acronym | |
| 857 | + [c.name, ', ' + s.acronym] | |
| 858 | + else | |
| 859 | + c.name | |
| 860 | + end | |
| 856 | 861 | end |
| 857 | 862 | def name_sort |
| 858 | 863 | name |
| ... | ... | @@ -863,17 +868,19 @@ private :generate_url, :url_options |
| 863 | 868 | public |
| 864 | 869 | |
| 865 | 870 | acts_as_faceted :fields => { |
| 866 | - :f_type => {:label => _('Type'), :type_if => proc { |klass| klass.kind_of?(Enterprise) }, :proc => proc { |id| f_type_proc(id) }}, | |
| 867 | - :f_categories => {:multi => true, :proc => proc {|facet, id| f_categories_proc(facet, id)}, | |
| 871 | + :f_region => {:label => _('City'), :type_if => proc { |klass| klass.kind_of?(Enterprise) }, | |
| 872 | + :proc => proc { |id| f_region_proc(id) }}, | |
| 873 | + :f_categories => {:multi => true, :proc => proc {|facet, id| f_categories_proc(facet, id)}, | |
| 868 | 874 | :label => proc { |env| f_categories_label_proc(env) }, :label_abbrev => proc { |env| f_categories_label_abbrev_proc(env) }}}, |
| 869 | 875 | :category_query => proc { |c| "f_categories:#{c.id}" }, |
| 870 | - :order => [:f_type, :f_categories] | |
| 876 | + :order => [:f_region, :f_categories] | |
| 871 | 877 | |
| 872 | 878 | acts_as_searchable :additional_fields => [ |
| 873 | 879 | {:name_sort => {:type => :string}}, |
| 874 | 880 | {:public => {:type => :boolean}}, |
| 875 | 881 | :extra_data_for_index ] + facets.keys.map{|i| {i => :facet}}, |
| 876 | 882 | :boost => proc {|p| 10 if p.enabled}, |
| 883 | + :include => [:categories, :region], | |
| 877 | 884 | :facets => facets.keys |
| 878 | 885 | handle_asynchronously :solr_save |
| 879 | 886 | ... | ... |