Commit 8e197eb47a1db4ca299a31830222ec23fec7ea0f
1 parent
aea0c47f
Exists in
master
and in
29 other branches
Fix category filtering and other minors
Showing
7 changed files
with
36 additions
and
27 deletions
Show diff stats
app/controllers/public/profile_search_controller.rb
... | ... | @@ -11,7 +11,8 @@ class ProfileSearchController < PublicController |
11 | 11 | if params[:where] == 'environment' |
12 | 12 | redirect_to :controller => 'search', :query => @q |
13 | 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 | 16 | end |
16 | 17 | end |
17 | 18 | end | ... | ... |
app/models/article.rb
... | ... | @@ -28,6 +28,9 @@ class Article < ActiveRecord::Base |
28 | 28 | has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ] |
29 | 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 | 34 | acts_as_having_settings :field => :setting |
32 | 35 | |
33 | 36 | settings_items :display_hits, :type => :boolean, :default => true |
... | ... | @@ -626,6 +629,9 @@ class Article < ActiveRecord::Base |
626 | 629 | def public |
627 | 630 | self.public? |
628 | 631 | end |
632 | + def category_filter | |
633 | + categories_including_virtual_ids | |
634 | + end | |
629 | 635 | public |
630 | 636 | |
631 | 637 | acts_as_faceted :fields => { |
... | ... | @@ -634,8 +640,8 @@ class Article < ActiveRecord::Base |
634 | 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 | 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 | 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 | 645 | :order => [:f_type, :f_published_at, :f_profile_type, :f_category] |
640 | 646 | |
641 | 647 | acts_as_searchable :fields => facets_fields_for_solr + [ |
... | ... | @@ -645,7 +651,8 @@ class Article < ActiveRecord::Base |
645 | 651 | {:abstract => :text}, {:filename => :text}, |
646 | 652 | # filtered fields |
647 | 653 | {:public => :boolean}, {:environment_id => :integer}, |
648 | - :language, :published, | |
654 | + {:profile_id => :integer}, :language, | |
655 | + {:category_filter => :integer}, | |
649 | 656 | # ordered/query-boosted fields |
650 | 657 | {:name_sortable => :string}, :last_changed_by_id, :published_at, :is_image, |
651 | 658 | :updated_at, :created_at, | ... | ... |
app/models/product.rb
... | ... | @@ -245,18 +245,18 @@ class Product < ActiveRecord::Base |
245 | 245 | self.public? |
246 | 246 | end |
247 | 247 | def price_sortable |
248 | - (price.nil? or price.zero?) ? 999999999.9 : price | |
248 | + (price.nil? or price.zero?) ? nil : price | |
249 | 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 | 252 | end |
253 | 253 | public |
254 | 254 | |
255 | 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 | 260 | :order => [:f_category, :f_region, :f_qualifier] |
261 | 261 | |
262 | 262 | Boosts = [ |
... | ... | @@ -277,7 +277,7 @@ class Product < ActiveRecord::Base |
277 | 277 | {:description => :text}, |
278 | 278 | # filtered fields |
279 | 279 | {:public => :boolean}, {:environment_id => :integer}, |
280 | - {:categories => :integer}, | |
280 | + {:category_filter => :integer}, | |
281 | 281 | # ordered/query-boosted fields |
282 | 282 | {:price_sortable => :decimal}, {:name_sortable => :string}, |
283 | 283 | {:lat => :float}, {:lng => :float}, | ... | ... |
app/models/profile.rb
... | ... | @@ -179,6 +179,9 @@ class Profile < ActiveRecord::Base |
179 | 179 | has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ] |
180 | 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 | 185 | has_many :abuse_complaints, :foreign_key => 'requestor_id' |
183 | 186 | |
184 | 187 | def top_level_categorization |
... | ... | @@ -839,6 +842,7 @@ private :generate_url, :url_options |
839 | 842 | end |
840 | 843 | def self.f_categories_proc(facet, id) |
841 | 844 | id = id.to_i |
845 | + return if id.zero? | |
842 | 846 | c = Category.find(id) |
843 | 847 | c.name if c.top_ancestor.id == facet[:label_id].to_i or facet[:label_id] == 0 |
844 | 848 | end |
... | ... | @@ -846,7 +850,7 @@ private :generate_url, :url_options |
846 | 850 | category_ids |
847 | 851 | end |
848 | 852 | def f_region |
849 | - self.region.id if self.region | |
853 | + self.region_id | |
850 | 854 | end |
851 | 855 | def self.f_region_proc(id) |
852 | 856 | c = Region.find(id) |
... | ... | @@ -864,14 +868,16 @@ private :generate_url, :url_options |
864 | 868 | def public |
865 | 869 | self.public? |
866 | 870 | end |
871 | + def category_filter | |
872 | + categories_including_virtual_ids | |
873 | + end | |
867 | 874 | public |
868 | 875 | |
869 | 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 | 881 | :order => [:f_region, :f_categories] |
876 | 882 | |
877 | 883 | acts_as_searchable :fields => facets_fields_for_solr + [:extra_data_for_index, |
... | ... | @@ -880,6 +886,7 @@ private :generate_url, :url_options |
880 | 886 | {:identifier => :text}, {:address => :text}, {:nickname => :text}, |
881 | 887 | # filtered fields |
882 | 888 | {:public => :boolean}, {:environment_id => :integer}, |
889 | + {:category_filter => :integer}, | |
883 | 890 | # ordered/query-boosted fields |
884 | 891 | {:name_sortable => :string}, {:user_id => :integer}, |
885 | 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 | 2 | <% @order.each do |name| %> |
3 | 3 | <% results = @results[name] %> |
4 | 4 | <% empty = results.nil? || results.empty? %> | ... | ... |
public/stylesheets/application.css
... | ... | @@ -3821,8 +3821,6 @@ h1#agenda-title { |
3821 | 3821 | -moz-border-radius:10px; |
3822 | 3822 | -webkit-border-radius:10px; |
3823 | 3823 | } |
3824 | -/* ==> public/stylesheets/controller_search.css <== */ | |
3825 | -/* @import url(pagination.css); ALREADY INCLUDED ABOVE */ | |
3826 | 3824 | |
3827 | 3825 | /* * * Profile search * * * * * * * */ |
3828 | 3826 | |
... | ... | @@ -3833,17 +3831,13 @@ h1#agenda-title { |
3833 | 3831 | -moz-border-radius: 5px; |
3834 | 3832 | -webkit-border-radius: 5px; |
3835 | 3833 | } |
3836 | -#public-profile-search .formfield input { | |
3837 | - width: 395px; | |
3838 | -} | |
3839 | -/* * * Profile Search Results * * * * * * * */ | |
3840 | 3834 | |
3841 | 3835 | #profile-search-results ul { |
3842 | 3836 | padding-left: 0px; |
3843 | 3837 | margin-left: 0px; |
3844 | 3838 | } |
3845 | 3839 | #profile-search-results form .formfield input { |
3846 | - width: 395px; | |
3840 | + width: 362px; | |
3847 | 3841 | } |
3848 | 3842 | #profile-search-results form .search_form .button { |
3849 | 3843 | margin-top: 5px; | ... | ... |
public/stylesheets/search.css
... | ... | @@ -121,7 +121,7 @@ |
121 | 121 | color: #FFF; |
122 | 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 | 125 | overflow: hidden; |
126 | 126 | } |
127 | 127 | .controller-search .search-results-innerbox { | ... | ... |