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 @@
- +
<%=_('Press Enter to send the search query.')%>
<%= javascript_tag 'jQuery("#user form input").hint();' %>
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 @@ -
  • - <%= link_to(article.title, article.url) %> -
    - <% if article.body %> - <% body_stripped = strip_tags(article.body.to_s) %> -
    <%= excerpt(body_stripped, body_stripped.first(3), 200) %>
    - <% end %> - -
    <%= _('Tags: ') + article.tags.join(', ') if !article.tags.empty? %> - -
    <%=_('Author: ') %><%= link_to(article.profile.name, profile_path(:profile => article.profile)) %> - -
    - <% if article.last_changed_by %> - <%= _('by %s') % link_to(article.last_changed_by.name, article.last_changed_by.url) %> - <% end %> - <%= _('Last update: %s.') % show_date(article.updated_at) %> +
  • + <%= link_to(article.title, article.url, :class => "search-result-title") %> +
    + <%= render :partial => 'image', :object => article %> +
    +
    -
    +
  • diff --git a/app/views/search/_article_author.rhtml b/app/views/search/_article_author.rhtml new file mode 100644 index 0000000..41ab926 --- /dev/null +++ b/app/views/search/_article_author.rhtml @@ -0,0 +1,8 @@ +<% article = article_author %> + +
    +
    + <%= _("Author") %> + <%= link_to_profile article.profile.name, article.profile.identifier %> +
    +
    diff --git a/app/views/search/_article_categories.rhtml b/app/views/search/_article_categories.rhtml new file mode 100644 index 0000000..4a0a940 --- /dev/null +++ b/app/views/search/_article_categories.rhtml @@ -0,0 +1,9 @@ +
    + <%= _('Categories') %> + + <% article_categories.each do |category| %> + <%= link_to_category category, false, :class => "search-article-category" %> + <% end %> + <%= _('None') if article_categories.empty? %> + +
    diff --git a/app/views/search/_article_common.rhtml b/app/views/search/_article_common.rhtml new file mode 100644 index 0000000..8e36d43 --- /dev/null +++ b/app/views/search/_article_common.rhtml @@ -0,0 +1,7 @@ +<% article = article_common %> + +<%= render :partial => 'article_author', :object => article %> +<%= render :partial => 'article_description', :object => article %> +<%= render :partial => 'article_tags', :object => article.tags %> +<%= render :partial => 'article_categories', :object => article.categories %> +<%= render :partial => 'article_last_change', :object => article %> diff --git a/app/views/search/_article_description.rhtml b/app/views/search/_article_description.rhtml new file mode 100644 index 0000000..dca7cbd --- /dev/null +++ b/app/views/search/_article_description.rhtml @@ -0,0 +1,11 @@ +<% article = article_description %> + +
    + <%= _("Description") %> + <% if !article.body.blank? %> + <% body_stripped = strip_tags(article.body.to_s) %> + <%= excerpt(body_stripped, body_stripped.first(3), 200) %> + <% else %> + <%= _('None') %> + <% end %> +
    diff --git a/app/views/search/_article_last_change.rhtml b/app/views/search/_article_last_change.rhtml new file mode 100644 index 0000000..f504551 --- /dev/null +++ b/app/views/search/_article_last_change.rhtml @@ -0,0 +1,9 @@ +<% article = article_last_change %> + +
    + <% if article.last_changed_by && article.last_changed_by != article.profile %> + <%= _('by %s') % link_to(article.last_changed_by.name, article.last_changed_by.url) %> <%= _(' at %s.') % show_date(article.updated_at) %> + <% else %> + <%= _('Last update: %s.') % show_date(article.updated_at) %> + <% end %> +
    diff --git a/app/views/search/_article_tags.rhtml b/app/views/search/_article_tags.rhtml new file mode 100644 index 0000000..057703a --- /dev/null +++ b/app/views/search/_article_tags.rhtml @@ -0,0 +1,9 @@ +
    + <%= _('Tags') %> + + <% article_tags.each do |tag| %> + <%= link_to_tag tag, :class => "search-article-tag" %> + <% end %> + <%= _('None') if article_tags.empty? %> + +
    diff --git a/app/views/search/_blog.rhtml b/app/views/search/_blog.rhtml new file mode 100644 index 0000000..a3dee5a --- /dev/null +++ b/app/views/search/_blog.rhtml @@ -0,0 +1,23 @@ +
  • + <%= link_to blog.title, blog.view_url, :class => 'search-result-title' %> +
    + <%= render :partial => 'image', :object => blog %> +
    +
    +
    + <%= _("Last posts") %> + <% r = blog.children.find(:all, :order => :updated_at, :conditions => ['type != ?', 'RssFeed']).last(3) %> + <% r.each do |a| %> + <%= link_to a.title, a.view_url, :class => 'search-blog-sample-item '+icon_for_article(a) %> + <% end %> + <%= _('None') if r.empty? %> +
    + + <%= render :partial => 'article_author', :object => blog %> + <%= render :partial => 'article_tags', :object => blog.tags %> + <%= render :partial => 'article_categories', :object => blog.categories %> + <%= render :partial => 'article_last_change', :object => blog %> +
    + +
    +
  • diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml index a8301ad..a4e0722 100644 --- a/app/views/search/_display_results.rhtml +++ b/app/views/search/_display_results.rhtml @@ -4,45 +4,31 @@ <% results = @results[name] %> <% if !results.nil? and !results.empty? %>
    - <% if @controller.action_name != 'assets' %> - <% if @results.size != 1 %> -

    - <%= @names[name] %> -

    - <% end %> - <%# FIXME: don't hardcode an asset like this %> - <% if name == :most_commented_articles %> - <%= link_to( results.respond_to?(:total_entries) ? _('see all (%d)') % results.total_entries : _('see all...'), - params.merge(:action => 'index', - :asset => 'articles' ), - :class => 'see-more' ) if @results.size > 1 %> - <% else %> - <%= link_to( results.respond_to?(:total_entries) ? _('see all (%d)') % results.total_entries : _('see all...'), - params.merge(:action => 'index', - :asset => name ), - :class => 'see-more' ) if @results.size > 1 %> - <% end %> + <% if @results.size > 1 %> +

    <%= @names[name] %>

    + <%= link_to(results.respond_to?(:total_entries) ? _('see all (%d)') % results.total_entries : _('see all...'), + params.merge(:action => name), :class => 'see-more' ) %> <% end %> - <% partial = partial_for_class results.first.class %> + + <% partial = partial_for_class(results.first.class.class_name.constantize) %>
      - <% results.each do |hit| %> - <% next if hit.respond_to?(:visible) && !hit.visible? %> - <%= render :partial => partial_for_class(hit.class), :object => hit %> - <% end %> + <% results.each do |hit| %> + <% next if hit.respond_to?(:visible) && !hit.visible? %> + <%= render :partial => partial_for_class(hit.class), :object => hit %> + <% end %>

    +
    <% else %>
    - <% if @controller.action_name != 'assets' %> - <% if @results.size != 1 %> -

    <%= @names[name] %>

    - <% end %> + <% if @results.size > 1 %> +

    <%= @names[name] %>

    <% end %>
    <%= _('None') %>
    @@ -52,6 +38,6 @@ <% end %> <% end %> -
    +
    diff --git a/app/views/search/_enterprise_homepage.rhtml b/app/views/search/_enterprise_homepage.rhtml new file mode 100644 index 0000000..3944a20 --- /dev/null +++ b/app/views/search/_enterprise_homepage.rhtml @@ -0,0 +1 @@ +<%= render :partial => 'text_article', :object => enterprise_homepage %> diff --git a/app/views/search/_event.rhtml b/app/views/search/_event.rhtml index ea7aea2..d40e7fb 100644 --- a/app/views/search/_event.rhtml +++ b/app/views/search/_event.rhtml @@ -1,6 +1,29 @@ -
  • - <%= link_to(event.title, event.url) %> -
    - <%= show_period(event.start_date, event.end_date) %> +
  • + <%= link_to(event.title, event.url, :class => "search-result-title") %> +
    + <%= render :partial => 'image', :object => event %>
    +
    + <% if event.body %> + <% body_stripped = strip_tags(event.body.to_s) %> +
    + <%= excerpt(body_stripped, body_stripped.first(3), 200) %> +
    + <% end %> + <% if event.start_date %> +
    + <%= _('Start date') %> + <%= event.start_date %> +
    + <% end %> + <% if event.end_date %> +
    + <%= _('End date') %> + <%= event.end_date %> +
    + <% end %> + + <%= render :partial => 'article_common', :object => event %> +
    +
  • diff --git a/app/views/search/_facets_menu.rhtml b/app/views/search/_facets_menu.rhtml index 467e057..472a105 100644 --- a/app/views/search/_facets_menu.rhtml +++ b/app/views/search/_facets_menu.rhtml @@ -1,51 +1,36 @@ -<% more_options = _("+ Options") %> -<% less_options = _("- Options") %> -<% less_options_limit = 7 %> +<% less_options_limit = 8 %>
    - <% if !@facets["facet_fields"].empty? %> - <% @asset_class.each_facet do |facet_id, index| %> - <% facet = @asset_class.facets[facet_id] %> - <% solr_facet = @asset_class.to_solr_facet_fields[facet_id] %> - <% facets_all = @facets["facet_fields"][solr_facet] %> - <% facets_found = params[:facet] ? facets_all.reject {|name, count| params[:facet][facet_id.to_s].to_s == name.to_s } : facets_all %> + <% @asset_class.map_facets_for(environment).each do |facet| %> - <% if facets_found and facets_found.count > 0 %> -
    -
    - <%= facet[:label] %> -

    +
    +
    + <%= facet[:label] %> +
    - <% if facets_found.count > less_options_limit %> - - <% end %> - -
    - <% c = 0; @asset_class.each_facet_name(solr_facet, facets_found, :sort => :count) do |name, count| %> - <%= link_to(name, params.merge({"facet[#{facet_id.to_s}]" => name})) + " (#{count})" %>
    - <% break if (c += 1) > less_options_limit %> - <% end %> -

    + <% if facet_count > 0 %> + - <% if facets_found.count > less_options_limit %> - <%= link_to_function more_options, "jQuery('#facet-menu-"+index.to_s+" .facet-menu-options').toggle(200); " + - "jQuery(this).text(jQuery(this).text() == '"+less_options+"' ? '"+more_options+"' : '"+less_options+"');" %> -
    +
    + <% results.each do |id, label, count| %> + <%= facet_link_html(facet, params, id, label, count) %>
    <% end %> +

    + <% if facet_count > less_options_limit %> + <%= link_to_function _("Options"), + "facet_options_toggle('#{facet[:id].to_s}', '#{url_for(params.merge(:action => 'facets_browse', :facet_id => facet[:id], :asset => @asset, :escape => false))}'); " + + "jQuery(this).toggleClass('facet-less-options')", :class => "facet-options-toggle" %>
    -
    <% end %> + + <% else %> + <%= _("No filter available") %> <% end %> - <% end %> -
    +
    + <% end %> +
    diff --git a/app/views/search/_facets_unselect_menu.rhtml b/app/views/search/_facets_unselect_menu.rhtml index ad6057c..db1393b 100644 --- a/app/views/search/_facets_unselect_menu.rhtml +++ b/app/views/search/_facets_unselect_menu.rhtml @@ -1,9 +1,6 @@ -
    <% if params[:facet] and params[:facet].count > 0 %> - <%= _("Applied filters") %> - <% params[:facet].each do |facet_id, name| %> - <%= link_to(name, params.merge(:facet => params[:facet].reject {|k,v| k == facet_id}), :class => 'facet-selected') %> - <% end %> + <%= _("Applied filters") %> + <%= facet_selecteds_html_for(environment, asset_class(@asset), params) %> <% end %>
    diff --git a/app/views/search/_folder.rhtml b/app/views/search/_folder.rhtml new file mode 100644 index 0000000..e35e72c --- /dev/null +++ b/app/views/search/_folder.rhtml @@ -0,0 +1,19 @@ +
  • + <%= link_to folder.title, folder.view_url, :class => 'search-result-title' %> +
    + <%= render :partial => 'image', :object => folder %> +
    +
    +
    + <%= _("Last items") %> + <% r = folder.children.last(3) %> + <% r.each do |a| %> + <%= link_to a.title, a.view_url, :class => 'search-folder-sample-item '+icon_for_article(a) %> + <% end %> + <%= _('None') if r.empty? %> +
    + + <%= render :partial => 'article_common', :object => folder %> +
    +
    +
  • diff --git a/app/views/search/_forum.rhtml b/app/views/search/_forum.rhtml new file mode 100644 index 0000000..1ce7b6d --- /dev/null +++ b/app/views/search/_forum.rhtml @@ -0,0 +1,20 @@ +
  • + <%= link_to forum.title, forum.view_url, :class => 'search-result-title' %> +
    + <%= render :partial => 'image', :object => forum %> +
    +
    +
    + <%= _("Last topics") %> + <% r = forum.children.find(:all, :order => :updated_at, :conditions => ['type != ?', 'RssFeed']).last(3) %> + <% r.each do |a| %> + <%= link_to a.title, a.view_url, :class => 'search-forum-sample-item '+icon_for_article(a) %> + <% end %> + <%= _('None') if r.empty? %> +
    + + <%= render :partial => 'article_common', :object => forum %> +
    + +
    +
  • diff --git a/app/views/search/_gallery.rhtml b/app/views/search/_gallery.rhtml new file mode 100644 index 0000000..e036ccb --- /dev/null +++ b/app/views/search/_gallery.rhtml @@ -0,0 +1,10 @@ +
  • + <%= link_to gallery.title, gallery.view_url, :class => 'search-result-title' %> +
    + <%= render :partial => 'image', :object => gallery %> +
    +
    + <%= render :partial => 'article_common', :object => gallery %> +
    +
    +
  • diff --git a/app/views/search/_image.rhtml b/app/views/search/_image.rhtml new file mode 100644 index 0000000..4fb2ddb --- /dev/null +++ b/app/views/search/_image.rhtml @@ -0,0 +1,47 @@ +
    + + <% if image.is_a? UploadedFile %> + <% extension = image.filename[(image.filename.rindex('.')+1)..-1].downcase %> + <% if ['jpg', 'jpeg', 'gif', 'png', 'tiff', 'svg'].include? extension %> + <%= link_to '', image.view_url, :class => "search-image-pic", :style => 'background-image: url(%s)'% image.public_filename(:thumb) %> + <% if image.width && image.height %> + <% javascript_tag do %> + image = jQuery('script').last().parent().find('.search-image-pic'); + des_width = parseInt(image.css('width')); + des_height = parseInt(image.css('height')); + + width = <%= image.width %>; + height = <%= image.height %>; + scale_factor = width > height ? des_width/width : des_height/height; + + image.css({'width' : scale_factor*width +'px', 'height' : scale_factor*height+'px'}); + <% end %> + <% end %> + <% elsif ['pdf'].include? extension %> + <%= link_to '', image.view_url, :class => 'search-image-pic icon-application-pdf' %> + <% elsif ['doc', 'docx', 'odt', 'rtf', 'txt', 'html', 'htm'].include? extension %> + <%= link_to '', image.view_url, :class => 'search-image-pic icon-application-vnd-oasis-opendocument-text' %> + <% elsif ['xls', 'xlsx', 'ods', 'csv', 'tsv', 'tab'].include? extension %> + <%= link_to '', image.view_url, :class => 'search-image-pic icon-application-vnd-oasis-opendocument-spreadsheet' %> + <% end %> + <% elsif image.is_a? Gallery %> + + <% elsif image.is_a? Product %> + <% if image.image %> + <%= link_to '', product_path(image), :class => "search-image-pic", :style => 'background-image: url(%s)'% image.default_image(:thumb) %> + <% else %> +
    <%= _('No image') %>
    + <% end %> + <% else %> +
    + <% end %> +
    diff --git a/app/views/search/_product.rhtml b/app/views/search/_product.rhtml index bac132f..71fb2c4 100644 --- a/app/views/search/_product.rhtml +++ b/app/views/search/_product.rhtml @@ -1,39 +1,75 @@ <% extra_content = @plugins.map(:asset_product_extras, product, product.enterprise).collect { |content| instance_eval(&content) } %> <% extra_properties = @plugins.map(:asset_product_properties, product)%> -
  • -
    - <%= link_to_product product, :class => 'product-pic', :style => 'background-image:url(%s)' % product.default_image(:minor) %> - <%= product.price if product.price %> +
  • +
    + <%= render :partial => 'image', :object => product %> + + <% if product.available %> + <% if product.price && product.price > 0 %> + <% has_discount = product.discount && product.discount > 0 %> + <% if product.price %> + <%=_("from") if has_discount %><%= price_span(product.price, :class => "search-product-price " + (has_discount ? 'with-discount' : '')) %> + <% if has_discount %> + <%=_("by")%><%= price_span(product.price_with_discount, :class => "search-product-price") %> + <% end %> + <% if product.unit %> +  <%= _('/') %> <%= product.unit.name %> + <% end %> + <% end %> +
    + <% if product.inputs.count > product.inputs.collect(&:is_from_solidarity_economy).count(nil) %> + <% se_i = t_i = 0 %> + <% product.inputs.each{ |i| t_i += 1; se_i += 1 if i.is_from_solidarity_economy } %> + <% p = case (se_i.to_f/t_i)*100 when 0..24.999 then ["0", _("0%")]; when 25..49.999 then ["25", _("25%")]; when 50..74.999 then ["50", _("50%")]; when 75..100 then ["75", _("100%")]; end %> +
    + <%= p[1] %> +
    + <% end %> + + <% if product.inputs.count == product.inputs.collect(&:has_price_details?).count(true) %> + <% title = product.inputs.map{ |i| + '
    ' + + '
    ' + i.product_category.name + '
    ' + + price_span(i.price_per_unit*i.amount_used, :class => 'search-product-input-price') + + '
    ' }.join('') %> + <%= link_to_function _("Open Price"), '', :title => title, :class => "search-product-price-details" %> + <% end %> +
    + <% end %> + <% else %> + <%= _('Not available') %>
    + <% end %> + -
    - <%= link_to_product product %> -
    - <%= _('SUPPLIER') %> <%= link_to_homepage(product.enterprise.name, product.enterprise.identifier) %> +
    + <%= link_to_product product, :class => 'search-result-title' %> +
    + <%= _('Supplier') %> <%= link_to_homepage(product.enterprise.name, product.enterprise.identifier) %>
    -
    +
    <% if product.description %> <% desc_stripped = strip_tags(product.description) %> - <%= _('DESCRIPTION') %> <%= excerpt(desc_stripped, desc_stripped.first(3), 100) %> + <%= _('Description') %> <%= excerpt(desc_stripped, desc_stripped.first(3), 300) %> <% end %>
    -
    -
    +
    +
    <% if product.enterprise.region %> - <%= _('REGION') %> -
    <%= product.enterprise.region.name %> + <%= _('City') %> +
    <%= city_with_state(product.enterprise.region) %> <% end %>
    -
    +
    <% if product.product_qualifiers.count > 0 %> - <%= _('QUALIFIERS') %> + <%= _('Qualifiers') %> <% product.product_qualifiers.each do |pq| %> <% if pq.qualifier %> -
    <%= pq.qualifier.name %> + <%= pq.qualifier.name + (pq.certifier.nil? ? _(";") : '') %> <% end %> <% if pq.certifier %> -
    <%= pq.certifier.name %> +  <%= _('cert. ') + pq.certifier.name + _(";") %> <% end %> <% end %> <% end %> diff --git a/app/views/search/_profile.rhtml b/app/views/search/_profile.rhtml index d23203f..d72edc3 100644 --- a/app/views/search/_profile.rhtml +++ b/app/views/search/_profile.rhtml @@ -1,20 +1,42 @@ -<% if @query.blank? || !profile.enterprise? %> - <%= profile_image_link profile, :portrait %> -<% else %> -
    - <%= profile_image_link profile, :portrait %> - <%= profile.name %> - <%= _("Region: ") + profile.region.name if profile.region %>
    - <% if !profile.description.blank? %> - <%= profile.description %>
    - <% end %> +
  • + <% if @empty_query or @results.size > 1 or !profile.enterprise? %> + <%= profile_image_link profile, :portrait, 'div' %> + <% else %> +
    +
    + <%= profile_image_link profile, :portrait, 'div' %> +
    +
    + <%= link_to_homepage(profile.name, profile.identifier, :class => "search-result-title") %> +
    + <% if profile.description %> + <% body_stripped = strip_tags(profile.description) %> + <% elsif profile.home_page and profile.home_page.body %> + <% body_stripped = strip_tags(profile.home_page.body) %> + <% end %> + <%= excerpt(body_stripped, body_stripped.first(3), 200) if body_stripped %> +
    +
    + <%= _("City") %> + <% if profile.region %> + <%= city_with_state(profile.region) %> + <% else %> + <% end %> +
    + <% if !profile.description.blank? %> +
    <%= profile.description %>

    + <% end %> -
    - <% profile.top_level_categorization.each do |parent, children| %> - <%= parent.name + ':' %> - <%= children.collect(&:name).join(', ') %> -
    - <% end %> -
    -
    -<% end %> +
    + <% profile.top_level_categorization.each do |parent, children| %> +
    + <%= parent.name %> + <%= children.collect(&:name).join(', ') %> +
    + <% end %> +
    +
    +
    + + <% end %> +
  • diff --git a/app/views/search/_results_header.rhtml b/app/views/search/_results_header.rhtml index 4191434..9c0663b 100644 --- a/app/views/search/_results_header.rhtml +++ b/app/views/search/_results_header.rhtml @@ -1,10 +1,19 @@ -
    - <%= label_total_found(asset, results.total_entries) %> - <% if params[:display] != 'map' %> - <%= _("Showing page %s of %s") % [results.current_page, results.total_pages] %> - <% end %> +
    "> + <% if !@empty_query %> +
    + <%= label_total_found(asset, results.total_entries) %> + <% if params[:display] != 'map' %> + <%= _("Showing page %s of %s") % [results.current_page, results.total_pages] %> + <% end %> +
    - <%= facets_unselect_menu(asset) %> +
    + <%= facets_unselect_menu(asset) %> + <%= order_by(asset) if params[:display] != 'map' %> +
    + <% else %> +
    <%= @filter_title if @filter_title %>
    + <% end %> - <%= order_by(asset) if params[:display] != 'map' %> +
    diff --git a/app/views/search/_search_form.rhtml b/app/views/search/_search_form.rhtml index 3933729..f6cfe85 100644 --- a/app/views/search/_search_form.rhtml +++ b/app/views/search/_search_form.rhtml @@ -3,26 +3,36 @@ <% form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, :method => 'get', :class => 'search_form' ) do %> - <%= '

    %s

    ' % form_title if defined? form_title %> <%= hidden_field_tag :display, params[:display] %> - <%= hidden_field_tag :asset, params[:asset] %> -
    - <%= text_field_tag 'query', @query, :id => ( lightbox? ? 'popup-search-input' : '' ), :size => 50 %> - <%= javascript_tag 'setTimeout("$(\"popup-search-input\").focus()", 10 )' if lightbox? %> + <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50 %> + <%= javascript_tag "jQuery('#search-input').attr('title', \"#{hint}\").hint()" if defined?(hint) %> + <%= javascript_tag "jQuery('.search_form').submit(function() { + if (jQuery('#search-input').val().length < 3) { + jQuery('#search-empty-query-error').slideDown(200).delay(2500).slideUp(200); + return false; + } + });" %> - <%= submit_button(:search, _('Search'), :name => :search_whole_site_no) %> - <% if @category %> - <%= submit_button(:search, _('Search in whole site'), :name => :search_whole_site_yes) %> - <% end %> + + <%= submit_button(:search, _('Search')) %> + +
    + <%= _("Type more than 2 characters to start a search") %> +
    - <% if lightbox?; button_bar do %> - <%= lightbox_close_button _('Close') %> - <% end; end %> + <% if @empty_query %> + <% hint = environment.search_hints[@asset] %> + <% if hint and !hint.blank? %> + <%= hint %> + <% end %> + <% end %> + +
    <% end %> diff --git a/app/views/search/_text_article.rhtml b/app/views/search/_text_article.rhtml new file mode 100644 index 0000000..964aca2 --- /dev/null +++ b/app/views/search/_text_article.rhtml @@ -0,0 +1,10 @@ +
  • + <%= link_to(text_article.title, text_article.url, :class => "search-result-title") %> +
    + <%= render :partial => 'image', :object => text_article %> +
    +
    + <%= render :partial => 'article_common', :object => text_article %> +
    +
    +
  • diff --git a/app/views/search/_uploaded_file.rhtml b/app/views/search/_uploaded_file.rhtml new file mode 100644 index 0000000..c97a983 --- /dev/null +++ b/app/views/search/_uploaded_file.rhtml @@ -0,0 +1,36 @@ +
  • + <%= link_to uploaded_file.filename, uploaded_file.view_url, :class => 'search-result-title' %> +
    + +
    + <%= render :partial => 'image', :object => uploaded_file %> +
    + +
    + <%= render :partial => 'article_author', :object => uploaded_file %> + +
    + <% if !uploaded_file.body.blank? %> + <%= _("Description") %> + <% body = strip_tags(uploaded_file.body.to_s) %> + <%= excerpt(body, body.first(3), 200) %> + <% end %> +
    + +
    + <% if uploaded_file.parent && uploaded_file.parent.published? %> + <% if uploaded_file.parent.gallery? %> + <%= _("Gallery") %> + <% else %> + <%= _("Folder") %> + <% end %> + <%= link_to uploaded_file.parent.name, {:controller => 'content_viewer', :profile => uploaded_file.profile.identifier, :action => 'view_page', :page => [uploaded_file.parent.slug]} %> + <% end %> +
    + + <%= render :partial => 'article_tags', :object => uploaded_file.tags %> + <%= render :partial => 'article_categories', :object => uploaded_file.categories %> + <%= render :partial => 'article_last_change', :object => uploaded_file %> +
    +
    +
  • diff --git a/app/views/search/articles.rhtml b/app/views/search/articles.rhtml index 4b336c8..83f4138 100644 --- a/app/views/search/articles.rhtml +++ b/app/views/search/articles.rhtml @@ -1,20 +1,20 @@ -<%= search_page_title( _('Articles'), { :query => @query, - :total_results => @total_results } ) %> +<%= search_page_title( @titles[:articles], @category ) %> -<%= search_page_link_to_all( { :asset => params[:asset], - :category => @category }) %> +
    + <% if !@empty_query %> + <%= facets_menu(:articles, @facets) %> + <% end %> +
    -<%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> +
    + <%= render :partial => 'search_form', :locals => { :form_title => _('Search'), :simple_search => true, + :hint => _('Type the title, author or content desired') } %> + <%= render :partial => 'results_header', :locals => { :asset => :articles, :results => @results[:articles] } %> -<% if !@query.blank? %> - <%= facets_menu(:articles, @facets) %> -<% end %> - -<%= render :partial => 'results_header', :locals => { :asset => :articles, :results => @results[:articles] } %> - -<%# FIXME ARMENGUE %> -<%= display_results(false) %> - -<%= pagination_links @results.values.first %> + <% if !@empty_query or @filter %> + <%= display_results %> + <%= pagination_links @results.values.first %> + <% end %> +

    diff --git a/app/views/search/category_index.rhtml b/app/views/search/category_index.rhtml index 1e1b7cb..97e8a20 100644 --- a/app/views/search/category_index.rhtml +++ b/app/views/search/category_index.rhtml @@ -3,7 +3,7 @@
    <%= image_tag(@category.image.public_filename(:thumb), :id => 'category-image') if @category.image %>

    <%= @category.name %>

    - <%= render :partial => 'display_results' %> + <%= display_results %>

    <%= _('Sub-categories') %>

    diff --git a/app/views/search/communities.rhtml b/app/views/search/communities.rhtml index 0cbfa27..da735ad 100644 --- a/app/views/search/communities.rhtml +++ b/app/views/search/communities.rhtml @@ -1,29 +1,25 @@ -<%= search_page_title( __('Communities'), { :query => @query, - :total_results => @total_results } ) %> +<%= search_page_title( @titles[:communities], @category ) %> -<%= search_page_link_to_all( { :asset => params[:asset], - :category => @category }) %> -<%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> - -<% if logged_in? %> - <% button_bar do %> - <%# FIXME shouldn't the user create the community in the current environment instead of going to its home environment? %> - <%= button(:add, __('New community'), user.url.merge(:controller => 'memberships', :action => 'new_community')) %> +
    + <% if logged_in? %> + <% button_bar do %> + <%# FIXME shouldn't the user create the community in the current environment instead of going to its home environment? %> + <%= button(:add, __('New community'), user.url.merge(:controller => 'memberships', :action => 'new_community')) %> + <% end %> <% end %> -<% end %> -<% if !@query.blank? %> - <%= facets_menu(:communities, @facets) %> -<% end %> -<%= render :partial => 'results_header', :locals => { :asset => :communities, :results => @results[:communities] } %> + <% if !@empty_query %> + <%= facets_menu(:communities, @facets) %> + <% end %> +
    -
    - <%# FIXME ARMENGUE %> - <%= display_results(false) %> +
    + <%= render :partial => 'search_form', :locals => { :form_title => _('Search'), :simple_search => true, + :hint => _("Type words about the community you're looking for") } %> + <%= render :partial => 'results_header', :locals => { :asset => :communities, :results => @results[:communities] } %> - <% if params[:display] != 'map' %> - <%= pagination_links @results.values.first %> - <% end %> + <%= display_results %> + <%= pagination_links @results.values.first %>

    diff --git a/app/views/search/enterprises.rhtml b/app/views/search/enterprises.rhtml index 01feb91..6383514 100644 --- a/app/views/search/enterprises.rhtml +++ b/app/views/search/enterprises.rhtml @@ -1,41 +1,29 @@ -

    - <% if !@query.blank? %> - <%=h @category ? (__('Enterprise results for "%{query}" in "%{category}"') % { :query => @query, :category => @category.name}) : (__('Enterprise results for "%s"') % @query) %> - <% else %> - <%=h @category ? (__('Enterprises in "%s"') % @category.name) : __('Enterprises') %> - <% end %> -

    - -<%= search_page_link_to_all( { :asset => params[:asset] }) %> +<%= search_page_title( @titles[:enterprises], @category ) %> -<%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> - -<% if logged_in? && environment.enabled?('enterprise_registration') %> - <% button_bar do %> - <%= button(:add, __('New enterprise'), {:controller => 'enterprise_registration'}) %> +
    + <% if logged_in? && environment.enabled?('enterprise_registration') %> + <% button_bar do %> + <%= button(:add, __('New enterprise'), {:controller => 'enterprise_registration'}) %> + <% end %> <% end %> -<% end %> - -<% if @categories_menu %> -
    -<% end %> -<% cache(:action => 'assets', :asset => 'enterprises', :query => @query) do %> - <% if !@query.blank? %> + <% if !@empty_query %> + <% button_bar do %> + <%= display_map_list_button %> + <% end %> <%= facets_menu(:enterprises, @facets) %> <% end %> -<% end %> +
    -<%= render :partial => 'results_header', :locals => { :asset => :enterprises, :results => @results[:enterprises] } %> +
    + <%= render :partial => 'search_form', :locals => { :form_title => _('Search'), :simple_search => true, + :hint => _("Type words about the enterprise you're looking for") } %> + <%= render :partial => 'results_header', :locals => { :asset => :enterprises, :results => @results[:enterprises] } %> -<%= display_results %> - -<% if @categories_menu %> -
    -<% end %> - -<% if params[:display] != 'map' %> - <%= pagination_links @results[:enterprises] %> -<% end %> + <%= display_results(true) %> + <% if params[:display] != 'map' %> + <%= pagination_links @results[:enterprises] %> + <% end %> +

    diff --git a/app/views/search/events.rhtml b/app/views/search/events.rhtml index 829d70d..b429e00 100644 --- a/app/views/search/events.rhtml +++ b/app/views/search/events.rhtml @@ -1,8 +1,3 @@ -

    - <%= _("%s's events") % @environment.name %> - <% if @category %> - :<%= @category.name %> - <% end %> -

    +<%= search_page_title( @titles[:events], @category ) %> <%= render :partial => 'events/agenda' %> diff --git a/app/views/search/facets_browse.rhtml b/app/views/search/facets_browse.rhtml new file mode 100644 index 0000000..7178788 --- /dev/null +++ b/app/views/search/facets_browse.rhtml @@ -0,0 +1,8 @@ +<% results = @asset_class.map_facet_results(@facet, params[:facet], @facets, @all_facets) %> + +<% array = [] %> +<% @asset_class.facet_result_sort(@facet, results, :alphabetically).each do |id, label, count| %> + <% array << {:id => id, :name => facet_link_html(@facet, params.merge(:controller => 'search', :action => @asset), id, label, count)} %> +<% end %> + +<%= facet_javascript('facet-input-'+@facet[:id].to_s, @facet, array) %> diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml index fb19583..0e3902d 100644 --- a/app/views/search/index.rhtml +++ b/app/views/search/index.rhtml @@ -1,7 +1,6 @@
    -<%= search_page_title(_('Search Results'), :query => CGI.escapeHTML(@query), - :total_results => @total_results) %> +<%= search_page_title(_('Search Results'), @category) %> <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> diff --git a/app/views/search/people.rhtml b/app/views/search/people.rhtml index df0514f..250a221 100644 --- a/app/views/search/people.rhtml +++ b/app/views/search/people.rhtml @@ -1,22 +1,20 @@ -<%= search_page_title( _('People'), { :query => @query, - :total_results => @total_results } ) %> +<%= search_page_title( @titles[:people], @category ) %> -<%= search_page_link_to_all( { :asset => params[:asset], - :category => @category }) %> +
    + <% if !@empty_query %> + <%= facets_menu(:people, @facets) %> + <% end %> +
    -<%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> +
    + <%= render :partial => 'search_form', :locals => { :form_title => _('Search'), :simple_search => true, + :hint => _("Type words about the person you're looking for") } %> + <%= render :partial => 'results_header', :locals => { :asset => :people, :results => @results[:people] } %> -<% if !@query.blank? %> - <%= facets_menu(:people, @facets) %> -<% end %> - -<%= render :partial => 'results_header', :locals => { :asset => :people, :results => @results[:people] } %> - -<%# FIXME ARMENGUE %> -<%= display_results(false) %> - -<% if params[:display] != 'map' %> - <%= pagination_links @results.values.first %> -<% end %> + <%= display_results %> + <% if params[:display] != 'map' %> + <%= pagination_links @results.values.first %> + <% end %> +

    diff --git a/app/views/search/products.rhtml b/app/views/search/products.rhtml index 95a165a..4c3b42a 100644 --- a/app/views/search/products.rhtml +++ b/app/views/search/products.rhtml @@ -1,31 +1,26 @@ -<%= search_page_title( _('Products and Services'), { :query => @query, - :total_results => @total_results } ) %> - -<%= search_page_link_to_all( { :asset => params[:asset], - :category => @category }) %> - -<%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> - -<% if @categories_menu %> -
    -<% end %> - -<% cache(:action => 'assets', :asset => 'products', :query => @query) do %> - <% if !@query.blank? %> - <%= facets_menu(:products, @facets) %> +<%= search_page_title( @titles[:products], @category ) %> + +
    + <% if !@empty_query %> + <% button_bar do %> + <%= display_map_list_button %> + <% end %> + <%= facets_menu(:products, @facets) %> <% end %> -<% end %> - -<%= render :partial => 'results_header', :locals => { :asset => :products, :results => @results[:products] } %> - -<%= display_results %> - -<% if @categories_menu %> -
    -<% end %> +
    + +
    + <%= render :partial => 'search_form', :locals => { :form_title => _("Search"), :simple_search => true, + :hint => _('Type the product, service, city or qualifier desired') } %> + <%= render :partial => 'results_header', :locals => { :asset => :products, :results => @results[:products] } %> + + <% if !@empty_query %> + <%= display_results(true) %> + <% if params[:display] != 'map' %> + <%= pagination_links @results[:products] %> + <% end %> + <% end %> +
    -<% if params[:display] != 'map' %> - <%= pagination_links @results[:products] %> -<% end %>
    diff --git a/lib/acts_as_faceted.rb b/lib/acts_as_faceted.rb index 2298d5f..52af9c6 100644 --- a/lib/acts_as_faceted.rb +++ b/lib/acts_as_faceted.rb @@ -6,47 +6,180 @@ module ActsAsFaceted module ActsMethods # Example: # - # acts_as_faceted :fields => { - # :f_category => {:label => _('Related products')}, - # :f_region => {:label => _('Region')}, - # :f_qualifier => {:label => _('Qualifiers')}}, - # :order => [:f_category, :f_region, :f_qualifier] + #acts_as_faceted :fields => { + # :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")}}, + # :f_profile_type => {:label => _('Author'), :proc => proc{|klass| f_profile_type_proc(klass)}}, + # :f_category => {:label => _('Categories')}}, + # :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_option_for_solr, + # :if => proc{|a| ! ['RssFeed'].include?(a.class.name)} def acts_as_faceted(options) extend ClassMethods + extend ActsAsSolr::CommonMethods cattr_accessor :facets cattr_accessor :facets_order - cattr_accessor :solr_facet_fields - cattr_accessor :to_solr_facet_fields + cattr_accessor :to_solr_fields_names + cattr_accessor :facets_results_containers + cattr_accessor :solr_fields_names + cattr_accessor :facets_option_for_solr + cattr_accessor :facets_fields_for_solr + cattr_accessor :facet_category_query self.facets = options[:fields] self.facets_order = options[:order] || facets + self.facets_results_containers = {:fields => 'facet_fields', :queries => 'facet_queries', :ranges => 'facet_ranges'} + self.facets_option_for_solr = Hash[facets.select{ |id,data| ! data.has_key?(:queries) }].keys + self.facets_fields_for_solr = facets.map{ |id,data| {id => data[:type] || :facet} } + self.solr_fields_names = facets.map{ |id,data| id.to_s + '_' + get_solr_field_type(data[:type] || :facet) } + self.facet_category_query = options[:category_query] # A hash to retrieve the field key for the solr facet string returned - # "field_name_facet" => :field_name - self.solr_facet_fields = Hash[facets.keys.map{|f| f.to_s+'_facet'}.zip(facets.keys)] # :field_name => "field_name_facet" - self.to_solr_facet_fields = Hash[facets.keys.zip(facets.keys.map{|f| f.to_s+'_facet'})] + self.to_solr_fields_names = Hash[facets.keys.zip(solr_fields_names)] + + def facet_by_id(id) + {:id => id}.merge(facets[id]) if facets[id] + end + + def map_facets_for(environment) + list = facets_order ? facets_order : facets.keys + list.map do |id| + facet = facet_by_id(id) + next if facet[:type_if] and !facet[:type_if].call(self.new) - def each_facet - if facets_order - facets_order.each_with_index { |f, i| yield [f, i] } + if facet[:multi] + facet[:label].call(environment).map do |label_id, label| + facet.merge({:id => facet[:id].to_s+'_'+label_id.to_s, :solr_field => facet[:id], :label_id => label_id, :label => label}) + end + else + facet.merge(:id => facet[:id].to_s, :solr_field => facet[:id]) + end + end.compact.flatten + end + + def map_facet_results(facet, facet_params, facets_data, unfiltered_facets_data = {}, options = {}) + facets_data ||= {} + solr_facet = to_solr_fields_names[facet[:solr_field]] + + if unfiltered_facets_data + facets_data = unfiltered_facets_data.mash do |container, value| + [container, value.mash do |field, value| + facets_data[container] = {} if facets_data[container].nil? or facets_data[container] == [] + f = Hash[Array(facets_data[container][field])] + zeros = [] + [field, Array(value).map do |id, count| + count = f[id] + if count.nil? + zeros.push [id, 0] + nil + else + [id, count] + end + end.compact + zeros] + end] + end + end + + if facet[:queries] + container = facets_data[facets_results_containers[:queries]] + facet_data = (container.nil? or container.empty?) ? [] : container.select{ |k,v| k.starts_with? solr_facet } else - facets.each_with_index { |f, i| yield [f. i] } + container = facets_data[facets_results_containers[:fields]] + facet_data = (container.nil? or container.empty?) ? [] : container[solr_facet] || [] end + + facet_count = facet_data.length + + if facet[:queries] + result = facet_data.map do |id, count| + q = id[id.index(':')+1,id.length] + label = facet_result_name(facet, q) + [q, label, count] if count > 0 + end.compact + result = facet[:queries_order].map{ |id| result.detect{ |rid, label, count| rid == id } }.compact if facet[:queries_order] + elsif facet[:proc] + if facet[:label_id] + result = facet_data.map do |id, count| + name = facet_result_name(facet, id) + [id, name, count] if name + end.compact + # FIXME limit is NOT improving performance in this case :( + facet_count = result.length + result = result.first(options[:limit]) if options[:limit] + else + facet_data = facet_data.first(options[:limit]) if options[:limit] + result = facet_data.map { |id, count| [id, facet_result_name(facet, id), count] } + end + else + facet_data = facet_data.first(options[:limit]) if options[:limit] + result = facet_data.map { |id, count| [id, facet_result_name(facet, id), count] } + end + + sorted = facet_result_sort(facet, result, options[:sort]) + + # length can't be used if limit option is given; + # total_entries comes to help + sorted.class.send(:define_method, :total_entries, proc { facet_count }) + + sorted end - def each_facet_name(solr_facet, data, options = {}) - facet = facets[solr_facet_fields[solr_facet]] + def facet_result_sort(facet, facets_data, sort_by = nil) + if facet[:queries_order] + facets_data + elsif sort_by == :alphabetically + facets_data.sort{ |a,b| a[1] <=> b[1] } + elsif sort_by == :count + facets_data.sort{ |a,b| -1*(a[2] <=> b[2]) } + else + facets_data + end + end - if options[:sort] == :alphabetically - result = data.sort{ |a,b| -1*(a[0] <=> b[0]) } - result.each { |name, count| yield [name, count] } + def facet_result_name(facet, data) + if facet[:queries] + gettext(facet[:queries][data]) + elsif facet[:proc] + if facet[:multi] + facet[:label_id] ||= 0 + facet[:proc].call(facet, data) + else + gettext(facet[:proc].call(data)) + end else - result = options[:sort] == :count ? data.sort{ |a,b| -1*(a[1] <=> b[1]) } : data - result.each { |name, count| yield [name, count] } + data end end + + def facets_find_options(facets_selected = {}, options = {}) + browses = [] + facets_selected ||= {} + facets_selected.map do |id, value| + if value.kind_of?(Hash) + value.map do |label_id, value| + value.to_a.each do |value| + browses << id.to_s + ':' + (facets[id.to_sym][:queries] ? value : '"'+value.to_s+'"') + end + end + else + browses << id.to_s + ':' + (facets[id.to_sym][:queries] ? value : '"'+value.to_s+'"') + end + end.flatten + + {:facets => {:zeros => false, :sort => :count, + :fields => facets_option_for_solr, + :browse => browses, + :query => facets.map { |f, options| options[:queries].keys.map { |q| f.to_s + ':' + q } if options[:queries]}.compact.flatten, + } + } + end end end @@ -54,3 +187,30 @@ end ActiveRecord::Base.extend ActsAsFaceted::ActsMethods +# from https://github.com/rubyworks/facets/blob/master/lib/core/facets/enumerable/graph.rb +module Enumerable + def graph(&yld) + if yld + h = {} + each do |*kv| + r = yld[*kv] + case r + when Hash + nk, nv = *r.to_a[0] + when Range + nk, nv = r.first, r.last + else + nk, nv = *r + end + h[nk] = nv + end + h + else + Enumerator.new(self,:graph) + end + end + + # Alias for #graph, which stands for "map hash". + alias_method :mash, :graph +end + diff --git a/lib/acts_as_searchable.rb b/lib/acts_as_searchable.rb index 8659925..0521384 100644 --- a/lib/acts_as_searchable.rb +++ b/lib/acts_as_searchable.rb @@ -4,16 +4,18 @@ module ActsAsSearchable ACTS_AS_SEARCHABLE_ENABLED = true unless defined? ACTS_AS_SEARCHABLE_ENABLED def acts_as_searchable(options = {}) - if ACTS_AS_SEARCHABLE_ENABLED - if (!options[:fields]) - options[:additional_fields] |= [{:schema_name => :string}] - else - options[:fields] << {:schema_name => :string} - end - acts_as_solr options - extend FindByContents - send :include, InstanceMethods + return if !ACTS_AS_SEARCHABLE_ENABLED + + if (!options[:fields]) + options[:additional_fields] |= [{:schema_name => :string}] + else + options[:fields] << {:schema_name => :string} end + acts_as_solr options + extend FindByContents + send :include, InstanceMethods + + handle_asynchronously :solr_save end module InstanceMethods @@ -31,14 +33,20 @@ module ActsAsSearchable def find_by_contents(query, pg_options = {}, options = {}, db_options = {}) pg_options[:page] ||= 1 pg_options[:per_page] ||= 20 - options[:limit] = pg_options[:per_page].to_i*pg_options[:page].to_i - options[:scores] = true; - + options[:limit] ||= pg_options[:per_page].to_i*pg_options[:page].to_i + options[:scores] ||= true; + all_facets_enabled = options.delete(:all_facets) query = !schema_name.empty? ? "+schema_name:\"#{schema_name}\" AND #{query}" : query + results = [] + facets = all_facets = {} + solr_result = find_by_solr(query, options) - if solr_result.nil? - results = facets = [] - else + if all_facets_enabled + options[:facets][:browse] = nil + all_facets = find_by_solr(query, options.merge(:limit => 0)).facets + end + + if !solr_result.nil? facets = options.include?(:facets) ? solr_result.facets : [] if db_options.empty? @@ -61,7 +69,7 @@ module ActsAsSearchable results = results.paginate(pg_options.merge(:total_entries => solr_result.total)) end - {:results => results, :facets => facets} + {:results => results, :facets => facets, :all_facets => all_facets} end end end diff --git a/public/designs/themes/base/style.css b/public/designs/themes/base/style.css index edfb690..8818bfb 100644 --- a/public/designs/themes/base/style.css +++ b/public/designs/themes/base/style.css @@ -1,6 +1,5 @@ /* ==> button.css <== */ - .button { -moz-border-radius: 3px; -webkit-border-radius: 3px; @@ -502,11 +501,11 @@ div#notice { } #content .profile-list li a, -#content .common-profile-list-block li a { +#content .common-profile-list-block .vcard li a { color: #555; } #content .profile-list li a:hover, -#content .common-profile-list-block li a:hover { +#content .common-profile-list-block .vcard li a:hover { color: #000; text-decoration: none; } diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 34cc445..c11f076 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -773,3 +773,17 @@ jQuery('a[title]').live('mouseout', function (e) { altBeautify.hide(); }); + +function facet_options_toggle(id, url) { + jQuery('#facet-menu-'+id+' .facet-menu-options').toggle('fast' , function () { + more = jQuery('#facet-menu-'+id+' .facet-menu-more-options'); + console.log(more); + if (more.is(':visible') && more.children().length == 0) { + more.addClass('small-loading'); + more.load(url, function () { + more.removeClass('small-loading'); + }); + } + }); +} + -- libgit2 0.21.2