Commit 8e197eb47a1db4ca299a31830222ec23fec7ea0f

Authored by Braulio Bhavamitra
1 parent aea0c47f

Fix category filtering and other minors

app/controllers/public/profile_search_controller.rb
@@ -11,7 +11,8 @@ class ProfileSearchController < PublicController @@ -11,7 +11,8 @@ class ProfileSearchController < PublicController
11 if params[:where] == 'environment' 11 if params[:where] == 'environment'
12 redirect_to :controller => 'search', :query => @q 12 redirect_to :controller => 'search', :query => @q
13 else 13 else
14 - @results = Article.find_by_contents(@q, {}, {:filter_queries => ["profile_id:#{profile.id}", 'published:true']})[:results].paginate(:per_page => 10, :page => params[:page]) 14 + @results = Article.find_by_contents(@q, {:per_page => 10, :page => params[:page]},
  15 + {:filter_queries => ["profile_id:#{profile.id}", 'public:true']})[:results]
15 end 16 end
16 end 17 end
17 end 18 end
app/models/article.rb
@@ -28,6 +28,9 @@ class Article < ActiveRecord::Base @@ -28,6 +28,9 @@ class Article < ActiveRecord::Base
28 has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ] 28 has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ]
29 has_many :categories, :through => :article_categorizations 29 has_many :categories, :through => :article_categorizations
30 30
  31 + has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization'
  32 + has_many :categories_including_virtual, :through => :article_categorizations_including_virtual, :source => :category
  33 +
31 acts_as_having_settings :field => :setting 34 acts_as_having_settings :field => :setting
32 35
33 settings_items :display_hits, :type => :boolean, :default => true 36 settings_items :display_hits, :type => :boolean, :default => true
@@ -626,6 +629,9 @@ class Article < ActiveRecord::Base @@ -626,6 +629,9 @@ class Article < ActiveRecord::Base
626 def public 629 def public
627 self.public? 630 self.public?
628 end 631 end
  632 + def category_filter
  633 + categories_including_virtual_ids
  634 + end
629 public 635 public
630 636
631 acts_as_faceted :fields => { 637 acts_as_faceted :fields => {
@@ -634,8 +640,8 @@ class Article < ActiveRecord::Base @@ -634,8 +640,8 @@ class Article < ActiveRecord::Base
634 '[NOW-1YEARS TO NOW/DAY]' => _("Last year"), '[NOW-1MONTHS TO NOW/DAY]' => _("Last month"), '[NOW-7DAYS TO NOW/DAY]' => _("Last week"), '[NOW-1DAYS TO NOW/DAY]' => _("Last day")}, 640 '[NOW-1YEARS TO NOW/DAY]' => _("Last year"), '[NOW-1MONTHS TO NOW/DAY]' => _("Last month"), '[NOW-7DAYS TO NOW/DAY]' => _("Last week"), '[NOW-1DAYS TO NOW/DAY]' => _("Last day")},
635 :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]']}, 641 :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]']},
636 :f_profile_type => {:label => _('Profile'), :proc => proc{|klass| f_profile_type_proc(klass)}}, 642 :f_profile_type => {:label => _('Profile'), :proc => proc{|klass| f_profile_type_proc(klass)}},
637 - :f_category => {:label => _('Categories')}},  
638 - :category_query => proc { |c| "f_category:\"#{c.name}\"" }, 643 + :f_category => {:label => _('Categories')},
  644 + }, :category_query => proc { |c| "category_filter:\"#{c.id}\"" },
639 :order => [:f_type, :f_published_at, :f_profile_type, :f_category] 645 :order => [:f_type, :f_published_at, :f_profile_type, :f_category]
640 646
641 acts_as_searchable :fields => facets_fields_for_solr + [ 647 acts_as_searchable :fields => facets_fields_for_solr + [
@@ -645,7 +651,8 @@ class Article < ActiveRecord::Base @@ -645,7 +651,8 @@ class Article < ActiveRecord::Base
645 {:abstract => :text}, {:filename => :text}, 651 {:abstract => :text}, {:filename => :text},
646 # filtered fields 652 # filtered fields
647 {:public => :boolean}, {:environment_id => :integer}, 653 {:public => :boolean}, {:environment_id => :integer},
648 - :language, :published, 654 + {:profile_id => :integer}, :language,
  655 + {:category_filter => :integer},
649 # ordered/query-boosted fields 656 # ordered/query-boosted fields
650 {:name_sortable => :string}, :last_changed_by_id, :published_at, :is_image, 657 {:name_sortable => :string}, :last_changed_by_id, :published_at, :is_image,
651 :updated_at, :created_at, 658 :updated_at, :created_at,
app/models/product.rb
@@ -245,18 +245,18 @@ class Product < ActiveRecord::Base @@ -245,18 +245,18 @@ class Product < ActiveRecord::Base
245 self.public? 245 self.public?
246 end 246 end
247 def price_sortable 247 def price_sortable
248 - (price.nil? or price.zero?) ? 999999999.9 : price 248 + (price.nil? or price.zero?) ? nil : price
249 end 249 end
250 - def categories  
251 - enterprise.category_ids << product_category_id 250 + def category_filter
  251 + enterprise.categories_including_virtual_ids << product_category_id
252 end 252 end
253 public 253 public
254 254
255 acts_as_faceted :fields => { 255 acts_as_faceted :fields => {
256 - :f_category => {:label => _('Related products')},  
257 - :f_region => {:label => _('City'), :proc => proc { |id| f_region_proc(id) }},  
258 - :f_qualifier => {:label => _('Qualifiers'), :proc => proc { |id| f_qualifier_proc(id) }}},  
259 - :category_query => proc { |c| "categories:#{c.id}" }, 256 + :f_category => {:label => _('Related products')},
  257 + :f_region => {:label => _('City'), :proc => proc { |id| f_region_proc(id) }},
  258 + :f_qualifier => {:label => _('Qualifiers'), :proc => proc { |id| f_qualifier_proc(id) }},
  259 + }, :category_query => proc { |c| "category_filter:#{c.id}" },
260 :order => [:f_category, :f_region, :f_qualifier] 260 :order => [:f_category, :f_region, :f_qualifier]
261 261
262 Boosts = [ 262 Boosts = [
@@ -277,7 +277,7 @@ class Product &lt; ActiveRecord::Base @@ -277,7 +277,7 @@ class Product &lt; ActiveRecord::Base
277 {:description => :text}, 277 {:description => :text},
278 # filtered fields 278 # filtered fields
279 {:public => :boolean}, {:environment_id => :integer}, 279 {:public => :boolean}, {:environment_id => :integer},
280 - {:categories => :integer}, 280 + {:category_filter => :integer},
281 # ordered/query-boosted fields 281 # ordered/query-boosted fields
282 {:price_sortable => :decimal}, {:name_sortable => :string}, 282 {:price_sortable => :decimal}, {:name_sortable => :string},
283 {:lat => :float}, {:lng => :float}, 283 {:lat => :float}, {:lng => :float},
app/models/profile.rb
@@ -179,6 +179,9 @@ class Profile &lt; ActiveRecord::Base @@ -179,6 +179,9 @@ class Profile &lt; ActiveRecord::Base
179 has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ] 179 has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ]
180 has_many :categories, :through => :profile_categorizations 180 has_many :categories, :through => :profile_categorizations
181 181
  182 + has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization'
  183 + has_many :categories_including_virtual, :through => :profile_categorizations_including_virtual, :source => :category
  184 +
182 has_many :abuse_complaints, :foreign_key => 'requestor_id' 185 has_many :abuse_complaints, :foreign_key => 'requestor_id'
183 186
184 def top_level_categorization 187 def top_level_categorization
@@ -839,6 +842,7 @@ private :generate_url, :url_options @@ -839,6 +842,7 @@ private :generate_url, :url_options
839 end 842 end
840 def self.f_categories_proc(facet, id) 843 def self.f_categories_proc(facet, id)
841 id = id.to_i 844 id = id.to_i
  845 + return if id.zero?
842 c = Category.find(id) 846 c = Category.find(id)
843 c.name if c.top_ancestor.id == facet[:label_id].to_i or facet[:label_id] == 0 847 c.name if c.top_ancestor.id == facet[:label_id].to_i or facet[:label_id] == 0
844 end 848 end
@@ -846,7 +850,7 @@ private :generate_url, :url_options @@ -846,7 +850,7 @@ private :generate_url, :url_options
846 category_ids 850 category_ids
847 end 851 end
848 def f_region 852 def f_region
849 - self.region.id if self.region 853 + self.region_id
850 end 854 end
851 def self.f_region_proc(id) 855 def self.f_region_proc(id)
852 c = Region.find(id) 856 c = Region.find(id)
@@ -864,14 +868,16 @@ private :generate_url, :url_options @@ -864,14 +868,16 @@ private :generate_url, :url_options
864 def public 868 def public
865 self.public? 869 self.public?
866 end 870 end
  871 + def category_filter
  872 + categories_including_virtual_ids
  873 + end
867 public 874 public
868 875
869 acts_as_faceted :fields => { 876 acts_as_faceted :fields => {
870 - :f_region => {:label => _('City'), :type_if => proc { |klass| klass.kind_of?(Enterprise) },  
871 - :proc => proc { |id| f_region_proc(id) }},  
872 - :f_categories => {:multi => true, :proc => proc {|facet, id| f_categories_proc(facet, id)},  
873 - :label => proc { |env| f_categories_label_proc(env) }, :label_abbrev => proc { |env| f_categories_label_abbrev_proc(env) }}},  
874 - :category_query => proc { |c| "f_categories:#{c.id}" }, 877 + :f_region => {:label => _('City'), :proc => proc { |id| f_region_proc(id) }},
  878 + :f_categories => {:multi => true, :proc => proc {|facet, id| f_categories_proc(facet, id)},
  879 + :label => proc { |env| f_categories_label_proc(env) }, :label_abbrev => proc{ |env| f_categories_label_abbrev_proc(env) }},
  880 + }, :category_query => proc { |c| "category_filter:#{c.id}" },
875 :order => [:f_region, :f_categories] 881 :order => [:f_region, :f_categories]
876 882
877 acts_as_searchable :fields => facets_fields_for_solr + [:extra_data_for_index, 883 acts_as_searchable :fields => facets_fields_for_solr + [:extra_data_for_index,
@@ -880,6 +886,7 @@ private :generate_url, :url_options @@ -880,6 +886,7 @@ private :generate_url, :url_options
880 {:identifier => :text}, {:address => :text}, {:nickname => :text}, 886 {:identifier => :text}, {:address => :text}, {:nickname => :text},
881 # filtered fields 887 # filtered fields
882 {:public => :boolean}, {:environment_id => :integer}, 888 {:public => :boolean}, {:environment_id => :integer},
  889 + {:category_filter => :integer},
883 # ordered/query-boosted fields 890 # ordered/query-boosted fields
884 {:name_sortable => :string}, {:user_id => :integer}, 891 {:name_sortable => :string}, {:user_id => :integer},
885 :enabled, :active, :validated, :public_profile, 892 :enabled, :active, :validated, :public_profile,
app/views/search/_display_results.rhtml
1 -<div id="search-results" class="<%= 'only-one-result-box' if @results.size == 1 %>"> 1 +<div id="search-results" class="<%= @results.size == 1 ? 'only-one-result-box' : 'multiple-results-boxes' %>">
2 <% @order.each do |name| %> 2 <% @order.each do |name| %>
3 <% results = @results[name] %> 3 <% results = @results[name] %>
4 <% empty = results.nil? || results.empty? %> 4 <% empty = results.nil? || results.empty? %>
public/stylesheets/application.css
@@ -3821,8 +3821,6 @@ h1#agenda-title { @@ -3821,8 +3821,6 @@ h1#agenda-title {
3821 -moz-border-radius:10px; 3821 -moz-border-radius:10px;
3822 -webkit-border-radius:10px; 3822 -webkit-border-radius:10px;
3823 } 3823 }
3824 -/* ==> public/stylesheets/controller_search.css <== */  
3825 -/* @import url(pagination.css); ALREADY INCLUDED ABOVE */  
3826 3824
3827 /* * * Profile search * * * * * * * */ 3825 /* * * Profile search * * * * * * * */
3828 3826
@@ -3833,17 +3831,13 @@ h1#agenda-title { @@ -3833,17 +3831,13 @@ h1#agenda-title {
3833 -moz-border-radius: 5px; 3831 -moz-border-radius: 5px;
3834 -webkit-border-radius: 5px; 3832 -webkit-border-radius: 5px;
3835 } 3833 }
3836 -#public-profile-search .formfield input {  
3837 - width: 395px;  
3838 -}  
3839 -/* * * Profile Search Results * * * * * * * */  
3840 3834
3841 #profile-search-results ul { 3835 #profile-search-results ul {
3842 padding-left: 0px; 3836 padding-left: 0px;
3843 margin-left: 0px; 3837 margin-left: 0px;
3844 } 3838 }
3845 #profile-search-results form .formfield input { 3839 #profile-search-results form .formfield input {
3846 - width: 395px; 3840 + width: 362px;
3847 } 3841 }
3848 #profile-search-results form .search_form .button { 3842 #profile-search-results form .search_form .button {
3849 margin-top: 5px; 3843 margin-top: 5px;
public/stylesheets/search.css
@@ -121,7 +121,7 @@ @@ -121,7 +121,7 @@
121 color: #FFF; 121 color: #FFF;
122 text-decoration: none; 122 text-decoration: none;
123 } 123 }
124 -.controller-search .search-results-innerbox.common-profile-list-block { 124 +.controller-search .multiple-results-boxes .search-results-innerbox.common-profile-list-block {
125 overflow: hidden; 125 overflow: hidden;
126 } 126 }
127 .controller-search .search-results-innerbox { 127 .controller-search .search-results-innerbox {