Commit da994e1f4288d41bc1f9e50b0b2bbdc1cfbafcb8

Authored by David Silva
Committed by Gabriela Navarro
1 parent 79b3cf7a
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Inproves software search.

Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
lib/ext/search_controller.rb
... ... @@ -24,6 +24,7 @@ class SearchController
24 24 def software_infos
25 25 @titles[:software_infos] = _("Software Catalog")
26 26 @category_filters = []
  27 + @categories = Category.all
27 28  
28 29 results = filter_software_infos_list
29 30 results = results.paginate(:per_page => 24, :page => params[:page])
... ... @@ -51,17 +52,13 @@ class SearchController
51 52 end
52 53  
53 54 def filter_software_infos_list
54   - unfiltered_software_infos_list = SoftwareInfo.like_search(params[:query])
  55 + filtered_communities_list = SoftwareInfo.like_search(params[:query])
55 56  
56   - filtered_communities_list = []
57   - unfiltered_software_infos_list.each do |software|
58   - filtered_communities_list << software.community
59   - end
60   -
61   - if not params[:filter].blank?
62   - params[:filter].split(",").each{|f| @category_filters << f.to_i}
63   - filtered_communities_list.select! do |community|
64   - !(community.category_ids & @category_filters).blank?
  57 + if not params[:categories].blank?
  58 + @category_filters = params[:categories].select {|c| c.to_i != 0 }
  59 +
  60 + filtered_communities_list.select! do |software|
  61 + !(software.community.category_ids & @category_filters).blank?
65 62 end
66 63 end
67 64  
... ...
lib/software_info.rb
... ... @@ -41,7 +41,8 @@ class SoftwareInfo &lt; ActiveRecord::Base
41 41 # used on find_by_contents
42 42 scope :like_search, lambda{ |name|
43 43 joins(:community).where(
44   - "name ILIKE ? OR acronym ILIKE ?", "%#{name}%", "%#{name}%"
  44 + "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?",
  45 + "%#{name}%", "%#{name}%", "%#{name}%"
45 46 )
46 47 }
47 48  
... ...
views/search/_catalog_filter.html.erb
1   -<div>
2   - <div id="catalog-list">
3   - <br>
4   - <ul>
5   - <% @category_filters.each do |filter_id| %>
6   - <li class="category_box"> <%= _(Category.find(filter_id).name) %>
7   - <span class="catalog-remove-item" data-id="<%= filter_id %>" >x</span>
8   - </li>
9   - <% end %>
10   - </ul>
  1 +<div id="catalog-list">
  2 +<br>
  3 +<ul>
  4 + <% @category_filters.each do |filter_id| %>
  5 + <li class="category_box"> <%= _(Category.find(filter_id).name) %>
  6 + <span class="catalog-remove-item" data-id="<%= filter_id %>" >x</span>
  7 + </li>
  8 + <% end %>
  9 +</ul>
  10 +</div>
  11 +
  12 +<div id="catalog-filter">
  13 + <div id='selected-options'>
  14 + <span><%= _('Selected options: ') %> sagdhjasgdhjagsd</span>
11 15 </div>
12 16  
13   - <div id="catalog-filter">
14   - <h4>
15   - <span><%= _("Categories filter") %>:</span>
16   - <%= text_field(:software, :catalog, :id=>"software-catalog", :placeholder=>_("Type a category name here")) %>
17   - </h4>
  17 + <div id='categories'>
  18 + <div id='categories-left'>
  19 + <ul>
  20 + <% @categories.each do |category| %>
  21 + <li>
  22 + <%= labelled_check_box category.name, "categories[]", category.id %>
  23 + </li>
  24 + <% end %>
  25 + </ul>
  26 + </div>
18 27 </div>
19   -</div>
20 28 \ No newline at end of file
  29 +</div>
  30 +</div>
... ...
views/search/_mpog_search_form.html.erb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +<div class='search-form'>
  2 +
  3 + <%= form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.path : nil ) },
  4 + :method => 'get', :class => 'search_form' ) do %>
  5 +
  6 + <%= hidden_field_tag :display, params[:display] %>
  7 + <%= hidden_field_tag :filter, params[:filter] %>
  8 +
  9 + <div class="search-field">
  10 + <span class="formfield">
  11 + <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50 %>
  12 + <%= javascript_tag "jQuery('#search-input').attr('title', \"#{hint}\").hint()" if defined?(hint) %>
  13 + </span>
  14 +
  15 + <%= submit_button(:search, _('Search')) %>
  16 + </div>
  17 +
  18 + <%= render :partial => 'search_form_extra_fields' %>
  19 + <%= render :partial => 'catalog_filter' %>
  20 +
  21 + <% end %>
  22 +
  23 + <% if @empty_query %>
  24 + <% hint = environment.search_hints[@asset] %>
  25 + <% if hint and !hint.blank? %>
  26 + <div class="search-hint"><%= hint %></div>
  27 + <% end %>
  28 + <% end %>
  29 +
  30 + <div style="clear: both"></div>
  31 +</div>
  32 +<div>
... ...
views/search/software_infos.html.erb
1 1 <%= search_page_title( @titles[@asset], @category ) %>
2 2  
3   -<%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %>
4   -
5   -<%= render :partial => "catalog_filter" %>
  3 +<%= render :partial => 'mpog_search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %>
6 4  
7 5 <%= render :partial => 'results_header' %>
8 6  
... ...