Commit 4a0ed4755e85562be9ef79604c73e3c6c2fb11ac
1 parent
c1d16ff7
Exists in
master
and in
5 other branches
Search by acronym in software_infos search
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
2 changed files
with
16 additions
and
8 deletions
Show diff stats
lib/ext/search_controller.rb
| ... | ... | @@ -23,13 +23,7 @@ class SearchController |
| 23 | 23 | @titles[:software_infos] = _("Software Catalog") |
| 24 | 24 | @category_filters = [] |
| 25 | 25 | |
| 26 | - if params[:filter].blank? | |
| 27 | - results = filter_communities_list{|community| community.software?} | |
| 28 | - else | |
| 29 | - params[:filter].split(",").each{|f| @category_filters << f.to_i} | |
| 30 | - results = filter_communities_list{|community| community.software? && !(community.category_ids & @category_filters).blank?} | |
| 31 | - end | |
| 32 | - | |
| 26 | + results = filter_software_infos_list | |
| 33 | 27 | results = results.paginate(:per_page => 24, :page => params[:page]) |
| 34 | 28 | @searches[@asset] = {:results => results} |
| 35 | 29 | @search = results |
| ... | ... | @@ -50,4 +44,18 @@ class SearchController |
| 50 | 44 | end |
| 51 | 45 | communities_list |
| 52 | 46 | end |
| 47 | + | |
| 48 | + def filter_software_infos_list | |
| 49 | + unfiltered_software_infos_list = SoftwareInfo.like_search(params[:query]) | |
| 50 | + | |
| 51 | + filtered_communities_list = [] | |
| 52 | + unfiltered_software_infos_list.each{|software| filtered_communities_list << software.community} | |
| 53 | + | |
| 54 | + if not params[:filter].blank? | |
| 55 | + params[:filter].split(",").each{|f| @category_filters << f.to_i} | |
| 56 | + filtered_communities_list.select!{|community| !(community.category_ids & @category_filters).blank?} | |
| 57 | + end | |
| 58 | + | |
| 59 | + filtered_communities_list | |
| 60 | + end | |
| 53 | 61 | end | ... | ... |
lib/software_info.rb
| ... | ... | @@ -31,7 +31,7 @@ class SoftwareInfo < ActiveRecord::Base |
| 31 | 31 | |
| 32 | 32 | # used on find_by_contents |
| 33 | 33 | scope :like_search, lambda{ |name| |
| 34 | - joins(:community).where("name ilike ?", "%#{name}%") | |
| 34 | + joins(:community).where("name ILIKE ? OR acronym ILIKE ?", "%#{name}%", "%#{name}%") | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | scope :search, lambda { |name="", database_description_id = "", | ... | ... |