Commit b0f53e17ed561e9e709a0ea60ae7fa9d9a84cff7

Authored by Luciano Prestes
Committed by Gabriela Navarro
1 parent b6f01b8f
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

Add languages and databases into software search

- Missing community description

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
lib/database_description.rb
1 1 class DatabaseDescription < ActiveRecord::Base
  2 +
  3 + SEARCHABLE_SOFTWARE_FIELDS = {
  4 + :name => 1
  5 + }
  6 +
2 7 attr_accessible :name
3 8  
4 9 has_many :software_databases
... ...
lib/ext/community.rb
... ... @@ -5,7 +5,7 @@ class Community
5 5 SEARCHABLE_SOFTWARE_FIELDS = {
6 6 :name => 1,
7 7 :identifier => 2,
8   - :nickname => 3,
  8 + :nickname => 3
9 9 }
10 10  
11 11 attr_accessible :visible
... ...
lib/programming_language.rb
1 1 class ProgrammingLanguage < ActiveRecord::Base
  2 +
  3 + SEARCHABLE_SOFTWARE_FIELDS = {
  4 + :name => 1
  5 + }
  6 +
2 7 attr_accessible :name
3 8  
4 9 validates_presence_of :name
... ...
lib/software_info.rb
... ... @@ -6,6 +6,13 @@ class SoftwareInfo &lt; ActiveRecord::Base
6 6 :finality => 2,
7 7 }
8 8  
  9 + SEARCHABLE_SOFTWARE_CLASSES = [
  10 + SoftwareInfo,
  11 + Community,
  12 + ProgrammingLanguage,
  13 + DatabaseDescription
  14 + ]
  15 +
9 16 scope :search_by_query, lambda {|query = ""|
10 17 filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|')
11 18 search_fields = SoftwareInfo.pg_search_plugin_fields
... ... @@ -13,15 +20,18 @@ class SoftwareInfo &lt; ActiveRecord::Base
13 20 if query.empty?
14 21 SoftwareInfo.all
15 22 else
16   - joins(:community).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')")
  23 + includes(:community, :programming_languages, :database_descriptions).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')")
17 24 end
18 25 }
19 26  
20 27 def self.pg_search_plugin_fields
21   - searchable_fields = Community::SEARCHABLE_SOFTWARE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{Community.table_name}.#{f}, '')"}.join(" || ' ' || ")
22   - searchable_fields += " || ' ' || "
23   - searchable_fields += self::SEARCHABLE_SOFTWARE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{table_name}.#{f}, '')"}.join(" || ' ' || ")
  28 + SEARCHABLE_SOFTWARE_CLASSES.collect { |one_class|
  29 + self.get_searchable_fields(one_class)
  30 + }.join(" || ' ' || ")
  31 + end
24 32  
  33 + def self.get_searchable_fields one_class
  34 + searchable_fields = one_class::SEARCHABLE_SOFTWARE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{one_class.table_name}.#{f}, '')"}.join(" || ' ' || ")
25 35 searchable_fields
26 36 end
27 37  
... ...
views/search/_full_community.html.erb
... ... @@ -10,7 +10,7 @@
10 10 <div class="search-community-content-block">
11 11 <span>
12 12 <% link_name = software.acronym.blank? ? community.name : "#{software.acronym} - #{community.name}" %>
13   - <h4 class="search-content-result">
  13 + <h4>
14 14 <%= link_to_homepage(link_name, community.identifier) %>
15 15 </h4>
16 16 </span>
... ...