From da994e1f4288d41bc1f9e50b0b2bbdc1cfbafcb8 Mon Sep 17 00:00:00 2001 From: David Carlos Date: Thu, 15 Jan 2015 18:26:05 -0200 Subject: [PATCH] Inproves software search. --- lib/ext/search_controller.rb | 17 +++++++---------- lib/software_info.rb | 3 ++- views/search/_catalog_filter.html.erb | 42 ++++++++++++++++++++++++++---------------- views/search/_mpog_search_form.html.erb | 32 ++++++++++++++++++++++++++++++++ views/search/software_infos.html.erb | 4 +--- 5 files changed, 68 insertions(+), 30 deletions(-) create mode 100644 views/search/_mpog_search_form.html.erb diff --git a/lib/ext/search_controller.rb b/lib/ext/search_controller.rb index 819c0f5..97c367f 100644 --- a/lib/ext/search_controller.rb +++ b/lib/ext/search_controller.rb @@ -24,6 +24,7 @@ class SearchController def software_infos @titles[:software_infos] = _("Software Catalog") @category_filters = [] + @categories = Category.all results = filter_software_infos_list results = results.paginate(:per_page => 24, :page => params[:page]) @@ -51,17 +52,13 @@ class SearchController end def filter_software_infos_list - unfiltered_software_infos_list = SoftwareInfo.like_search(params[:query]) + filtered_communities_list = SoftwareInfo.like_search(params[:query]) - filtered_communities_list = [] - unfiltered_software_infos_list.each do |software| - filtered_communities_list << software.community - end - - if not params[:filter].blank? - params[:filter].split(",").each{|f| @category_filters << f.to_i} - filtered_communities_list.select! do |community| - !(community.category_ids & @category_filters).blank? + if not params[:categories].blank? + @category_filters = params[:categories].select {|c| c.to_i != 0 } + + filtered_communities_list.select! do |software| + !(software.community.category_ids & @category_filters).blank? end end diff --git a/lib/software_info.rb b/lib/software_info.rb index c972919..726b7ce 100644 --- a/lib/software_info.rb +++ b/lib/software_info.rb @@ -41,7 +41,8 @@ class SoftwareInfo < ActiveRecord::Base # used on find_by_contents scope :like_search, lambda{ |name| joins(:community).where( - "name ILIKE ? OR acronym ILIKE ?", "%#{name}%", "%#{name}%" + "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?", + "%#{name}%", "%#{name}%", "%#{name}%" ) } diff --git a/views/search/_catalog_filter.html.erb b/views/search/_catalog_filter.html.erb index cf3f6e6..bd59eba 100644 --- a/views/search/_catalog_filter.html.erb +++ b/views/search/_catalog_filter.html.erb @@ -1,19 +1,29 @@ -
-
-
-
    - <% @category_filters.each do |filter_id| %> -
  • <%= _(Category.find(filter_id).name) %> - x -
  • - <% end %> -
+
+
+
    + <% @category_filters.each do |filter_id| %> +
  • <%= _(Category.find(filter_id).name) %> + x +
  • + <% end %> +
+
+ +
+
+ <%= _('Selected options: ') %> sagdhjasgdhjagsd
-
-

- <%= _("Categories filter") %>: - <%= text_field(:software, :catalog, :id=>"software-catalog", :placeholder=>_("Type a category name here")) %> -

+
+
+
    + <% @categories.each do |category| %> +
  • + <%= labelled_check_box category.name, "categories[]", category.id %> +
  • + <% end %> +
+
-
\ No newline at end of file +
+
diff --git a/views/search/_mpog_search_form.html.erb b/views/search/_mpog_search_form.html.erb new file mode 100644 index 0000000..4e46072 --- /dev/null +++ b/views/search/_mpog_search_form.html.erb @@ -0,0 +1,32 @@ +
+ + <%= form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.path : nil ) }, + :method => 'get', :class => 'search_form' ) do %> + + <%= hidden_field_tag :display, params[:display] %> + <%= hidden_field_tag :filter, params[:filter] %> + +
+ + <%= 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')) %> +
+ + <%= render :partial => 'search_form_extra_fields' %> + <%= render :partial => 'catalog_filter' %> + + <% end %> + + <% if @empty_query %> + <% hint = environment.search_hints[@asset] %> + <% if hint and !hint.blank? %> +
<%= hint %>
+ <% end %> + <% end %> + +
+
+
diff --git a/views/search/software_infos.html.erb b/views/search/software_infos.html.erb index dbc8ffb..fb5726e 100644 --- a/views/search/software_infos.html.erb +++ b/views/search/software_infos.html.erb @@ -1,8 +1,6 @@ <%= search_page_title( @titles[@asset], @category ) %> -<%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %> - -<%= render :partial => "catalog_filter" %> +<%= render :partial => 'mpog_search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %> <%= render :partial => 'results_header' %> -- libgit2 0.21.2