Commit 10a5b12eec26175ae2abd2330d0c0872ff2671b8
1 parent
fc5d5b0e
Exists in
master
and in
29 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,6 +19,8 @@ class Product < ActiveRecord::Base | ||
19 | validates_numericality_of :price, :allow_nil => true | 19 | validates_numericality_of :price, :allow_nil => true |
20 | validates_numericality_of :discount, :allow_nil => true | 20 | validates_numericality_of :discount, :allow_nil => true |
21 | 21 | ||
22 | + named_scope :more_recent, :order => "updated_at DESC" | ||
23 | + | ||
22 | after_update :save_image | 24 | after_update :save_image |
23 | 25 | ||
24 | before_create do |p| | 26 | before_create do |p| |
app/models/profile.rb
@@ -87,7 +87,7 @@ class Profile < ActiveRecord::Base | @@ -87,7 +87,7 @@ class Profile < ActiveRecord::Base | ||
87 | named_scope :more_popular | 87 | named_scope :more_popular |
88 | named_scope :more_active | 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 | acts_as_trackable :dependent => :destroy | 92 | acts_as_trackable :dependent => :destroy |
93 | 93 | ||
@@ -847,12 +847,17 @@ private :generate_url, :url_options | @@ -847,12 +847,17 @@ private :generate_url, :url_options | ||
847 | def f_categories | 847 | def f_categories |
848 | category_ids | 848 | category_ids |
849 | end | 849 | end |
850 | - | ||
851 | - def f_type | ||
852 | - self.class.name | 850 | + def f_region |
851 | + self.region.id if self.region | ||
853 | end | 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 | end | 861 | end |
857 | def name_sort | 862 | def name_sort |
858 | name | 863 | name |
@@ -863,17 +868,19 @@ private :generate_url, :url_options | @@ -863,17 +868,19 @@ private :generate_url, :url_options | ||
863 | public | 868 | public |
864 | 869 | ||
865 | acts_as_faceted :fields => { | 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 | :label => proc { |env| f_categories_label_proc(env) }, :label_abbrev => proc { |env| f_categories_label_abbrev_proc(env) }}}, | 874 | :label => proc { |env| f_categories_label_proc(env) }, :label_abbrev => proc { |env| f_categories_label_abbrev_proc(env) }}}, |
869 | :category_query => proc { |c| "f_categories:#{c.id}" }, | 875 | :category_query => proc { |c| "f_categories:#{c.id}" }, |
870 | - :order => [:f_type, :f_categories] | 876 | + :order => [:f_region, :f_categories] |
871 | 877 | ||
872 | acts_as_searchable :additional_fields => [ | 878 | acts_as_searchable :additional_fields => [ |
873 | {:name_sort => {:type => :string}}, | 879 | {:name_sort => {:type => :string}}, |
874 | {:public => {:type => :boolean}}, | 880 | {:public => {:type => :boolean}}, |
875 | :extra_data_for_index ] + facets.keys.map{|i| {i => :facet}}, | 881 | :extra_data_for_index ] + facets.keys.map{|i| {i => :facet}}, |
876 | :boost => proc {|p| 10 if p.enabled}, | 882 | :boost => proc {|p| 10 if p.enabled}, |
883 | + :include => [:categories, :region], | ||
877 | :facets => facets.keys | 884 | :facets => facets.keys |
878 | handle_asynchronously :solr_save | 885 | handle_asynchronously :solr_save |
879 | 886 |