From 8e197eb47a1db4ca299a31830222ec23fec7ea0f Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Thu, 5 Apr 2012 10:53:04 +0000 Subject: [PATCH] Fix category filtering and other minors --- app/controllers/public/profile_search_controller.rb | 3 ++- app/models/article.rb | 13 ++++++++++--- app/models/product.rb | 16 ++++++++-------- app/models/profile.rb | 19 +++++++++++++------ app/views/search/_display_results.rhtml | 2 +- public/stylesheets/application.css | 8 +------- public/stylesheets/search.css | 2 +- 7 files changed, 36 insertions(+), 27 deletions(-) diff --git a/app/controllers/public/profile_search_controller.rb b/app/controllers/public/profile_search_controller.rb index fb108fe..e69174d 100644 --- a/app/controllers/public/profile_search_controller.rb +++ b/app/controllers/public/profile_search_controller.rb @@ -11,7 +11,8 @@ class ProfileSearchController < PublicController if params[:where] == 'environment' redirect_to :controller => 'search', :query => @q else - @results = Article.find_by_contents(@q, {}, {:filter_queries => ["profile_id:#{profile.id}", 'published:true']})[:results].paginate(:per_page => 10, :page => params[:page]) + @results = Article.find_by_contents(@q, {:per_page => 10, :page => params[:page]}, + {:filter_queries => ["profile_id:#{profile.id}", 'public:true']})[:results] end end end diff --git a/app/models/article.rb b/app/models/article.rb index 94016f7..17f0e9c 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -28,6 +28,9 @@ class Article < ActiveRecord::Base has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ] has_many :categories, :through => :article_categorizations + has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization' + has_many :categories_including_virtual, :through => :article_categorizations_including_virtual, :source => :category + acts_as_having_settings :field => :setting settings_items :display_hits, :type => :boolean, :default => true @@ -626,6 +629,9 @@ class Article < ActiveRecord::Base def public self.public? end + def category_filter + categories_including_virtual_ids + end public acts_as_faceted :fields => { @@ -634,8 +640,8 @@ class Article < ActiveRecord::Base '[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")}, :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]']}, :f_profile_type => {:label => _('Profile'), :proc => proc{|klass| f_profile_type_proc(klass)}}, - :f_category => {:label => _('Categories')}}, - :category_query => proc { |c| "f_category:\"#{c.name}\"" }, + :f_category => {:label => _('Categories')}, + }, :category_query => proc { |c| "category_filter:\"#{c.id}\"" }, :order => [:f_type, :f_published_at, :f_profile_type, :f_category] acts_as_searchable :fields => facets_fields_for_solr + [ @@ -645,7 +651,8 @@ class Article < ActiveRecord::Base {:abstract => :text}, {:filename => :text}, # filtered fields {:public => :boolean}, {:environment_id => :integer}, - :language, :published, + {:profile_id => :integer}, :language, + {:category_filter => :integer}, # ordered/query-boosted fields {:name_sortable => :string}, :last_changed_by_id, :published_at, :is_image, :updated_at, :created_at, diff --git a/app/models/product.rb b/app/models/product.rb index 6365b82..bb97209 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -245,18 +245,18 @@ class Product < ActiveRecord::Base self.public? end def price_sortable - (price.nil? or price.zero?) ? 999999999.9 : price + (price.nil? or price.zero?) ? nil : price end - def categories - enterprise.category_ids << product_category_id + def category_filter + enterprise.categories_including_virtual_ids << product_category_id end public acts_as_faceted :fields => { - :f_category => {:label => _('Related products')}, - :f_region => {:label => _('City'), :proc => proc { |id| f_region_proc(id) }}, - :f_qualifier => {:label => _('Qualifiers'), :proc => proc { |id| f_qualifier_proc(id) }}}, - :category_query => proc { |c| "categories:#{c.id}" }, + :f_category => {:label => _('Related products')}, + :f_region => {:label => _('City'), :proc => proc { |id| f_region_proc(id) }}, + :f_qualifier => {:label => _('Qualifiers'), :proc => proc { |id| f_qualifier_proc(id) }}, + }, :category_query => proc { |c| "category_filter:#{c.id}" }, :order => [:f_category, :f_region, :f_qualifier] Boosts = [ @@ -277,7 +277,7 @@ class Product < ActiveRecord::Base {:description => :text}, # filtered fields {:public => :boolean}, {:environment_id => :integer}, - {:categories => :integer}, + {:category_filter => :integer}, # ordered/query-boosted fields {:price_sortable => :decimal}, {:name_sortable => :string}, {:lat => :float}, {:lng => :float}, diff --git a/app/models/profile.rb b/app/models/profile.rb index 29bccfd..e4dcff6 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -179,6 +179,9 @@ class Profile < ActiveRecord::Base has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ] has_many :categories, :through => :profile_categorizations + has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' + has_many :categories_including_virtual, :through => :profile_categorizations_including_virtual, :source => :category + has_many :abuse_complaints, :foreign_key => 'requestor_id' def top_level_categorization @@ -839,6 +842,7 @@ private :generate_url, :url_options end def self.f_categories_proc(facet, id) id = id.to_i + return if id.zero? c = Category.find(id) c.name if c.top_ancestor.id == facet[:label_id].to_i or facet[:label_id] == 0 end @@ -846,7 +850,7 @@ private :generate_url, :url_options category_ids end def f_region - self.region.id if self.region + self.region_id end def self.f_region_proc(id) c = Region.find(id) @@ -864,14 +868,16 @@ private :generate_url, :url_options def public self.public? end + def category_filter + categories_including_virtual_ids + end public acts_as_faceted :fields => { - :f_region => {:label => _('City'), :type_if => proc { |klass| klass.kind_of?(Enterprise) }, - :proc => proc { |id| f_region_proc(id) }}, - :f_categories => {:multi => true, :proc => proc {|facet, id| f_categories_proc(facet, id)}, - :label => proc { |env| f_categories_label_proc(env) }, :label_abbrev => proc { |env| f_categories_label_abbrev_proc(env) }}}, - :category_query => proc { |c| "f_categories:#{c.id}" }, + :f_region => {:label => _('City'), :proc => proc { |id| f_region_proc(id) }}, + :f_categories => {:multi => true, :proc => proc {|facet, id| f_categories_proc(facet, id)}, + :label => proc { |env| f_categories_label_proc(env) }, :label_abbrev => proc{ |env| f_categories_label_abbrev_proc(env) }}, + }, :category_query => proc { |c| "category_filter:#{c.id}" }, :order => [:f_region, :f_categories] acts_as_searchable :fields => facets_fields_for_solr + [:extra_data_for_index, @@ -880,6 +886,7 @@ private :generate_url, :url_options {:identifier => :text}, {:address => :text}, {:nickname => :text}, # filtered fields {:public => :boolean}, {:environment_id => :integer}, + {:category_filter => :integer}, # ordered/query-boosted fields {:name_sortable => :string}, {:user_id => :integer}, :enabled, :active, :validated, :public_profile, diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml index 526bc10..d7ce59f 100644 --- a/app/views/search/_display_results.rhtml +++ b/app/views/search/_display_results.rhtml @@ -1,4 +1,4 @@ -
+
<% @order.each do |name| %> <% results = @results[name] %> <% empty = results.nil? || results.empty? %> diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 4911484..d79fd48 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -3821,8 +3821,6 @@ h1#agenda-title { -moz-border-radius:10px; -webkit-border-radius:10px; } -/* ==> public/stylesheets/controller_search.css <== */ -/* @import url(pagination.css); ALREADY INCLUDED ABOVE */ /* * * Profile search * * * * * * * */ @@ -3833,17 +3831,13 @@ h1#agenda-title { -moz-border-radius: 5px; -webkit-border-radius: 5px; } -#public-profile-search .formfield input { - width: 395px; -} -/* * * Profile Search Results * * * * * * * */ #profile-search-results ul { padding-left: 0px; margin-left: 0px; } #profile-search-results form .formfield input { - width: 395px; + width: 362px; } #profile-search-results form .search_form .button { margin-top: 5px; diff --git a/public/stylesheets/search.css b/public/stylesheets/search.css index 0fb027f..0e2ed8f 100644 --- a/public/stylesheets/search.css +++ b/public/stylesheets/search.css @@ -121,7 +121,7 @@ color: #FFF; text-decoration: none; } -.controller-search .search-results-innerbox.common-profile-list-block { +.controller-search .multiple-results-boxes .search-results-innerbox.common-profile-list-block { overflow: hidden; } .controller-search .search-results-innerbox { -- libgit2 0.21.2