Commit da994e1f4288d41bc1f9e50b0b2bbdc1cfbafcb8
Committed by
Gabriela Navarro
1 parent
79b3cf7a
Exists in
master
and in
5 other branches
Inproves software search.
Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
5 changed files
with
68 additions
and
30 deletions
Show diff stats
lib/ext/search_controller.rb
@@ -24,6 +24,7 @@ class SearchController | @@ -24,6 +24,7 @@ class SearchController | ||
24 | def software_infos | 24 | def software_infos |
25 | @titles[:software_infos] = _("Software Catalog") | 25 | @titles[:software_infos] = _("Software Catalog") |
26 | @category_filters = [] | 26 | @category_filters = [] |
27 | + @categories = Category.all | ||
27 | 28 | ||
28 | results = filter_software_infos_list | 29 | results = filter_software_infos_list |
29 | results = results.paginate(:per_page => 24, :page => params[:page]) | 30 | results = results.paginate(:per_page => 24, :page => params[:page]) |
@@ -51,17 +52,13 @@ class SearchController | @@ -51,17 +52,13 @@ class SearchController | ||
51 | end | 52 | end |
52 | 53 | ||
53 | def filter_software_infos_list | 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 | end | 62 | end |
66 | end | 63 | end |
67 | 64 |
lib/software_info.rb
@@ -41,7 +41,8 @@ class SoftwareInfo < ActiveRecord::Base | @@ -41,7 +41,8 @@ class SoftwareInfo < ActiveRecord::Base | ||
41 | # used on find_by_contents | 41 | # used on find_by_contents |
42 | scope :like_search, lambda{ |name| | 42 | scope :like_search, lambda{ |name| |
43 | joins(:community).where( | 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 | </div> | 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 | </div> | 27 | </div> |
19 | -</div> | ||
20 | \ No newline at end of file | 28 | \ No newline at end of file |
29 | +</div> | ||
30 | +</div> |
@@ -0,0 +1,32 @@ | @@ -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 | <%= search_page_title( @titles[@asset], @category ) %> | 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 | <%= render :partial => 'results_header' %> | 5 | <%= render :partial => 'results_header' %> |
8 | 6 |