Commit 28004418058f4f1e576a28aa68f992da7b6773d3
Committed by
Gabriela Navarro
1 parent
d675b078
Exists in
master
and in
5 other branches
Refactor scope search_by_query in SoftwareInfo to includes use the constant SEAR…
…CHABLE_SOFTWARE_CLASSES Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
1 changed file
with
16 additions
and
1 deletions
Show diff stats
lib/software_info.rb
... | ... | @@ -20,10 +20,25 @@ class SoftwareInfo < ActiveRecord::Base |
20 | 20 | if query.empty? |
21 | 21 | SoftwareInfo.all |
22 | 22 | else |
23 | - includes(:community, :programming_languages, :database_descriptions).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')") | |
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}')") | |
24 | 25 | end |
25 | 26 | } |
26 | 27 | |
28 | + def self.transform_list_in_methods_list list | |
29 | + methods_list = [] | |
30 | + | |
31 | + list.each do |element| | |
32 | + if SoftwareInfo.instance_methods.include?(element.to_s.underscore.to_sym) | |
33 | + methods_list << element.to_s.underscore.to_sym | |
34 | + elsif SoftwareInfo.instance_methods.include?(element.to_s.underscore.pluralize.to_sym) | |
35 | + methods_list << element.to_s.underscore.pluralize.to_sym | |
36 | + end | |
37 | + end | |
38 | + | |
39 | + methods_list | |
40 | + end | |
41 | + | |
27 | 42 | def self.pg_search_plugin_fields |
28 | 43 | SEARCHABLE_SOFTWARE_CLASSES.collect { |one_class| |
29 | 44 | self.get_searchable_fields(one_class) | ... | ... |