Commit 553ee63f0e0c6915a24de7f2493ff961de79d375
1 parent
6129c293
Exists in
sisp_improvements
Multi env on SoftwareInfo scope search_by_query
Signed-off-by: Tallys Martins <tallysmartins@yahoo.com.br>
Showing
2 changed files
with
5 additions
and
4 deletions
Show diff stats
src/noosfero-spb/software_communities/lib/ext/search_controller.rb
| ... | ... | @@ -89,10 +89,11 @@ class SearchController |
| 89 | 89 | params[:query] ||= "" |
| 90 | 90 | visible_communities = visible_profiles(Community) |
| 91 | 91 | |
| 92 | - filtered_software_list = SoftwareInfo.search_by_query(params[:query]) | |
| 92 | + filtered_software_list = SoftwareInfo.search_by_query(params[:query], environment) | |
| 93 | 93 | |
| 94 | 94 | if params[:only_softwares] |
| 95 | 95 | params[:only_softwares].collect!{ |software_name| software_name.to_slug } |
| 96 | + #FIX-ME: This query is not appropriate | |
| 96 | 97 | filtered_software_list = SoftwareInfo.all.select{ |s| params[:only_softwares].include?(s.identifier) } |
| 97 | 98 | @public_software_selected = false |
| 98 | 99 | end | ... | ... |
src/noosfero-spb/software_communities/lib/software_info.rb
| ... | ... | @@ -13,15 +13,15 @@ class SoftwareInfo < ActiveRecord::Base |
| 13 | 13 | DatabaseDescription |
| 14 | 14 | ] |
| 15 | 15 | |
| 16 | - scope :search_by_query, lambda { |query = ""| | |
| 16 | + scope :search_by_query, lambda { |query = "", env = Environment.default| | |
| 17 | 17 | filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') |
| 18 | 18 | search_fields = SoftwareInfo.pg_search_plugin_fields |
| 19 | 19 | |
| 20 | 20 | if query.empty? |
| 21 | - SoftwareInfo.joins(:community).where("profiles.visible = ?", true) | |
| 21 | + SoftwareInfo.joins(:community).where("profiles.visible = ? AND environment_id = ? ", true, env.id) | |
| 22 | 22 | else |
| 23 | 23 | searchable_software_objects = SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES) |
| 24 | - includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true) | |
| 24 | + includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ? AND environment_id = ?", true, env.id) | |
| 25 | 25 | end |
| 26 | 26 | } |
| 27 | 27 | ... | ... |