diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 95dbb74..dd1e1aa 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -1,115 +1,80 @@ class SearchController < PublicController MAP_SEARCH_LIMIT = 2000 - SINGLE_SEARCH_LIMIT = 20 - MULTIPLE_SEARCH_LIMIT = 6 + LIST_SEARCH_LIMIT = 20 + BLOCKS_SEARCH_LIMIT = 18 + MULTIPLE_SEARCH_LIMIT = 8 helper TagsHelper include SearchHelper + include ActionView::Helpers::NumberHelper before_filter :load_category before_filter :load_search_assets + before_filter :load_query no_design_blocks - def articles - @asset = :articles - @query = params[:query] || '' - @order ||= [@asset] - @results ||= {} - @filter = filter + def facets_browse + @asset = params[:asset] + @asset_class = asset_class(@asset) - pg_options = paginate_options(@asset, limit, params[:per_page]) - if !@query.blank? - ret = asset_class(@asset).find_by_contents(@query, pg_options, solr_options(@asset, params[:facet], params[:order_by])) - @results[@asset] = ret[:results] - @facets = ret[:facets] - else - @results[@asset] = asset_class(@asset).send('paginate', :all, pg_options) - @facets = {} + @facets_only = true + send(@asset) + + @facet = @asset_class.map_facets_for(environment).find { |facet| facet[:id] == params[:facet_id] } + raise 'Facet not found' if @facet.nil? + + render :layout => false + end + + def articles + @filter = params[:filter] ? filter : nil + @filter_title = params[:filter] ? filter_description(@asset, @filter) : nil + if !@empty_query + full_text_search + elsif params[:filter] + @results[@asset] = @environment.articles.more_recent.paginate(paginate_options) end end - alias :contents :articles + def contents + redirect_to params.merge(:action => :articles) + end def people - @asset = :people - @query = params[:query] || '' - @order ||= [@asset] - @results ||= {} - @filter = filter - @title = self.filter_description(params[:action] + '_' + @filter ) - - @results[@asset] = @environment.people.visible.send(@filter) - if !@query.blank? - ret = @results[@asset].find_by_contents(@query, {}, solr_options(@asset, params[:facet], params[:order_by])) - @results[@asset] = ret[:results] - @facets = ret[:facets] + if !@empty_query + full_text_search else + @results[@asset] = @environment.people.visible.send(@filter).paginate(paginate_options) @facets = {} end - @results[@asset] = @results[@asset].compact.paginate(:per_page => limit, :page => params[:page]) end def products - @asset = :products - @query = params[:query] || '' - @order ||= [@asset] - @results ||= {} - - pg_options = paginate_options(@asset, limit, params[:per_page]) - if !@query.blank? - ret = asset_class(@asset).find_by_contents(@query, pg_options, solr_options(@asset, params[:facet], params[:order_by])) - @results[@asset] = ret[:results] - @facets = ret[:facets] - else - @results[@asset] = asset_class(@asset).send('paginate', :all, pg_options) - @facets = {} + if !@empty_query + full_text_search end end def enterprises - @asset = :enterprises - @query = params[:query] || '' - @order ||= [@asset] - @results ||= {} - - pg_options = paginate_options(@asset, limit, params[:per_page]) - if !@query.blank? - ret = asset_class(@asset).find_by_contents(@query, pg_options, solr_options(@asset, params[:facet], params[:order_by])) - @results[@asset] = ret[:results] - @facets = ret[:facets] + if !@empty_query + full_text_search else - @results[@asset] = asset_class(@asset).send('paginate', :all, pg_options) - @facets = {} + @filter_title = _('Enterprises from network') + @results[@asset] = asset_class(@asset).paginate(paginate_options) end end def communities - @asset = :communities - @query = params[:query] || '' - @order ||= [@asset] - @results ||= {} - @filter = filter - @title = self.filter_description(params[:action] + '_' + @filter ) - - @results[@asset] = @environment.communities.visible.send(@filter) - if !@query.blank? - ret = @results[@asset].find_by_contents(@query, {}, solr_options(@asset, params[:facet], params[:order_by])) - @results[@asset] = ret[:results] - @facets = ret[:facets] + if !@empty_query + full_text_search else - @facets = {} + @results[@asset] = @environment.communities.visible.send(@filter).paginate(paginate_options) end - @results[@asset] = @results[@asset].compact.paginate(:per_page => limit, :page => params[:page]) end def events - @asset = :events - params[:asset] |= [@asset] - @query = params[:query] || '' - @order ||= [@asset] - @results ||= {} @category_id = @category ? @category.id : nil if params[:year] || params[:month] @@ -129,9 +94,7 @@ class SearchController < PublicController @results[@asset] = Event.send('find', :all) end else - pg_options = paginate_options(@asset, limit, params[:per_page]) - solr_options = solr_options(@asset, params[:facet], params[:per_page]) - @results[@asset] = Event.find_by_contents(@query, pg_options, solr_options)[:results] + full_text_search end @selected_day = nil @@ -157,6 +120,7 @@ class SearchController < PublicController @results = {} @order = [] @names = {} + @results_only = true @enabled_searchs.select { |key,description| @searching[key] }.each do |key, description| send(key) @@ -186,19 +150,17 @@ class SearchController < PublicController @names = {} limit = MULTIPLE_SEARCH_LIMIT [ - [ :people, _('People'), recent('people', limit) ], - [ :enterprises, __('Enterprises'), recent('enterprises', limit) ], - [ :products, _('Products'), recent('products', limit) ], - [ :events, _('Upcoming events'), upcoming_events({:per_page => limit}) ], - [ :communities, __('Communities'), recent('communities', limit) ], - [ :most_commented_articles, _('Most commented articles'), most_commented_articles(limit) ], - [ :articles, _('Articles'), recent('text_articles', limit) ] - ].each do |key, name, list| - @order << key - @results[key] = list - @names[key] = name + [ :people, _('People'), :recent_people ], + [ :enterprises, _('Enterprises'), :recent_enterprises ], + [ :products, _('Products'), :recent_products ], + [ :events, _('Upcoming events'), :upcoming_events ], + [ :communities, _('Communities'), :recent_communities ], + [ :articles, _('Contents'), :recent_articles ] + ].each do |asset, name, filter| + @order << asset + @results[asset] = @category.send(filter, limit) + @names[asset] = name end - @facets = {} end def tags @@ -218,50 +180,33 @@ class SearchController < PublicController def events_by_day @selected_day = build_date(params[:year], params[:month], params[:day]) - if params[:category_id] and Category.exists?(params[:category_id]) - @events_of_the_day = environment.events.by_day(@selected_day).in_category(Category.find(params[:category_id])) - else - @events_of_the_day = environment.events.by_day(@selected_day) - end + @events_of_the_day = environment.events.by_day(@selected_day) render :partial => 'events/events_by_day' end ####################################################### protected - def recent(asset, limit = nil) - options = {:page => 1, :per_page => limit, :order => 'created_at DESC, id DESC'} - - if asset == :events - finder_method = 'find' - options.delete(:page) - options.delete(:per_page) - else - finder_method = 'paginate' - end - - asset_class(asset).send(finder_method, :all, category_options_for_find(asset_class(asset), {:order => "#{asset_table(asset)}.name"}.merge(options))) - end - - def most_commented_articles(limit=10, options={}) - options = {:page => 1, :per_page => limit, :order => 'comments_count DESC'}.merge(options) - Article.paginate(:all, category_options_for_find(Article, options)) - end - - def upcoming_events(options = {}) - options.delete(:page) - options.delete(:per_page) + def load_query + @asset = params[:action].to_sym + @order ||= [@asset] + @results ||= {} + @filter = filter + @filter_title = filter_description(@asset, @filter) - Event.find(:all, {:include => :categories, :conditions => [ 'categories.id = ? and start_date >= ?', category_id, Date.today ], :order => 'start_date' }.merge(options)) + @query = params[:query] || '' + @empty_query = @category.nil? && @query.blank? end - def current_events(year, month, options={}) - options.delete(:page) - options.delete(:per_page) - - range = Event.date_range(year, month) - - Event.find(:all, {:include => :categories, :conditions => { 'categories.id' => category_id, :start_date => range }}.merge(options)) + def load_category + unless params[:category_path].blank? + path = params[:category_path].join('/') + @category = environment.categories.find_by_path(path) + if @category.nil? + render_not_found(path) + end + @category_id = @category.id + end end FILTERS = %w( @@ -277,112 +222,83 @@ class SearchController < PublicController end end - def filter_description(str) + def filter_description(asset, filter) { - 'contents_more_recent' => _('More recent contents'), - 'contents_more_popular' => _('More popular contents'), - 'people_more_recent' => _('More recent people'), - 'people_more_active' => _('More active people'), - 'people_more_popular' => _('More popular people'), - 'communities_more_recent' => _('More recent communities'), - 'communities_more_active' => _('More active communities'), - 'communities_more_popular' => _('More popular communities'), - }[str] || str - end - - attr_reader :category - attr_reader :category_id - - def load_category - unless params[:category_path].blank? - path = params[:category_path].join('/') - @category = environment.categories.find_by_path(path) - if @category.nil? - render_not_found(path) - end - @category_id = @category.id - end + 'articles_more_recent' => _('More recent contents from network'), + 'articles_more_popular' => _('More popular contents from network'), + 'people_more_recent' => _('More recent people from network'), + 'people_more_active' => _('More active people from network'), + 'people_more_popular' => _('More popular people from network'), + 'communities_more_recent' => _('More recent communities from network'), + 'communities_more_active' => _('More active communities from network'), + 'communities_more_popular' => _('More popular communities from network'), + }[asset.to_s + '_' + filter] end def load_search_assets @enabled_searchs = [ - [ :articles, N_('Articles') ], - [ :enterprises, N_('Enterprises') ], - [ :people, N_('People') ], - [ :communities, N_('Communities') ], - [ :products, N_('Products') ], - [ :events, N_('Events') ] + [ :articles, _('Contents') ], + [ :enterprises, _('Enterprises') ], + [ :people, _('People') ], + [ :communities, _('Communities') ], + [ :products, _('Products and Services') ], + [ :events, _('Events') ] ].select {|key, name| !environment.enabled?('disable_asset_' + key.to_s) } @searching = {} + @titles = {} @enabled_searchs.each do |key, name| + @titles[key] = name @searching[key] = params[:action] == 'index' || params[:action] == key.to_s end end - def paginate_options(asset, limit, page) - result = { :per_page => limit, :page => page } - end - - def solr_options(asset, facet, solr_order) - result = {} - - if asset_class(asset).methods.include?('facets') - result.merge!(:facets => {:zeros => false, :sort => :count, :fields => asset_class(asset).facets.keys, - :browse => facet ? facet.map{ |k,v| k.to_s+':"'+v.to_s+'"'} : ''}) - end - - if solr_order - result[:order_by] = solr_order - end - - result - end - def limit - searching = @searching.values.select{|v|v} + searching = @searching.values.select{ |v| v } if params[:display] == 'map' MAP_SEARCH_LIMIT + elsif searching.size <= 1 + if [:people, :communities].include? @asset + BLOCKS_SEARCH_LIMIT + elsif @asset == :enterprises and @empty_query + BLOCKS_SEARCH_LIMIT + else + LIST_SEARCH_LIMIT + end else - (searching.size <= 1) ? SINGLE_SEARCH_LIMIT : MULTIPLE_SEARCH_LIMIT + MULTIPLE_SEARCH_LIMIT end end - def category_options_for_find(klass, options={}, date_range = nil) - if defined? options[:product_category] - prod_cat = options.delete(:product_category) - end - - case klass.name - when 'Comment' - {:joins => 'inner join articles_categories on articles_categories.article_id = comments.article_id', :conditions => ['articles_categories.category_id = (?)', category_id]}.merge!(options) - when 'Product' - if prod_cat - {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id inner join product_categorizations on (product_categorizations.product_id = products.id)', :conditions => ['categories_profiles.category_id = (?) and product_categorizations.category_id = (?)', category_id, prod_cat.id]}.merge!(options) - else - {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options) - end - when 'Article', 'TextArticle' - {:joins => 'inner join articles_categories on (articles_categories.article_id = articles.id)', :conditions => ['articles_categories.category_id = (?)', category_id]}.merge!(options) - when 'Event' - conditions = - if date_range - ['articles_categories.category_id = (:category_id) and (start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day)', {:category_id => category_id, :start_day => date_range.first, :end_day => date_range.last} ] - else - ['articles_categories.category_id = (?) ', category_id ] - end - {:joins => 'inner join articles_categories on (articles_categories.article_id = articles.id)', :conditions => conditions}.merge!(options) - when 'Enterprise' - if prod_cat - {:joins => 'inner join categories_profiles on (categories_profiles.profile_id = profiles.id) inner join products on (products.enterprise_id = profiles.id) inner join product_categorizations on (product_categorizations.product_id = products.id)', :conditions => ['categories_profiles.category_id = (?) and product_categorizations.category_id = (?)', category_id, prod_cat.id]}.merge!(options) - else - {:joins => 'inner join categories_profiles on (categories_profiles.profile_id = profiles.id)', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options) - end - when 'Person', 'Community' - {:joins => 'inner join categories_profiles on (categories_profiles.profile_id = profiles.id)', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options) - else - raise "unreconized class #{klass.name}" + def paginate_options(page = params[:page]) + { :per_page => limit, :page => page } + end + + def full_text_search(paginate_options = nil) + paginate_options ||= paginate_options(params[:page]) + solr_options = solr_options(@asset, params[:facet], params[:order_by]) + + ret = asset_class(@asset).find_by_contents(@query, paginate_options, solr_options) + @results[@asset] = ret[:results] + @facets = ret[:facets] + @all_facets = ret[:all_facets] + end + + def solr_options(asset, facets_selected, solr_order = nil) + result = {} + + asset_class = asset_class(asset) + if !@results_only and asset_class.methods.include?('facets') + result.merge! asset_class.facets_find_options(facets_selected) + result[:all_facets] = true + result[:limit] = 0 if @facets_only + result[:facets][:browse] << asset_class.facet_category_query.call(@category) if @category + puts result[:facets][:browse] end + + result[:order] = solr_order if solr_order + + result end def asset_class(asset) diff --git a/app/helpers/display_helper.rb b/app/helpers/display_helper.rb index 13b3742..5450781 100644 --- a/app/helpers/display_helper.rb +++ b/app/helpers/display_helper.rb @@ -8,14 +8,24 @@ module DisplayHelper opts end + def price_span(price, options = {}) + content_tag 'span', + number_to_currency(price, :unit => environment.currency_unit, :delimiter => environment.currency_delimiter, :separator => environment.currency_separator), + options + end + def product_path(product) product.enterprise.enabled? ? product.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => product) : product.enterprise.url end - def link_to_category(category, full = true) + def link_to_tag(tag, html_options = {}) + link_to tag.name, {:controller => 'search', :action => 'tag', :tag => tag.name}, html_options + end + + def link_to_category(category, full = true, html_options = {}) return _('Uncategorized product') unless category name = full ? category.full_name(' → ') : category.name - link_to name, Noosfero.url_options.merge({:controller => 'search', :action => 'category_index', :category_path => category.path.split('/'),:host => category.environment.default_hostname }) + link_to name, Noosfero.url_options.merge({:controller => 'search', :action => 'category_index', :category_path => category.path.split('/'),:host => category.environment.default_hostname }), html_options end def link_to_product_category(category) diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 72e2230..c58218c 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -9,54 +9,31 @@ module SearchHelper (n * 100.0).round end - def display_results(use_map = true) - - unless use_map && GoogleMaps.enabled?(environment.default_hostname) - return render(:partial => 'display_results') + def display_results(use_map = false) + if params[:display] == 'map' && use_map && GoogleMaps.enabled?(environment.default_hostname) + partial = 'google_maps' + klass = 'map' + else + partial = 'display_results' + klass = 'list' end - data = - if params[:display] == 'map' - { - :partial => 'google_maps', - :toggle => button(:search, _('Display in list'), params.merge(:display => 'list'), :class => "map-toggle-button" ), - :class => 'map' , - } - else - { - :partial => 'display_results', - :toggle => button(:search, _('Display in map'), params.merge(:display => 'map'), :class => "map-toggle-button" ), - :class => 'list' , - } - end - - content_tag('div', data[:toggle] + (render :partial => data[:partial]), :class => "map-or-list-search-results #{data[:class]}") + content_tag('div', render(:partial => partial), :class => "map-or-list-search-results #{klass}") end - def product_categories_menu(asset, product_category, object_ids = nil) - cats = ProductCategory.menu_categories(@product_category, environment) - cats += cats.select { |c| c.children_count > 0 }.map(&:children).flatten - product_categories_ids = cats.map(&:id) - - counts = @noosfero_finder.product_categories_count(asset, product_categories_ids, object_ids) - - product_categories_menu = ProductCategory.menu_categories(product_category, environment).map do |cat| - hits = counts[cat.id] - childs = [] - if hits - if cat.children_count > 0 - childs = cat.children.map do |child| - child_hits = counts[child.id] - [child, child_hits] - end.select{|child, child_hits| child_hits } - else - childs = [] - end - end - [cat, hits, childs] - end.select{|cat, hits| hits } + def display_map_list_button + button(:search, params[:display] == 'map' ? _('Display in list') : _('Display in map'), + params.merge(:display => (params[:display] == 'map' ? 'list' : 'map')), + :class => "map-toggle-button" ) + end - render(:partial => 'product_categories_menu', :object => product_categories_menu) + def city_with_state(city) + s = city.parent + if city and city.kind_of?(City) and s and s.kind_of?(State) and s.acronym + city.name + ', ' + s.acronym + else + city.name + end end def facets_menu(asset, _facets) @@ -148,15 +125,15 @@ module SearchHelper def order_by(asset) options = { - :products => [[_('Best match'), ''], [_('Name'), 'name_sort asc'], [_('Lower price'), 'price asc'], [_('Higher price'), 'price desc']], - :events => [[_('Best match'), ''], [_('Name'), 'name_sort asc']], - :articles => [[_('Best match'), ''], [_('Name'), 'name_sort asc'], [_('Most recent'), 'updated_at desc']], - :enterprises => [[_('Best match'), ''], [_('Name'), 'name_sort asc']], - :people => [[_('Best match'), ''], [_('Name'), 'name_sort asc']], - :communities => [[_('Best match'), ''], [_('Name'), 'name_sort asc']], + :products => [[_('Relevance'), ''], [_('Name'), 'name_or_category_sort asc'], [_('Lower price'), 'price_sort asc'], [_('Higher price'), 'price_sort desc']], + :events => [[_('Relevance'), ''], [_('Name'), 'name_sort asc']], + :articles => [[_('Relevance'), ''], [_('Name'), 'name_sort asc'], [_('Most recent'), 'updated_at desc']], + :enterprises => [[_('Relevance'), ''], [_('Name'), 'name_sort asc']], + :people => [[_('Relevance'), ''], [_('Name'), 'name_sort asc']], + :communities => [[_('Relevance'), ''], [_('Name'), 'name_sort asc']], } - content_tag('div', _('Order by ') + + content_tag('div', _('Sort results by ') + select_tag(asset.to_s + '[order]', options_for_select(options[asset], params[:order_by]), {:onchange => "window.location=jQuery.param.querystring(window.location.href, { 'order_by' : this.options[this.selectedIndex].value})"}), :class => "search-ordering") @@ -178,4 +155,5 @@ module SearchHelper '' end end + end diff --git a/app/models/article.rb b/app/models/article.rb index 563e594..21d1246 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -139,11 +139,18 @@ class Article < ActiveRecord::Base {:conditions => [ 'parent_id is null and profile_id = ?', profile.id ]} } + named_scope :more_recent, + :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND + ((articles.type != ?) OR articles.type is NULL)", + true, true, true, true, 'RssFeed' + ], + :order => 'articles.published_at desc, articles.id desc' + # retrieves the latest +limit+ articles, sorted from the most recent to the # oldest. # # Only includes articles where advertise == true - def self.recent(limit, extra_conditions = {}) + def self.recent(limit = nil, extra_conditions = {}) # FIXME this method is a horrible hack options = { :limit => limit, :conditions => [ @@ -558,17 +565,53 @@ class Article < ActiveRecord::Base end private + + def self.f_type_proc(klass) + klass.constantize + h = { + 'UploadedFile' => _("Uploaded File"), + 'TextArticle' => _("Text"), + 'Folder' => _("Folder"), + 'Event' => _("Event"), + 'EnterpriseHomepage' => ("Homepage"), + 'Gallery' => ("Gallery"), + 'Blog' => ("Blog"), + 'Forum' => ("Forum") + } + h[klass] + end + def self.f_profile_type_proc(klass) + h = { + 'Enterprise' => _("Enterprise"), + 'Community' => _("Community"), + 'Person' => ("Person"), + 'BscPlugin::Bsc' => ("BSC") + } + h[klass] + end + + UploadedFile + TextArticle + TinyMceArticle + TextileArticle + Folder + EnterpriseHomepage + Gallery + Blog + Forum + Event + #excludes RssFeed + def f_type - self.class.short_description + case self.class.to_s + when 'TinyMceArticle', 'TextileArticle' + 'TextArticle' + else + self.class.to_s + end end - def f_publish_date - today = Date.today - range = '' - range = _('Last year') if (today-1.year..today).include?(self.published_at) - range = _('Last month') if (today-1.month..today).include?(self.published_at) - range = _('Last week') if (today-1.week..today).include?(self.published_at) - range = _('Last day') if (today-1.day..today).include?(self.published_at) - range + def f_published_at + self.published_at end def f_profile_type self.profile.class.to_s @@ -579,16 +622,21 @@ class Article < ActiveRecord::Base public acts_as_faceted :fields => { - :f_type => {:label => _('Type')}, - :f_publish_date => {:label => _('Published')}, - :f_profile_type => {:label => _('Type of profile')}, - :f_category => {:label => _('Categories')}}, - :order => [:f_type, :f_publish_date, :f_profile_type, :f_category] - - acts_as_searchable :additional_fields => [ :comment_data, {:name => {:type => :string, :as => :name_sort, :boost => 5.0}} ] + facets.keys.map{|i| {i => :facet}}, + :f_type => {:label => _('Type'), :proc => proc{|klass| f_type_proc(klass)}}, + :f_published_at => {:type => :date, :label => _('Published date'), :queries => {'[* TO NOW-1YEARS/DAY]' => _("Older than one year"), + '[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}\"" }, + :order => [:f_type, :f_published_at, :f_profile_type, :f_category] + + acts_as_searchable :additional_fields => [ {:name => {:type => :string, :as => :name_sort, :boost => 5.0}} ] + facets_fields_for_solr, + :exclude_fields => [:setting], :include => [:profile], - :facets => facets.keys, - :if => proc{|a| ! ['Feed'].include?(a.type)} + :facets => facets_option_for_solr, + :boost => proc {|a| 10 if a.profile.enabled}, + :if => proc{|a| ! ['RssFeed'].include?(a.class.name)} private diff --git a/app/models/category.rb b/app/models/category.rb index 02297c8..e1a37b3 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -36,18 +36,38 @@ class Category < ActiveRecord::Base { :conditions => [ "type IN (?) OR type IS NULL", types.reject{ |t| t.blank? } ] } } + def recent_people(limit = 10) + self.people.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit) + end + + def recent_enterprises(limit = 10) + self.enterprises.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit) + end + + def recent_communities(limit = 10) + self.communities.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit) + end + + def recent_products(limit = 10) + self.products.paginate(:order => 'created_at DESC, id DESC', :page => 1, :per_page => limit) + end + def recent_articles(limit = 10) self.articles.recent(limit) end def recent_comments(limit = 10) - comments.find(:all, :order => 'created_at DESC, comments.id DESC', :limit => limit) + comments.paginate(:all, :order => 'created_at DESC, comments.id DESC', :page => 1, :per_page => limit) end def most_commented_articles(limit = 10) self.articles.most_commented(limit) end + def upcoming_events(limit = 10) + self.events.find(:all, :conditions => [ 'start_date >= ?', Date.today ], :order => 'start_date') + end + def display_in_menu? display_in_menu end @@ -64,10 +84,6 @@ class Category < ActiveRecord::Base results end - def root_parent - parent_id.nil? ? self : Category.find_by_id(parent_id).root_parent - end - def is_leaf_displayable_in_menu? return false if self.display_in_menu == false self.children.find(:all, :conditions => {:display_in_menu => true}).empty? diff --git a/app/models/environment.rb b/app/models/environment.rb index a2e36a4..87955a6 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -247,8 +247,9 @@ class Environment < ActiveRecord::Base settings_items :enabled_plugins, :type => Array, :default => [] - settings_items :search_products_hint, :type => String, :default => '' - settings_items :search_contents_hint, :type => String, :default => '' + settings_items :search_hints, :type => Hash, :default => {} + + settings_items :top_level_category_as_facet_ids, :type => Array, :default => [] def news_amount_by_folder=(amount) settings[:news_amount_by_folder] = amount.to_i diff --git a/app/views/layouts/application-ng.rhtml b/app/views/layouts/application-ng.rhtml index 4486076..01f0ac5 100644 --- a/app/views/layouts/application-ng.rhtml +++ b/app/views/layouts/application-ng.rhtml @@ -66,7 +66,7 @@
diff --git a/app/views/search/_article.rhtml b/app/views/search/_article.rhtml index 1878f3b..2304bab 100644 --- a/app/views/search/_article.rhtml +++ b/app/views/search/_article.rhtml @@ -1,21 +1,10 @@ -