Commit e6d5780d179d61cff097447d86196875a7730409

Authored by Braulio Bhavamitra
1 parent 83c7d50d

Search refactoring

- Start search refactoring to a action based controller, like the
  BrowseController
- Region, city and other advanced options removed in favor of facets
- Add search contents menu Contents (or Articles) like people one.
- Removed browse controller and views. They will unified with the
  refactored search controller and views.
- Initial category search changes, see subsequent commits
app/controllers/public/search_controller.rb
1 1 class SearchController < PublicController
2 2  
3 3 helper TagsHelper
  4 + include SearchHelper
4 5  
5 6 before_filter :load_category
6   - before_filter :prepare_filter
7 7 before_filter :check_search_whole_site
8 8 before_filter :load_search_assets
9   - before_filter :check_valid_assets, :only => [ :assets ]
10 9  
11 10 no_design_blocks
12 11  
13   - protected
  12 + def articles
  13 + @asset = :articles
  14 + @query = params[:query] || ''
  15 + @order ||= [@asset]
  16 + @results ||= {}
  17 + @filter = filter
  18 +
  19 + pg_options = paginate_options(@asset, limit, params[:per_page])
  20 + if !@query.blank?
  21 + ret = asset_class(@asset).find_by_contents(@query, pg_options, solr_options(@asset, params[:facet], params[:order_by]))
  22 + @results[@asset] = ret[:results]
  23 + @facets = ret[:facets]
  24 + else
  25 + @results[@asset] = asset_class(@asset).send('paginate', :all, pg_options)
  26 + @facets = {}
  27 + end
  28 + end
14 29  
15   - def load_search_assets
16   - @search_in = where_to_search
17   - @searching = {}
18   - @search_in.each do |key, name|
19   - @searching[key] = (params[:asset].blank? && (params[:find_in].nil? || params[:find_in].empty? || params[:find_in].include?(key.to_s))) || (params[:asset] == key.to_s)
  30 + alias :contents :articles
  31 +
  32 + def people
  33 + @asset = :people
  34 + @query = params[:query] || ''
  35 + @order ||= [@asset]
  36 + @results ||= {}
  37 + @filter = filter
  38 + @title = self.filter_description(params[:action] + '_' + @filter )
  39 +
  40 + @results[@asset] = @environment.people.visible.send(@filter)
  41 + if !@query.blank?
  42 + ret = @results[@asset].find_by_contents(@query, {}, solr_options(@asset, params[:facet], params[:order_by]))
  43 + @results[@asset] = ret[:results]
  44 + @facets = ret[:facets]
  45 + else
  46 + @facets = {}
20 47 end
  48 + @results[@asset] = @results[@asset].compact.paginate(:per_page => limit, :page => params[:page])
21 49 end
22 50  
23   - def prepare_filter
24   - if @category
25   - @noosfero_finder = CategoryFinder.new(@category)
  51 + def products
  52 + @asset = :products
  53 + @query = params[:query] || ''
  54 + @order ||= [@asset]
  55 + @results ||= {}
  56 +
  57 + pg_options = paginate_options(@asset, limit, params[:per_page])
  58 + if !@query.blank?
  59 + ret = asset_class(@asset).find_by_contents(@query, pg_options, solr_options(@asset, params[:facet], params[:order_by]))
  60 + @results[@asset] = ret[:results]
  61 + @facets = ret[:facets]
26 62 else
27   - @noosfero_finder = EnvironmentFinder.new(@environment)
  63 + @results[@asset] = asset_class(@asset).send('paginate', :all, pg_options)
  64 + @facets = {}
28 65 end
29 66 end
30 67  
31   - def check_search_whole_site
32   - if params[:search_whole_site_yes] or params[:search_whole_site] == 'yes'
33   - redirect_to params.merge(:category_path => [], :search_whole_site => nil, :search_whole_site_yes => nil)
  68 + def enterprises
  69 + @asset = :enterprises
  70 + @query = params[:query] || ''
  71 + @order ||= [@asset]
  72 + @results ||= {}
  73 +
  74 + pg_options = paginate_options(@asset, limit, params[:per_page])
  75 + if !@query.blank?
  76 + ret = asset_class(@asset).find_by_contents(@query, pg_options, solr_options(@asset, params[:facet], params[:order_by]))
  77 + @results[@asset] = ret[:results]
  78 + @facets = ret[:facets]
  79 + else
  80 + @results[@asset] = asset_class(@asset).send('paginate', :all, pg_options)
  81 + @facets = {}
34 82 end
35 83 end
36 84  
37   - def check_valid_assets
38   - @asset = params[:asset].to_sym
39   - if !where_to_search.map(&:first).include?(@asset)
40   - render :text => 'go away', :status => 403
41   - return
  85 + def communities
  86 + @asset = :communities
  87 + @query = params[:query] || ''
  88 + @order ||= [@asset]
  89 + @results ||= {}
  90 + @filter = filter
  91 + @title = self.filter_description(params[:action] + '_' + @filter )
  92 +
  93 + @results[@asset] = @environment.communities.visible.send(@filter)
  94 + if !@query.blank?
  95 + ret = @results[@asset].find_by_contents(@query, {}, solr_options(@asset, params[:facet], params[:order_by]))
  96 + @results[@asset] = ret[:results]
  97 + @facets = ret[:facets]
  98 + else
  99 + @facets = {}
42 100 end
  101 + @results[@asset] = @results[@asset].compact.paginate(:per_page => limit, :page => params[:page])
43 102 end
44 103  
45 104 def events
  105 + @asset = :events
  106 + params[:asset] |= [@asset]
  107 + @query = params[:query] || ''
  108 + @order ||= [@asset]
  109 + @results ||= {}
46 110 @category_id = @category ? @category.id : nil
47 111  
  112 + if params[:year] || params[:month]
  113 + date = Date.new(year.to_i, month.to_i, 1)
  114 + date_range = (date - 1.month)..(date + 1.month).at_end_of_month
  115 + end
  116 +
  117 + if @query.blank?
  118 + # Ignore pagination for asset events
  119 + if date_range
  120 + @results[@asset] = Event.send('find', :all,
  121 + :conditions => [
  122 + 'start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day',
  123 + {:start_day => date_range.first, :end_day => date_range.last}
  124 + ])
  125 + else
  126 + @results[@asset] = Event.send('find', :all)
  127 + end
  128 + else
  129 + pg_options = paginate_options(@asset, limit, params[:per_page])
  130 + solr_options = solr_options(@asset, params[:facet], params[:per_page])
  131 + @results[@asset] = Event.find_by_contents(@query, pg_options, solr_options)[:results]
  132 + end
  133 +
48 134 @selected_day = nil
49 135 @events_of_the_day = []
50 136 date = build_date(params[:year], params[:month], params[:day])
... ... @@ -58,125 +144,24 @@ class SearchController &lt; PublicController
58 144 end
59 145 end
60 146  
61   - events = @results[:events]
62   -
  147 + events = @results[@asset]
63 148 @calendar = populate_calendar(date, events)
64 149 @previous_calendar = populate_calendar(date - 1.month, events)
65 150 @next_calendar = populate_calendar(date + 1.month, events)
66 151 end
67 152  
68   - def people
69   - #nothing, just to enable
70   - end
71   - def enterprises
72   - load_product_categories_menu(:enterprises)
73   - @categories_menu = true
74   - end
75   - def communities
76   - #nothing, just to enable
77   - end
78   - def articles
79   - #nothins, just to enable
80   - end
81   -
82   - def products
83   - load_product_categories_menu(:products)
84   - @categories_menu = true
85   - end
86   -
87   - def load_product_categories_menu(asset)
88   - @results[asset].uniq!
89   - # REFACTOR DUPLICATED CODE inner loop doing the same thing that outter loop
90   -
91   - if !@query.blank? || @region && !params[:radius].blank?
92   - ret = @noosfero_finder.find(asset, @query, calculate_find_options(asset, nil, params[:page], @product_category, @region, params[:radius], params[:year], params[:month], params[:order_by]).merge({:limit => :all}))
93   - @result_ids = ret.is_a?(Hash) ? ret[:results] : ret
94   - end
95   -
96   - end
97   -
98   - def calculate_find_options(asset, limit, page, product_category, region, radius, year, month, solr_order)
99   - result = { :product_category => product_category, :per_page => limit, :page => page }
100   - if [:enterprises, :people, :products].include?(asset) && region
101   - result.merge!(:within => radius, :region => region.id)
102   - end
103   -
104   - if month || year
105   - date = Date.new(year.to_i, month.to_i, 1)
106   - result[:date_range] = (date - 1.month)..(date + 1.month).at_end_of_month
107   - end
108   -
109   - if asset_class(asset).methods.include?('facets')
110   - result.merge!(:facets => {:zeros => false, :sort => :count, :fields => asset_class(asset).facets.keys,
111   - :browse => params[:facet] ? params[:facet].map{ |k,v| k.to_s+':"'+v.to_s+'"'} : ''})
112   - end
113   -
114   - result[:order_by] = solr_order
115   -
116   - result
117   - end
118   -
119   - # limit the number of results per page
120   - # TODO: dont hardcore like this
121   - def limit
122   - searching = @searching.values.select{|v|v}
123   - if params[:display] == 'map'
124   - 2000
125   - else
126   - (searching.size == 1) ? 20 : 6
127   - end
128   - end
129   -
130   - public
131   -
132   - include SearchHelper
133   -
134   - ######################################################
135   -
136   - def where_to_search
137   - [
138   - [ :articles, N_('Articles') ],
139   - [ :enterprises, N_('Enterprises') ],
140   - [ :people, N_('People') ],
141   - [ :communities, N_('Communities') ],
142   - [ :products, N_('Products') ],
143   - [ :events, N_('Events') ]
144   - ].select {|key, name| !environment.enabled?('disable_asset_' + key.to_s) }
145   - end
146   -
147   - def cities
148   - @cities = City.find(:all, :order => 'name', :conditions => ['parent_id = ? and lat is not null and lng is not null', params[:state_id]])
149   - render :action => 'cities', :layout => false
150   - end
151   -
152   - def complete_region
153   - # FIXME this logic should be in the model
154   - @regions = Region.find(:all, :conditions => [ '(name like ? or name like ?) and lat is not null and lng is not null', '%' + params[:region][:name] + '%', '%' + params[:region][:name].capitalize + '%' ])
155   - render :action => 'complete_region', :layout => false
156   - end
157   -
158 153 def index
159   - @query = params[:query] || ''
160   - @product_category = ProductCategory.find(params[:product_category]) if params[:product_category]
161   -
162   - @region = City.find_by_id(params[:city]) if !params[:city].blank? && params[:city] =~ /^\d+$/
163   -
164   - # how many assets we are searching for?
165   - number_of_result_assets = @searching.values.select{|v| v}.size
166   -
167 154 @results = {}
168   - @facets = {}
169 155 @order = []
170 156 @names = {}
171 157  
172 158 where_to_search.select { |key,description| @searching[key] }.each do |key, description|
  159 + send(key)
173 160 @order << key
174   - find_options = calculate_find_options(key, limit, params[:page], @product_category, @region, params[:radius], params[:year], params[:month], params[:order_by]);
175   - ret = @noosfero_finder.find(key, @query, find_options)
176   - @results[key] = ret.is_a?(Hash) ? ret[:results] : ret
177   - @facets[key] = ret.is_a?(Hash) ? ret[:facets] : {}
178 161 @names[key] = getterm(description)
179 162 end
  163 + @asset = nil
  164 + @facets = {}
180 165  
181 166 if @results.keys.size == 1
182 167 specific_action = @results.keys.first
... ... @@ -187,34 +172,76 @@ class SearchController &lt; PublicController
187 172 return
188 173 end
189 174 end
190   -
191   - render :action => 'index'
192 175 end
193 176  
194 177 alias :assets :index
195 178  
196   - #######################################################
197   -
198 179 # view the summary of one category
199 180 def category_index
200 181 @results = {}
201 182 @order = []
202 183 @names = {}
203 184 [
204   - [ :people, _('People'), @noosfero_finder.recent('people', limit) ],
205   - [ :enterprises, __('Enterprises'), @noosfero_finder.recent('enterprises', limit) ],
206   - [ :products, _('Products'), @noosfero_finder.recent('products', limit) ],
207   - [ :events, _('Upcoming events'), @noosfero_finder.upcoming_events({:per_page => limit}) ],
208   - [ :communities, __('Communities'), @noosfero_finder.recent('communities', limit) ],
209   - [ :most_commented_articles, _('Most commented articles'), @noosfero_finder.most_commented_articles(limit) ],
210   - [ :articles, _('Articles'), @noosfero_finder.recent('text_articles', limit) ]
  185 + [ :people, _('People'), recent('people') ],
  186 + [ :enterprises, __('Enterprises'), recent('enterprises') ],
  187 + [ :products, _('Products'), recent('products') ],
  188 + [ :events, _('Upcoming events'), upcoming_events({:per_page => limit}) ],
  189 + [ :communities, __('Communities'), recent('communities', limit) ],
  190 + [ :most_commented_articles, _('Most commented articles'), most_commented_articles(limit) ],
  191 + [ :articles, _('Articles'), recent('text_articles', limit) ]
211 192 ].each do |key, name, list|
212 193 @order << key
213 194 @results[key] = list
214 195 @names[key] = name
215 196 end
  197 + @facets = {}
  198 + end
  199 +
  200 + protected
  201 +
  202 + def recent(asset, limit = nil)
  203 + find(asset, nil, :limit => limit, :order => 'created_at DESC, id DESC')
  204 + end
  205 +
  206 + def most_commented_articles(limit=10, options={})
  207 + options = {:page => 1, :per_page => limit, :order => 'comments_count DESC'}.merge(options)
  208 + Article.paginate(:all, options_for_find(Article, options))
  209 + end
  210 +
  211 + def upcoming_events(options = {})
  212 + options.delete(:page)
  213 + options.delete(:per_page)
  214 +
  215 + Event.find(:all, {:include => :categories, :conditions => [ 'categories.id = ? and start_date >= ?', category_id, Date.today ], :order => 'start_date' }.merge(options))
216 216 end
  217 +
  218 +
217 219 attr_reader :category
  220 + attr_reader :category_id
  221 +
  222 + def load_category
  223 + unless params[:category_path].blank?
  224 + path = params[:category_path].join('/')
  225 + @category = environment.categories.find_by_path(path)
  226 + if @category.nil?
  227 + render_not_found(path)
  228 + end
  229 + @category_id = @category.id
  230 + end
  231 + end
  232 +
  233 + def where_to_search
  234 + [
  235 + [ :articles, N_('Articles') ],
  236 + [ :enterprises, N_('Enterprises') ],
  237 + [ :people, N_('People') ],
  238 + [ :communities, N_('Communities') ],
  239 + [ :products, N_('Products') ],
  240 + [ :events, N_('Events') ]
  241 + ].select {|key, name| !environment.enabled?('disable_asset_' + key.to_s) }
  242 + end
  243 +
  244 + #######################################################
218 245  
219 246 def tags
220 247 @tags_cache_key = "tags_env_#{environment.id.to_s}"
... ... @@ -248,4 +275,90 @@ class SearchController &lt; PublicController
248 275 render :partial => 'events/events_by_day'
249 276 end
250 277  
  278 + def current_events(year, month, options={})
  279 + options.delete(:page)
  280 + options.delete(:per_page)
  281 +
  282 + range = Event.date_range(year, month)
  283 +
  284 + Event.find(:all, {:include => :categories, :conditions => { 'categories.id' => category_id, :start_date => range }}.merge(options))
  285 + end
  286 +
  287 + def filter
  288 + if FILTERS.include?(params[:filter])
  289 + params[:filter]
  290 + else
  291 + 'more_recent'
  292 + end
  293 + end
  294 +
  295 + def filter_description(str)
  296 + {
  297 + 'contents_more_recent' => _('More recent contents'),
  298 + 'contents_more_popular' => _('More popular contents'),
  299 + 'people_more_recent' => _('More recent people'),
  300 + 'people_more_active' => _('More active people'),
  301 + 'people_more_popular' => _('More popular people'),
  302 + 'communities_more_recent' => _('More recent communities'),
  303 + 'communities_more_active' => _('More active communities'),
  304 + 'communities_more_popular' => _('More popular communities'),
  305 + }[str] || str
  306 + end
  307 +
  308 + def load_search_assets
  309 + @search_in = where_to_search
  310 + @searching = {}
  311 + @search_in.each do |key, name|
  312 + @searching[key] = (params[:asset].blank? && (params[:find_in].nil? || params[:find_in].empty? || params[:find_in].include?(key.to_s))) || (params[:asset] == key.to_s)
  313 + end
  314 + end
  315 +
  316 + def check_search_whole_site
  317 + if params[:search_whole_site_yes] or params[:search_whole_site] == 'yes'
  318 + redirect_to params.merge(:category_path => [], :search_whole_site => nil, :search_whole_site_yes => nil)
  319 + end
  320 + end
  321 +
  322 + FILTERS = %w(
  323 + more_recent
  324 + more_active
  325 + more_popular
  326 + )
  327 +
  328 + def paginate_options(asset, limit, page)
  329 + result = { :per_page => limit, :page => page }
  330 + end
  331 +
  332 + def solr_options(asset, facet, solr_order)
  333 + result = {}
  334 +
  335 + if asset_class(asset).methods.include?('facets')
  336 + result.merge!(:facets => {:zeros => false, :sort => :count, :fields => asset_class(asset).facets.keys,
  337 + :browse => facet ? facet.map{ |k,v| k.to_s+':"'+v.to_s+'"'} : ''})
  338 + end
  339 +
  340 + if solr_order
  341 + result[:order_by] = solr_order
  342 + end
  343 +
  344 + result
  345 + end
  346 +
  347 + def limit
  348 + searching = @searching.values.select{|v|v}
  349 + if params[:display] == 'map'
  350 + 2000
  351 + else
  352 + (searching.size == 1) ? 20 : 6
  353 + end
  354 + end
  355 +
  356 + def asset_class(asset)
  357 + asset.to_s.singularize.camelize.constantize
  358 + end
  359 +
  360 + def asset_table(asset)
  361 + asset_class(asset).table_name
  362 + end
  363 +
251 364 end
... ...
app/helpers/application_helper.rb
... ... @@ -572,7 +572,7 @@ module ApplicationHelper
572 572 end
573 573 extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' )
574 574 links = links_for_balloon(profile)
575   - content_tag tag,
  575 + content_tag('div', content_tag(tag,
576 576 (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{links.to_json}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") +
577 577 link_to(
578 578 content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) +
... ... @@ -582,7 +582,7 @@ module ApplicationHelper
582 582 :class => 'profile_link url',
583 583 :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name,
584 584 :title => profile.name ),
585   - :class => 'vcard'
  585 + :class => 'vcard'), :class => 'common-profile-list-block')
586 586 end
587 587  
588 588 def gravatar_url_for(email, options = {})
... ... @@ -887,9 +887,6 @@ module ApplicationHelper
887 887 def search_page_title(title, options={})
888 888 title = "<h1>" + title + "</h1>"
889 889 title += "<h2 class='query'>" + _("Searched for '%s'") % options[:query] + "</h2>" if !options[:query].blank?
890   - title += "<h2 class='query'>" + _("In category %s") % options[:category] + "</h2>" if !options[:category].blank?
891   - title += "<h2 class='query'>" + _("within %d km from %s") % [options[:distance], options[:region]] + "</h2>" if !options[:distance].blank? && !options[:region].blank?
892   - title += "<h2 class='query'>" + _("%d results found") % options[:total_results] + "</h2>" if !options[:total_results].blank?
893 890 title
894 891 end
895 892  
... ... @@ -1105,33 +1102,46 @@ module ApplicationHelper
1105 1102 ") : '')
1106 1103 end
1107 1104  
1108   - def browse_people_menu
  1105 + def search_contents_menu
  1106 + links = [
  1107 + {s_('contents|More Recent') => {:href => url_for({:controller => 'search', :action => 'contents', :filter => 'more_recent'})}},
  1108 + #{s_('contents|More Popular') => {:href => url_for({:controller => 'search', :action => 'contents', :filter => 'more_popular'})}}
  1109 + ]
  1110 + if logged_in?
  1111 + links.push(_('New Content') => lightbox_options({:href => url_for({:controller => 'cms', :action => 'new', :profile => current_user.login, :cms => true})}))
  1112 + end
  1113 +
  1114 + link_to(content_tag(:span, _('Contents'), :class => 'icon-menu-contents'), {:controller => "search", :action => 'contents'}, :id => 'submenu-contents') +
  1115 + link_to(content_tag(:span, _('Contents Menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-contents-trigger')
  1116 + end
  1117 +
  1118 + def search_people_menu
1109 1119 links = [
1110   - {s_('people|More Recent') => {:href => url_for({:controller => 'browse', :action => 'people', :filter => 'more_recent'})}},
1111   - {s_('people|More Active') => {:href => url_for({:controller => 'browse', :action => 'people', :filter => 'more_active'})}},
1112   - {s_('people|More Popular') => {:href => url_for({:controller => 'browse', :action => 'people', :filter => 'more_popular'})}}
  1120 + {s_('people|More Recent') => {:href => url_for({:controller => 'search', :action => 'people', :filter => 'more_recent'})}},
  1121 + {s_('people|More Active') => {:href => url_for({:controller => 'search', :action => 'people', :filter => 'more_active'})}},
  1122 + {s_('people|More Popular') => {:href => url_for({:controller => 'search', :action => 'people', :filter => 'more_popular'})}}
1113 1123 ]
1114 1124 if logged_in?
1115 1125 links.push(_('My friends') => {:href => url_for({:profile => current_user.login, :controller => 'friends'})})
1116 1126 links.push(_('Invite friends') => {:href => url_for({:profile => current_user.login, :controller => 'invite', :action => 'friends'})})
1117 1127 end
1118 1128  
1119   - link_to(content_tag(:span, _('People'), :class => 'icon-menu-people'), {:controller => "browse", :action => 'people'}, :id => 'submenu-people') +
  1129 + link_to(content_tag(:span, _('People'), :class => 'icon-menu-people'), {:controller => "search", :action => 'people'}, :id => 'submenu-people') +
1120 1130 link_to(content_tag(:span, _('People Menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-people-trigger')
1121 1131 end
1122 1132  
1123   - def browse_communities_menu
  1133 + def search_communities_menu
1124 1134 links = [
1125   - {s_('communities|More Recent') => {:href => url_for({:controller => 'browse', :action => 'communities', :filter => 'more_recent'})}},
1126   - {s_('communities|More Active') => {:href => url_for({:controller => 'browse', :action => 'communities', :filter => 'more_active'})}},
1127   - {s_('communities|More Popular') => {:href => url_for({:controller => 'browse', :action => 'communities', :filter => 'more_popular'})}}
  1135 + {s_('communities|More Recent') => {:href => url_for({:controller => 'search', :action => 'communities', :filter => 'more_recent'})}},
  1136 + {s_('communities|More Active') => {:href => url_for({:controller => 'search', :action => 'communities', :filter => 'more_active'})}},
  1137 + {s_('communities|More Popular') => {:href => url_for({:controller => 'search', :action => 'communities', :filter => 'more_popular'})}}
1128 1138 ]
1129 1139 if logged_in?
1130 1140 links.push(_('My communities') => {:href => url_for({:profile => current_user.login, :controller => 'memberships'})})
1131 1141 links.push(_('New community') => {:href => url_for({:profile => current_user.login, :controller => 'memberships', :action => 'new_community'})})
1132 1142 end
1133 1143  
1134   - link_to(content_tag(:span, _('Communities'), :class => 'icon-menu-community'), {:controller => "browse", :action => 'communities'}, :id => 'submenu-communities') +
  1144 + link_to(content_tag(:span, _('Communities'), :class => 'icon-menu-community'), {:controller => "search", :action => 'communities'}, :id => 'submenu-communities') +
1135 1145 link_to(content_tag(:span, _('Communities Menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-communities-trigger')
1136 1146 end
1137 1147  
... ...
app/views/browse/_article.rhtml
... ... @@ -1,11 +0,0 @@
1   -<li class="<%= 'browse-results-type-content ' + icon_for_article(result) %>">
2   - <strong><%= link_to(result.title, result.view_url) %></strong>
3   - <div class="item_meta">
4   - <span class="item_by">
5   - <%= _('by %s') % link_to(result.author.name, result.author.url) %>
6   - </span>
7   - <span class="extra-info">
8   - <%= (@filter == 'more_recent' ? result.send(@filter + '_label') + show_date(result.created_at) : result.send(@filter + '_label')) %>
9   - </span>
10   - </div>
11   -</li>
app/views/browse/_display_results.rhtml
... ... @@ -1,19 +0,0 @@
1   -<div id="browse-results">
2   -
3   - <div class='browse-results-innerbox'>
4   - <% if @results.empty? %>
5   - <div class="browse-results-type-empty">
6   - <div> <%= _('None') %> </div>
7   - </div><!-- end class="browse-results-innerbox" -->
8   - <% end %>
9   - <ul class='common-profile-list-block'>
10   - <% @results.each do |result| %>
11   - <%= render :partial => partial_for_class(result.class), :locals => {:result => result} %>
12   - <% end %>
13   - </ul>
14   - <br style='clear: both;'>
15   - </div>
16   -
17   - <br style="clear:both" />
18   -</div><!-- end id="browse-results" -->
19   -
app/views/browse/_person.rhtml
... ... @@ -1,3 +0,0 @@
1   -<%= profile_image_link result, :portrait, 'li',
2   - "<span class='adr'>#{result.city}</span>" +
3   - (@filter == 'more_recent' ? result.send(@filter + '_label') + show_date(result.created_at) : result.send(@filter + '_label')) %>
app/views/browse/_profile.rhtml
... ... @@ -1 +0,0 @@
1   -<%= profile_image_link result, :portrait, 'li', @filter == 'more_recent' ? result.send(@filter + '_label') + show_date(result.created_at) : result.send(@filter + '_label') %>
app/views/browse/_search_form.rhtml
... ... @@ -1,10 +0,0 @@
1   -<% form_tag( { :controller => 'browse', :action => action}, :method => 'get', :class => 'search_form' ) do %>
2   -
3   - <div class="search-field">
4   - <span class="formfield">
5   - <%= text_field_tag 'query', @query, :size => 50 %>
6   - </span>
7   - <%= submit_button(:search, _('Search')) %>
8   - </div>
9   -
10   -<% end %>
app/views/browse/communities.rhtml
... ... @@ -1,9 +0,0 @@
1   -<%= search_page_title( @title, { :query => @query} ) %>
2   -
3   -<%= render :partial => 'search_form', :locals => {:action => 'communities'} %>
4   -
5   -<%= render :partial => 'display_results' %>
6   -
7   -<%= pagination_links @results %>
8   -
9   -<br style="clear:both" />
app/views/browse/contents.rhtml
... ... @@ -1,9 +0,0 @@
1   -<%= search_page_title( @title, { :query => @query} ) %>
2   -
3   -<%= render :partial => 'search_form', :locals => {:action => 'contents'} %>
4   -
5   -<%= render :partial => 'display_results' %>
6   -
7   -<%= pagination_links @results %>
8   -
9   -<br style="clear:both" />
app/views/browse/people.rhtml
... ... @@ -1,9 +0,0 @@
1   -<%= search_page_title( @title, { :query => @query} ) %>
2   -
3   -<%= render :partial => 'search_form', :locals => {:action => 'people'} %>
4   -
5   -<%= render :partial => 'display_results' %>
6   -
7   -<%= pagination_links @results %>
8   -
9   -<br style="clear:both" />
app/views/search/_content.rhtml 0 → 120000
... ... @@ -0,0 +1 @@
  1 +_article.rhtml
0 2 \ No newline at end of file
... ...
app/views/search/_enterprise.rhtml
... ... @@ -1,17 +0,0 @@
1   -<% if params[:query].blank? %>
2   - <%= profile_image_link enterprise, :portrait %>
3   -<% else %>
4   - <div class="enterprise-result">
5   - <%= profile_image_link enterprise, :portrait %>
6   - <span><%= enterprise.name %></span>
7   - <span><%= _("Region: ") + enterprise.region.name if enterprise.region %></span>
8   - <span><%= enterprise.description %></span>
9   -
10   - <div class="enterprise-categorization">
11   - <% enterprise.top_level_categorization.each do |parent, children| %>
12   - <span class="enterprise-categorization-parent"><%= parent.name + ':' %></span>
13   - <span class="enterprise-categorization-children"><%= children.collect(&:name).join(', ') %></span>
14   - <% end %>
15   - </div>
16   - </div>
17   -<% end %>
app/views/search/_profile.rhtml
1   -<%= profile_image_link profile, :portrait %>
  1 +<% if @query.blank? || !profile.enterprise? %>
  2 + <%= profile_image_link profile, :portrait %>
  3 +<% else %>
  4 + <div class="enterprise-result">
  5 + <%= profile_image_link profile, :portrait %>
  6 + <span><%= profile.name %></span>
  7 + <span><%= _("Region: ") + profile.region.name if profile.region %></span><br />
  8 + <% if !profile.description.blank? %>
  9 + <span><%= profile.description %></span><br />
  10 + <% end %>
  11 +
  12 + <div class="enterprise-categorization">
  13 + <% profile.top_level_categorization.each do |parent, children| %>
  14 + <span class="enterprise-categorization-parent"><%= parent.name + ':' %></span>
  15 + <span class="enterprise-categorization-children"><%= children.collect(&:name).join(', ') %></span>
  16 + <br />
  17 + <% end %>
  18 + </div>
  19 + </div>
  20 +<% end %>
... ...
app/views/search/_search_form.rhtml
1 1 <div class='search-form'>
2 2 <% simple_search = false unless defined? simple_search %>
3 3  
4   -<% form_tag( { :controller => 'search', :action => 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) },
  4 +<% form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) },
5 5 :method => 'get', :class => 'search_form' ) do %>
6 6 <%= '<h3>%s</h3>' % form_title if defined? form_title %>
7 7  
... ... @@ -20,41 +20,6 @@
20 20 <% end %>
21 21 </div>
22 22  
23   - <div id='advanced-search-options' style="display: <%= simple_search ? 'none' : 'block' %>">
24   - <div class="search-options search-within">
25   - <h4><%= _('Search within:') %></h4>
26   - <br style='clear:left'/>
27   - <div>
28   - <span class="formfield">
29   - <%= select_city %>
30   - </span>
31   - <span class="formfield">
32   - <%= labelled_select(_('Distance:'), 'radius', :first, :last, nil, [15, 30, 50, 100, 150, 200, 300, 400, 500, 1000].map{|n|[n, n.to_s + 'km']}) %>
33   - </span>
34   - </div>
35   - </div><!-- fim class="search-options" -->
36   -
37   - <div class="search-options search-for">
38   - <h4><%= _('Search for:') %></h4>
39   - <ul>
40   - <% @search_in.map { |t,n| [t,getterm(n)] } .
41   - sort_by(&:last).each do |thing, name| %>
42   - <li>
43   - <%= labelled_check_box name, 'find_in[]', thing.to_s, @searching[thing.to_sym] %>
44   - </li>
45   - <% end %>
46   - </ul>
47   - <br style="clear:both" />
48   - </div><!-- fim class="search-options" -->
49   - </div><!-- end id="advanced-search-options" -->
50   -
51   - <% if simple_search %>
52   - <%= link_to_function(_('More options'), nil, :id => 'advanced_search_link') do |page|
53   - page['advanced_search_link'].hide
54   - page['advanced-search-options'].toggle
55   - end %>
56   - <% end %>
57   -
58 23 <% if lightbox?; button_bar do %>
59 24 <%= lightbox_close_button _('Close') %>
60 25 <% end; end %>
... ...
app/views/search/articles.rhtml
1 1 <%= search_page_title( _('Articles'), { :query => @query,
2   - :category => @category ? @category.name : nil,
3   - :total_results => @total_results,
4   - :region => @region ? @region.name : nil,
5   - :distance => @radius } ) %>
  2 + :total_results => @total_results } ) %>
6 3  
7 4 <%= search_page_link_to_all( { :asset => params[:asset],
8 5 :category => @category }) %>
... ... @@ -10,7 +7,7 @@
10 7 <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %>
11 8  
12 9 <% if !@query.blank? %>
13   - <%= facets_menu(:articles, @facets[:articles]) %>
  10 + <%= facets_menu(:articles, @facets) %>
14 11 <% end %>
15 12  
16 13 <%= render :partial => 'results_header', :locals => { :asset => :articles, :results => @results[:articles] } %>
... ...
app/views/search/cities.rhtml
... ... @@ -1,7 +0,0 @@
1   -<% if !@cities.empty? %>
2   - <% @cities.each do |city| %>
3   - <option value=<%= city.id.to_s.inspect %>><%= city.name %></option>
4   - <% end %>
5   -<% else %>
6   - <option value=''><%= _('No City') %></option>
7   -<% end%>
app/views/search/communities.rhtml
1 1 <%= search_page_title( __('Communities'), { :query => @query,
2   - :category => @category ? @category.name : nil,
3   - :total_results => @total_results,
4   - :region => @region ? @region.name : nil,
5   - :distance => @radius } ) %>
  2 + :total_results => @total_results } ) %>
6 3  
7 4 <%= search_page_link_to_all( { :asset => params[:asset],
8 5 :category => @category }) %>
... ... @@ -16,7 +13,7 @@
16 13 <% end %>
17 14  
18 15 <% if !@query.blank? %>
19   - <%= facets_menu(:communities, @facets[:communities]) %>
  16 + <%= facets_menu(:communities, @facets) %>
20 17 <% end %>
21 18 <%= render :partial => 'results_header', :locals => { :asset => :communities, :results => @results[:communities] } %>
22 19  
... ...
app/views/search/complete_region.rhtml
... ... @@ -1,7 +0,0 @@
1   -<% unless @regions.empty? %>
2   - <ul>
3   - <% for region in @regions %>
4   - <li><%= region.name %></li>
5   - <% end %>
6   - </ul>
7   -<% end%>
app/views/search/contents.rhtml 0 → 120000
... ... @@ -0,0 +1 @@
  1 +articles.rhtml
0 2 \ No newline at end of file
... ...
app/views/search/enterprises.rhtml
... ... @@ -6,12 +6,7 @@
6 6 <% end %>
7 7 </h1>
8 8  
9   -<% if @radius && @region %>
10   - <h2><%=h (_('Within %s km from %s') % [@radius, @region.name]) %><h2>
11   -<% end %>
12   -
13   -<%= search_page_link_to_all( { :asset => params[:asset],
14   - :category => @category }) %>
  9 +<%= search_page_link_to_all( { :asset => params[:asset] }) %>
15 10  
16 11 <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %>
17 12  
... ... @@ -25,11 +20,9 @@
25 20 <div class="has_cat_list">
26 21 <% end %>
27 22  
28   -<% cache(:action => 'assets', :asset => 'enterprises', :category_path => params[:category_path], :query => @query, :product_category => @product_category, :region => @region, :radius => params[:radius]) do %>
29   - <% if @query.blank? %>
30   - <%= product_categories_menu(:enterprises, @product_category, @result_ids) %>
31   - <% else %>
32   - <%= facets_menu(:enterprises, @facets[:enterprises]) %>
  23 +<% cache(:action => 'assets', :asset => 'enterprises', :query => @query) do %>
  24 + <% if !@query.blank? %>
  25 + <%= facets_menu(:enterprises, @facets) %>
33 26 <% end %>
34 27 <% end %>
35 28  
... ...
app/views/search/index.rhtml
1 1 <div id="search-page">
2 2  
3   -<%= search_page_title(_('Search Results'), :query => CGI.escapeHTML(@query), :category => @category ? @category.name : nil, :total_results => @total_results) %>
  3 +<%= search_page_title(_('Search Results'), :query => CGI.escapeHTML(@query),
  4 + :total_results => @total_results) %>
4 5  
5 6 <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %>
6 7  
... ...
app/views/search/people.rhtml
1 1 <%= search_page_title( _('People'), { :query => @query,
2   - :category => @category ? @category.name : nil,
3   - :total_results => @total_results,
4   - :region => @region ? @region.name : nil,
5   - :distance => @radius } ) %>
  2 + :total_results => @total_results } ) %>
6 3  
7 4 <%= search_page_link_to_all( { :asset => params[:asset],
8 5 :category => @category }) %>
... ... @@ -10,7 +7,7 @@
10 7 <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %>
11 8  
12 9 <% if !@query.blank? %>
13   - <%= facets_menu(:people, @facets[:people]) %>
  10 + <%= facets_menu(:people, @facets) %>
14 11 <% end %>
15 12  
16 13 <%= render :partial => 'results_header', :locals => { :asset => :people, :results => @results[:people] } %>
... ...
app/views/search/products.rhtml
1 1 <%= search_page_title( _('Products and Services'), { :query => @query,
2   - :category => @category ? @category.name : nil,
3   - :total_results => @total_results,
4   - :region => @region ? @region.name : nil,
5   - :distance => @radius } ) %>
  2 + :total_results => @total_results } ) %>
6 3  
7 4 <%= search_page_link_to_all( { :asset => params[:asset],
8 5 :category => @category }) %>
... ... @@ -13,11 +10,9 @@
13 10 <div class="has_cat_list">
14 11 <% end %>
15 12  
16   -<% cache(:action => 'assets', :asset => 'products', :category_path => params[:category_path], :query => @query, :product_category => @product_category, :region => @region, :radius => params[:radius]) do %>
17   - <% if @query.empty? %>
18   - <%= product_categories_menu(:products, @product_category, @result_ids) %>
19   - <% else %>
20   - <%= facets_menu(:products, @facets[:products]) %>
  13 +<% cache(:action => 'assets', :asset => 'products', :query => @query) do %>
  14 + <% if !@query.blank? %>
  15 + <%= facets_menu(:products, @facets) %>
21 16 <% end %>
22 17 <% end %>
23 18  
... ...