Commit 01cb2ec2d35a1c59b05b5ee9926de7507eb470ae
1 parent
c3a2bee3
Exists in
master
and in
29 other branches
Fixed category index
Showing
19 changed files
with
99 additions
and
80 deletions
Show diff stats
app/helpers/search_helper.rb
@@ -65,12 +65,11 @@ module SearchHelper | @@ -65,12 +65,11 @@ module SearchHelper | ||
65 | content_tag('div', render(:partial => partial), :class => "map-or-list-search-results #{klass}") | 65 | content_tag('div', render(:partial => partial), :class => "map-or-list-search-results #{klass}") |
66 | end | 66 | end |
67 | 67 | ||
68 | - def display_filter(item, display) | ||
69 | - asset = item.class.name.downcase.pluralize.to_sym | 68 | + def display_filter(asset, display) |
70 | if display?(asset, display) | 69 | if display?(asset, display) |
71 | display | 70 | display |
72 | else | 71 | else |
73 | - item.class.default_search_display | 72 | + asset_class(asset).default_search_display |
74 | end | 73 | end |
75 | end | 74 | end |
76 | 75 |
app/views/search/_display_results.rhtml
@@ -12,15 +12,15 @@ | @@ -12,15 +12,15 @@ | ||
12 | <% end %> | 12 | <% end %> |
13 | <% end %> | 13 | <% end %> |
14 | 14 | ||
15 | + <% display = display_filter(name, params[:display]) %> | ||
15 | 16 | ||
16 | <div class="search-results-innerbox search-results-type-<%= name.to_s.singularize %> <%= 'common-profile-list-block' if [:enterprises, :people, :communities].include?(name) %>"> | 17 | <div class="search-results-innerbox search-results-type-<%= name.to_s.singularize %> <%= 'common-profile-list-block' if [:enterprises, :people, :communities].include?(name) %>"> |
17 | <ul> | 18 | <ul> |
18 | - <% search[:results].each do |hit| %> | ||
19 | - <% display = display_filter(hit, params[:display]) %> | ||
20 | - <% partial = partial_for_class(hit.class, display) %> | ||
21 | - <% variable_name = partial.gsub("#{display}_", '').to_sym %> | ||
22 | - <%= render :partial => partial, :locals => {variable_name => hit} %> | ||
23 | - <% end %> | 19 | + <% search[:results].each do |hit| %> |
20 | + <% partial = partial_for_class(hit.class, display) %> | ||
21 | + <% variable_name = partial.gsub("#{display}_", '').to_sym %> | ||
22 | + <%= render :partial => partial, :locals => {variable_name => hit} %> | ||
23 | + <% end %> | ||
24 | </ul> | 24 | </ul> |
25 | </div> | 25 | </div> |
26 | <% else %> | 26 | <% else %> |
app/views/search/_results_header.rhtml
1 | <div class="search-results-header <%= "search-no-results" if @searches[@asset].nil? or @searches[@asset].length == 0 %>"> | 1 | <div class="search-results-header <%= "search-no-results" if @searches[@asset].nil? or @searches[@asset].length == 0 %>"> |
2 | <div id='search-filter-title'><%= filter_title(@asset, @filter) %></div> | 2 | <div id='search-filter-title'><%= filter_title(@asset, @filter) %></div> |
3 | <%= display_selector(@asset, params[:display]) %> | 3 | <%= display_selector(@asset, params[:display]) %> |
4 | - <%= filter_selector(@asset, @filter)%> | 4 | + <%= filter_selector(@asset, @filter) %> |
5 | <div style="clear: both"></div> | 5 | <div style="clear: both"></div> |
6 | </div> | 6 | </div> |
app/views/search/_search_form.rhtml
@@ -6,16 +6,6 @@ | @@ -6,16 +6,6 @@ | ||
6 | <%= hidden_field_tag :display, params[:display] %> | 6 | <%= hidden_field_tag :display, params[:display] %> |
7 | <%= hidden_field_tag :filter, params[:filter] %> | 7 | <%= hidden_field_tag :filter, params[:filter] %> |
8 | 8 | ||
9 | - <% params_uri = CGI::unescape(request.request_uri) %> | ||
10 | - <% if params_uri.index('?') %> | ||
11 | - <% params_uri[(params_uri.index('?')+1)..-1].to_s.split("&").each do |part| %> | ||
12 | - <% if part.start_with? "facet" %> | ||
13 | - <% name_value = part.split("=") %> | ||
14 | - <%= hidden_field_tag name_value[0], name_value[1] %> | ||
15 | - <% end %> | ||
16 | - <% end %> | ||
17 | - <% end %> | ||
18 | - | ||
19 | <div class="search-field"> | 9 | <div class="search-field"> |
20 | <span class="formfield"> | 10 | <span class="formfield"> |
21 | <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50 %> | 11 | <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50 %> |
@@ -25,6 +15,8 @@ | @@ -25,6 +15,8 @@ | ||
25 | <%= submit_button(:search, _('Search')) %> | 15 | <%= submit_button(:search, _('Search')) %> |
26 | </div> | 16 | </div> |
27 | 17 | ||
18 | + <%= render :partial => 'search_form_extra_fields' %> | ||
19 | + | ||
28 | <% end %> | 20 | <% end %> |
29 | 21 | ||
30 | <% if @empty_query %> | 22 | <% if @empty_query %> |
@@ -0,0 +1,6 @@ | @@ -0,0 +1,6 @@ | ||
1 | +<%# | ||
2 | + This partial serves the search engine plugins to fill in any extra | ||
3 | + fields they need in the search form. The search engine plugin must define a | ||
4 | + partial named like this one and the plugin's view path will override the | ||
5 | + default view path which will render the plugin file instead of this one. | ||
6 | +%> |
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +require_dependency 'search_controller' | ||
2 | + | ||
3 | +module SolrPlugin::FacetsBrowse | ||
4 | + def self.included(base) | ||
5 | + base.send :include, InstanceMethods | ||
6 | + base.send :include, SolrPlugin::ResultsHelper | ||
7 | + end | ||
8 | + | ||
9 | + module InstanceMethods | ||
10 | + def facets_browse | ||
11 | + @asset = params[:asset_key].to_sym | ||
12 | + @asset_class = asset_class(@asset) | ||
13 | + | ||
14 | + @facets_only = true | ||
15 | + send(@asset) | ||
16 | + set_facets_variables | ||
17 | + | ||
18 | + @facet = @asset_class.map_facets_for(environment).find { |facet| facet[:id] == params[:facet_id] } | ||
19 | + raise 'Facet not found' if @facet.nil? | ||
20 | + | ||
21 | + render :layout => false | ||
22 | + end | ||
23 | + end | ||
24 | +end | ||
25 | + | ||
26 | +SearchController.send(:include, SolrPlugin::FacetsBrowse) |
plugins/solr/lib/solr_plugin.rb
@@ -12,8 +12,13 @@ class SolrPlugin < Noosfero::Plugin | @@ -12,8 +12,13 @@ class SolrPlugin < Noosfero::Plugin | ||
12 | _("Uses Solr as search engine.") | 12 | _("Uses Solr as search engine.") |
13 | end | 13 | end |
14 | 14 | ||
15 | + def stylesheet? | ||
16 | + true | ||
17 | + end | ||
18 | + | ||
15 | def find_by_contents(klass, query, paginate_options={}, options={}) | 19 | def find_by_contents(klass, query, paginate_options={}, options={}) |
16 | category = options.delete(:category) | 20 | category = options.delete(:category) |
21 | + filter = options.delete(:filter) | ||
17 | solr_options = solr_options(class_asset(klass), category) | 22 | solr_options = solr_options(class_asset(klass), category) |
18 | user = context.respond_to?(:user) ? context.send(:user) : nil | 23 | user = context.respond_to?(:user) ? context.send(:user) : nil |
19 | solr_options.merge!(products_options(user)) if klass == Product && empty_query?(query, category) | 24 | solr_options.merge!(products_options(user)) if klass == Product && empty_query?(query, category) |
plugins/solr/lib/solr_plugin/results_helper.rb
@@ -4,7 +4,7 @@ class SolrPlugin < Noosfero::Plugin | @@ -4,7 +4,7 @@ class SolrPlugin < Noosfero::Plugin | ||
4 | asset.to_s.singularize.camelize.constantize | 4 | asset.to_s.singularize.camelize.constantize |
5 | end | 5 | end |
6 | 6 | ||
7 | - def set_results_variables | 7 | + def set_facets_variables |
8 | @facets = @searches[@asset][:facets] | 8 | @facets = @searches[@asset][:facets] |
9 | @all_facets = @searches[@asset][:all_facets] | 9 | @all_facets = @searches[@asset][:all_facets] |
10 | end | 10 | end |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +.controller-search #search-column-right .search-field .formfield { | ||
2 | + width: 594px; | ||
3 | + display: inline-block; | ||
4 | +} | ||
5 | + | ||
6 | +#search-column-right .search-customize-options { | ||
7 | + float: left; | ||
8 | + margin-top: 23px; | ||
9 | + margin-left: 0; | ||
10 | +} | ||
11 | + | ||
12 | +#search-column-right .search-results-box .vcard { | ||
13 | + margin: 4.5px 8px; | ||
14 | +} |
@@ -0,0 +1,8 @@ | @@ -0,0 +1,8 @@ | ||
1 | +<% results = @asset_class.map_facet_results(@facet, params[:facet], @facets, @all_facets) %> | ||
2 | + | ||
3 | +<% array = [] %> | ||
4 | +<% @asset_class.facet_result_sort(@facet, results, :alphabetically).each do |id, label, count| %> | ||
5 | + <% array << {:id => id, :name => facet_link_html(@facet, params.merge(:controller => 'search', :action => @asset), id, label, count)} %> | ||
6 | +<% end %> | ||
7 | + | ||
8 | +<%= facet_javascript('facet-input-'+@facet[:id].to_s, @facet, array) %> |
plugins/solr/views/search/_facets_menu.html.erb
@@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
23 | 23 | ||
24 | <% if facet_count > less_options_limit %> | 24 | <% if facet_count > less_options_limit %> |
25 | <%= link_to_function _("Options"), | 25 | <%= link_to_function _("Options"), |
26 | - "facet_options_toggle('#{facet[:id].to_s}', '#{url_for(params.merge(:controller => 'solr_plugin_controller' :action => 'facets_browse', :facet_id => facet[:id], :asset => @asset, :escape => false))}'); " + | 26 | + "facet_options_toggle('#{facet[:id].to_s}', '#{url_for(params.merge(:action => 'facets_browse', :facet_id => facet[:id], :asset_key => @asset, :escape => false))}'); " + |
27 | "jQuery(this).toggleClass('facet-less-options')", :class => "facet-options-toggle" %> | 27 | "jQuery(this).toggleClass('facet-less-options')", :class => "facet-options-toggle" %> |
28 | <br /> | 28 | <br /> |
29 | <% end %> | 29 | <% end %> |
plugins/solr/views/search/_results.html.erb
1 | <%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %> | 1 | <%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %> |
2 | <%= render :partial => 'results_header' %> | 2 | <%= render :partial => 'results_header' %> |
3 | 3 | ||
4 | -<%= display_results(@asset) %> | 4 | +<%= display_results(@searches, @asset) %> |
5 | <% if params[:display] != 'map' %> | 5 | <% if params[:display] != 'map' %> |
6 | <%= pagination_links @searches[@asset][:results] %> | 6 | <%= pagination_links @searches[@asset][:results] %> |
7 | <% end %> | 7 | <% end %> |
plugins/solr/views/search/_results_header.html.erb
@@ -14,9 +14,9 @@ | @@ -14,9 +14,9 @@ | ||
14 | <%= order_by(@asset) if params[:display] != 'map' %> | 14 | <%= order_by(@asset) if params[:display] != 'map' %> |
15 | </div> | 15 | </div> |
16 | <% else %> | 16 | <% else %> |
17 | - <div id='search-filter-title'><%= @filter_title if @filter_title %></div> | 17 | + <div id='search-filter-title'><%= filter_title(@asset, @filter) %></div> |
18 | <% end %> | 18 | <% end %> |
19 | - <% float = !@empty_query && params[:display] == 'list' ? 'left' : 'right' %> | ||
20 | - <%= display_filter(@asset, params[:display], float) if map_capable?(@asset) %> | 19 | + <%= display_selector(@asset, params[:display]) %> |
20 | + <%= filter_selector(@asset, @filter) if @empty_query && params[:display] != 'map' %> | ||
21 | <div style="clear: both"></div> | 21 | <div style="clear: both"></div> |
22 | </div> | 22 | </div> |
plugins/solr/views/search/_search_form.rhtml
@@ -1,37 +0,0 @@ | @@ -1,37 +0,0 @@ | ||
1 | -<div class='search-form'> | ||
2 | - | ||
3 | - <% form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, | ||
4 | - :method => 'get', :class => 'search_form' ) do %> | ||
5 | - | ||
6 | - <%= hidden_field_tag :display, params[:display] %> | ||
7 | - | ||
8 | - <% params_uri = CGI::unescape(request.request_uri) %> | ||
9 | - <% if params_uri.index('?') %> | ||
10 | - <% params_uri[(params_uri.index('?')+1)..-1].to_s.split("&").each do |part| %> | ||
11 | - <% if part.start_with? "facet" %> | ||
12 | - <% name_value = part.split("=") %> | ||
13 | - <%= hidden_field_tag name_value[0], name_value[1] %> | ||
14 | - <% end %> | ||
15 | - <% end %> | ||
16 | - <% end %> | ||
17 | - | ||
18 | - <div class="search-field"> | ||
19 | - <span class="formfield"> | ||
20 | - <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50 %> | ||
21 | - <%= javascript_tag "jQuery('#search-input').attr('title', \"#{hint}\").hint()" if defined?(hint) %> | ||
22 | - </span> | ||
23 | - | ||
24 | - <%= submit_button(:search, _('Search')) %> | ||
25 | - </div> | ||
26 | - | ||
27 | - <% end %> | ||
28 | - | ||
29 | - <% if @empty_query %> | ||
30 | - <% hint = environment.search_hints[@asset] %> | ||
31 | - <% if hint and !hint.blank? %> | ||
32 | - <div class="search-hint"><%= hint %></div> | ||
33 | - <% end %> | ||
34 | - <% end %> | ||
35 | - | ||
36 | - <div style="clear: both"></div> | ||
37 | -</div> |
plugins/solr/views/search/_search_form_extra_fields.html.erb
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +<% params_uri = CGI::unescape(request.request_uri) %> | ||
2 | +<% if params_uri.index('?') %> | ||
3 | + <% params_uri[(params_uri.index('?')+1)..-1].to_s.split("&").each do |part| %> | ||
4 | + <% if part.start_with? "facet" %> | ||
5 | + <% name_value = part.split("=") %> | ||
6 | + <%= hidden_field_tag name_value[0], name_value[1] %> | ||
7 | + <% end %> | ||
8 | + <% end %> | ||
9 | +<% end %> |
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +<% extend SolrPlugin::ResultsHelper %> | ||
2 | + | ||
3 | +<% results = @asset_class.map_facet_results(@facet, params[:facet], @facets, @all_facets) %> | ||
4 | + | ||
5 | +<% array = [] %> | ||
6 | +<% @asset_class.facet_result_sort(@facet, results, :alphabetically).each do |id, label, count| %> | ||
7 | + <% array << {:id => id, :name => facet_link_html(@facet, params.merge(:controller => 'search', :action => @asset), id, label, count)} %> | ||
8 | +<% end %> | ||
9 | + | ||
10 | +<%= facet_javascript('facet-input-'+@facet[:id].to_s, @facet, array) %> |
plugins/solr/views/search/search_page.html.erb
plugins/solr/views/solr_plugin_public/facets_browse.rhtml
@@ -1,14 +0,0 @@ | @@ -1,14 +0,0 @@ | ||
1 | -<% | ||
2 | - # TODO This view was created to remove the solr dependencies from | ||
3 | - # noosfero views. All code here might not be working as they're | ||
4 | - # supposed to. Everything must be reviewed! | ||
5 | -%> | ||
6 | - | ||
7 | -<% results = @asset_class.map_facet_results(@facet, params[:facet], @facets, @all_facets) %> | ||
8 | - | ||
9 | -<% array = [] %> | ||
10 | -<% @asset_class.facet_result_sort(@facet, results, :alphabetically).each do |id, label, count| %> | ||
11 | - <% array << {:id => id, :name => facet_link_html(@facet, params.merge(:controller => 'search', :action => @asset), id, label, count)} %> | ||
12 | -<% end %> | ||
13 | - | ||
14 | -<%= facet_javascript('facet-input-'+@facet[:id].to_s, @facet, array) %> |
public/stylesheets/search.css
@@ -14,9 +14,10 @@ | @@ -14,9 +14,10 @@ | ||
14 | 14 | ||
15 | .controller-search #content form input.button.submit { | 15 | .controller-search #content form input.button.submit { |
16 | display: inline-block; | 16 | display: inline-block; |
17 | - height: 25px; | ||
18 | - max-height: 25px; | 17 | + height: 27px; |
18 | + max-height: 27px; | ||
19 | width: 87px; | 19 | width: 87px; |
20 | + margin-bottom: 1px; | ||
20 | } | 21 | } |
21 | .controller-search .current-cat-path { | 22 | .controller-search .current-cat-path { |
22 | padding-left: 25px; | 23 | padding-left: 25px; |