Commit b0f53e17ed561e9e709a0ea60ae7fa9d9a84cff7

Authored by Luciano Prestes
Committed by Gabriela Navarro
1 parent b6f01b8f

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 class DatabaseDescription < ActiveRecord::Base 1 class DatabaseDescription < ActiveRecord::Base
  2 +
  3 + SEARCHABLE_SOFTWARE_FIELDS = {
  4 + :name => 1
  5 + }
  6 +
2 attr_accessible :name 7 attr_accessible :name
3 8
4 has_many :software_databases 9 has_many :software_databases
lib/ext/community.rb
@@ -5,7 +5,7 @@ class Community @@ -5,7 +5,7 @@ class Community
5 SEARCHABLE_SOFTWARE_FIELDS = { 5 SEARCHABLE_SOFTWARE_FIELDS = {
6 :name => 1, 6 :name => 1,
7 :identifier => 2, 7 :identifier => 2,
8 - :nickname => 3, 8 + :nickname => 3
9 } 9 }
10 10
11 attr_accessible :visible 11 attr_accessible :visible
lib/programming_language.rb
1 class ProgrammingLanguage < ActiveRecord::Base 1 class ProgrammingLanguage < ActiveRecord::Base
  2 +
  3 + SEARCHABLE_SOFTWARE_FIELDS = {
  4 + :name => 1
  5 + }
  6 +
2 attr_accessible :name 7 attr_accessible :name
3 8
4 validates_presence_of :name 9 validates_presence_of :name
lib/software_info.rb
@@ -6,6 +6,13 @@ class SoftwareInfo &lt; ActiveRecord::Base @@ -6,6 +6,13 @@ class SoftwareInfo &lt; ActiveRecord::Base
6 :finality => 2, 6 :finality => 2,
7 } 7 }
8 8
  9 + SEARCHABLE_SOFTWARE_CLASSES = [
  10 + SoftwareInfo,
  11 + Community,
  12 + ProgrammingLanguage,
  13 + DatabaseDescription
  14 + ]
  15 +
9 scope :search_by_query, lambda {|query = ""| 16 scope :search_by_query, lambda {|query = ""|
10 filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') 17 filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|')
11 search_fields = SoftwareInfo.pg_search_plugin_fields 18 search_fields = SoftwareInfo.pg_search_plugin_fields
@@ -13,15 +20,18 @@ class SoftwareInfo &lt; ActiveRecord::Base @@ -13,15 +20,18 @@ class SoftwareInfo &lt; ActiveRecord::Base
13 if query.empty? 20 if query.empty?
14 SoftwareInfo.all 21 SoftwareInfo.all
15 else 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 end 24 end
18 } 25 }
19 26
20 def self.pg_search_plugin_fields 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 searchable_fields 35 searchable_fields
26 end 36 end
27 37
views/search/_full_community.html.erb
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 <div class="search-community-content-block"> 10 <div class="search-community-content-block">
11 <span> 11 <span>
12 <% link_name = software.acronym.blank? ? community.name : "#{software.acronym} - #{community.name}" %> 12 <% link_name = software.acronym.blank? ? community.name : "#{software.acronym} - #{community.name}" %>
13 - <h4 class="search-content-result"> 13 + <h4>
14 <%= link_to_homepage(link_name, community.identifier) %> 14 <%= link_to_homepage(link_name, community.identifier) %>
15 </h4> 15 </h4>
16 </span> 16 </span>