Commit b0f53e17ed561e9e709a0ea60ae7fa9d9a84cff7
Committed by
Gabriela Navarro
1 parent
b6f01b8f
Exists in
master
and in
5 other branches
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>
Showing
5 changed files
with
26 additions
and
6 deletions
Show diff stats
lib/database_description.rb
lib/ext/community.rb
lib/programming_language.rb
lib/software_info.rb
... | ... | @@ -6,6 +6,13 @@ class SoftwareInfo < 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 < 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> | ... | ... |