diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 3b08ced..6e5534a 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -65,12 +65,11 @@ module SearchHelper content_tag('div', render(:partial => partial), :class => "map-or-list-search-results #{klass}") end - def display_filter(item, display) - asset = item.class.name.downcase.pluralize.to_sym + def display_filter(asset, display) if display?(asset, display) display else - item.class.default_search_display + asset_class(asset).default_search_display end end diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml index 5d9d8a4..c95be59 100644 --- a/app/views/search/_display_results.rhtml +++ b/app/views/search/_display_results.rhtml @@ -12,15 +12,15 @@ <% end %> <% end %> + <% display = display_filter(name, params[:display]) %>
<% else %> diff --git a/app/views/search/_results_header.rhtml b/app/views/search/_results_header.rhtml index 6bc006e..39fed43 100644 --- a/app/views/search/_results_header.rhtml +++ b/app/views/search/_results_header.rhtml @@ -1,6 +1,6 @@
">
<%= filter_title(@asset, @filter) %>
<%= display_selector(@asset, params[:display]) %> - <%= filter_selector(@asset, @filter)%> + <%= filter_selector(@asset, @filter) %>
diff --git a/app/views/search/_search_form.rhtml b/app/views/search/_search_form.rhtml index 72cd95e..359ed3d 100644 --- a/app/views/search/_search_form.rhtml +++ b/app/views/search/_search_form.rhtml @@ -6,16 +6,6 @@ <%= hidden_field_tag :display, params[:display] %> <%= hidden_field_tag :filter, params[:filter] %> - <% params_uri = CGI::unescape(request.request_uri) %> - <% if params_uri.index('?') %> - <% params_uri[(params_uri.index('?')+1)..-1].to_s.split("&").each do |part| %> - <% if part.start_with? "facet" %> - <% name_value = part.split("=") %> - <%= hidden_field_tag name_value[0], name_value[1] %> - <% end %> - <% end %> - <% end %> -
<%= text_field_tag 'query', @query, :id => 'search-input', :size => 50 %> @@ -25,6 +15,8 @@ <%= submit_button(:search, _('Search')) %>
+ <%= render :partial => 'search_form_extra_fields' %> + <% end %> <% if @empty_query %> diff --git a/app/views/search/_search_form_extra_fields.html.erb b/app/views/search/_search_form_extra_fields.html.erb new file mode 100644 index 0000000..d557588 --- /dev/null +++ b/app/views/search/_search_form_extra_fields.html.erb @@ -0,0 +1,6 @@ +<%# + This partial serves the search engine plugins to fill in any extra + fields they need in the search form. The search engine plugin must define a + partial named like this one and the plugin's view path will override the + default view path which will render the plugin file instead of this one. +%> diff --git a/plugins/solr/lib/ext/facets_browse.rb b/plugins/solr/lib/ext/facets_browse.rb new file mode 100644 index 0000000..f5de95e --- /dev/null +++ b/plugins/solr/lib/ext/facets_browse.rb @@ -0,0 +1,26 @@ +require_dependency 'search_controller' + +module SolrPlugin::FacetsBrowse + def self.included(base) + base.send :include, InstanceMethods + base.send :include, SolrPlugin::ResultsHelper + end + + module InstanceMethods + def facets_browse + @asset = params[:asset_key].to_sym + @asset_class = asset_class(@asset) + + @facets_only = true + send(@asset) + set_facets_variables + + @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 + end +end + +SearchController.send(:include, SolrPlugin::FacetsBrowse) diff --git a/plugins/solr/lib/solr_plugin.rb b/plugins/solr/lib/solr_plugin.rb index c814dc5..e7cd6dd 100644 --- a/plugins/solr/lib/solr_plugin.rb +++ b/plugins/solr/lib/solr_plugin.rb @@ -12,8 +12,13 @@ class SolrPlugin < Noosfero::Plugin _("Uses Solr as search engine.") end + def stylesheet? + true + end + def find_by_contents(klass, query, paginate_options={}, options={}) category = options.delete(:category) + filter = options.delete(:filter) solr_options = solr_options(class_asset(klass), category) user = context.respond_to?(:user) ? context.send(:user) : nil solr_options.merge!(products_options(user)) if klass == Product && empty_query?(query, category) diff --git a/plugins/solr/lib/solr_plugin/results_helper.rb b/plugins/solr/lib/solr_plugin/results_helper.rb index c5d114a..5555236 100644 --- a/plugins/solr/lib/solr_plugin/results_helper.rb +++ b/plugins/solr/lib/solr_plugin/results_helper.rb @@ -4,7 +4,7 @@ class SolrPlugin < Noosfero::Plugin asset.to_s.singularize.camelize.constantize end - def set_results_variables + def set_facets_variables @facets = @searches[@asset][:facets] @all_facets = @searches[@asset][:all_facets] end diff --git a/plugins/solr/public/style.css b/plugins/solr/public/style.css new file mode 100644 index 0000000..29acf83 --- /dev/null +++ b/plugins/solr/public/style.css @@ -0,0 +1,14 @@ +.controller-search #search-column-right .search-field .formfield { + width: 594px; + display: inline-block; +} + +#search-column-right .search-customize-options { + float: left; + margin-top: 23px; + margin-left: 0; +} + +#search-column-right .search-results-box .vcard { + margin: 4.5px 8px; +} diff --git a/plugins/solr/views/facets_browse.html.erb b/plugins/solr/views/facets_browse.html.erb new file mode 100644 index 0000000..7178788 --- /dev/null +++ b/plugins/solr/views/facets_browse.html.erb @@ -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/plugins/solr/views/search/_facets_menu.html.erb b/plugins/solr/views/search/_facets_menu.html.erb index cd6ac2c..56cfb4a 100644 --- a/plugins/solr/views/search/_facets_menu.html.erb +++ b/plugins/solr/views/search/_facets_menu.html.erb @@ -23,7 +23,7 @@ <% if facet_count > less_options_limit %> <%= link_to_function _("Options"), - "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))}'); " + + "facet_options_toggle('#{facet[:id].to_s}', '#{url_for(params.merge(:action => 'facets_browse', :facet_id => facet[:id], :asset_key => @asset, :escape => false))}'); " + "jQuery(this).toggleClass('facet-less-options')", :class => "facet-options-toggle" %>
<% end %> diff --git a/plugins/solr/views/search/_results.html.erb b/plugins/solr/views/search/_results.html.erb index f96e7fa..bed01c9 100644 --- a/plugins/solr/views/search/_results.html.erb +++ b/plugins/solr/views/search/_results.html.erb @@ -1,7 +1,7 @@ <%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %> <%= render :partial => 'results_header' %> -<%= display_results(@asset) %> +<%= display_results(@searches, @asset) %> <% if params[:display] != 'map' %> <%= pagination_links @searches[@asset][:results] %> <% end %> diff --git a/plugins/solr/views/search/_results_header.html.erb b/plugins/solr/views/search/_results_header.html.erb index 280e2f3..7d8f428 100644 --- a/plugins/solr/views/search/_results_header.html.erb +++ b/plugins/solr/views/search/_results_header.html.erb @@ -14,9 +14,9 @@ <%= order_by(@asset) if params[:display] != 'map' %> <% else %> -
<%= @filter_title if @filter_title %>
+
<%= filter_title(@asset, @filter) %>
<% end %> - <% float = !@empty_query && params[:display] == 'list' ? 'left' : 'right' %> - <%= display_filter(@asset, params[:display], float) if map_capable?(@asset) %> + <%= display_selector(@asset, params[:display]) %> + <%= filter_selector(@asset, @filter) if @empty_query && params[:display] != 'map' %>
diff --git a/plugins/solr/views/search/_search_form.rhtml b/plugins/solr/views/search/_search_form.rhtml deleted file mode 100644 index e298996..0000000 --- a/plugins/solr/views/search/_search_form.rhtml +++ /dev/null @@ -1,37 +0,0 @@ -
- - <% form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, - :method => 'get', :class => 'search_form' ) do %> - - <%= hidden_field_tag :display, params[:display] %> - - <% params_uri = CGI::unescape(request.request_uri) %> - <% if params_uri.index('?') %> - <% params_uri[(params_uri.index('?')+1)..-1].to_s.split("&").each do |part| %> - <% if part.start_with? "facet" %> - <% name_value = part.split("=") %> - <%= hidden_field_tag name_value[0], name_value[1] %> - <% end %> - <% end %> - <% end %> - -
- - <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50 %> - <%= javascript_tag "jQuery('#search-input').attr('title', \"#{hint}\").hint()" if defined?(hint) %> - - - <%= submit_button(:search, _('Search')) %> -
- - <% end %> - - <% if @empty_query %> - <% hint = environment.search_hints[@asset] %> - <% if hint and !hint.blank? %> -
<%= hint %>
- <% end %> - <% end %> - -
-
diff --git a/plugins/solr/views/search/_search_form_extra_fields.html.erb b/plugins/solr/views/search/_search_form_extra_fields.html.erb new file mode 100644 index 0000000..6de54c9 --- /dev/null +++ b/plugins/solr/views/search/_search_form_extra_fields.html.erb @@ -0,0 +1,9 @@ +<% params_uri = CGI::unescape(request.request_uri) %> +<% if params_uri.index('?') %> + <% params_uri[(params_uri.index('?')+1)..-1].to_s.split("&").each do |part| %> + <% if part.start_with? "facet" %> + <% name_value = part.split("=") %> + <%= hidden_field_tag name_value[0], name_value[1] %> + <% end %> + <% end %> +<% end %> diff --git a/plugins/solr/views/search/facets_browse.html.erb b/plugins/solr/views/search/facets_browse.html.erb new file mode 100644 index 0000000..54c55c2 --- /dev/null +++ b/plugins/solr/views/search/facets_browse.html.erb @@ -0,0 +1,10 @@ +<% extend SolrPlugin::ResultsHelper %> + +<% 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/plugins/solr/views/search/search_page.html.erb b/plugins/solr/views/search/search_page.html.erb index 8ee945d..a2a8539 100644 --- a/plugins/solr/views/search/search_page.html.erb +++ b/plugins/solr/views/search/search_page.html.erb @@ -1,5 +1,5 @@ <% extend SolrPlugin::ResultsHelper %> -<% set_results_variables %> +<% set_facets_variables %> <%= search_page_title( @titles[@asset], @category ) %> diff --git a/plugins/solr/views/solr_plugin_public/facets_browse.rhtml b/plugins/solr/views/solr_plugin_public/facets_browse.rhtml deleted file mode 100644 index 946d234..0000000 --- a/plugins/solr/views/solr_plugin_public/facets_browse.rhtml +++ /dev/null @@ -1,14 +0,0 @@ -<% - # TODO This view was created to remove the solr dependencies from - # noosfero views. All code here might not be working as they're - # supposed to. Everything must be reviewed! -%> - -<% 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/public/stylesheets/search.css b/public/stylesheets/search.css index 3fe9762..e856ea6 100644 --- a/public/stylesheets/search.css +++ b/public/stylesheets/search.css @@ -14,9 +14,10 @@ .controller-search #content form input.button.submit { display: inline-block; - height: 25px; - max-height: 25px; + height: 27px; + max-height: 27px; width: 87px; + margin-bottom: 1px; } .controller-search .current-cat-path { padding-left: 25px; -- libgit2 0.21.2