@@ -9,48 +9,14 @@ class Profile < ApplicationRecord
99 validates :website , url : true , http_url : true , allow_blank : true
1010 validates :orcid , orcid : true , allow_blank : true
1111 after_validation :check_public
12+ after_commit :reindex_trainer
1213 clean_array_fields ( :expertise_academic , :expertise_technical , :fields ,
1314 :interest , :activity , :language , :social_media )
1415 update_suggestions ( :expertise_technical , :interest )
1516
1617 extend FriendlyId
1718 friendly_id :full_name , use : :slugged
1819
19- after_update_commit :reindex
20- after_destroy_commit :reindex
21-
22- if TeSS ::Config . solr_enabled
23- # :nocov:
24- searchable do
25- # full text search fields
26- text :firstname
27- text :surname
28- text :description
29- # sort title
30- string :sort_title do
31- full_name . downcase
32- end
33- # other fields
34- integer :user_id
35- string :full_name
36- string :location
37- string :orcid
38- string :experience do
39- TrainerExperienceDictionary . instance . lookup_value ( self . experience , 'title' )
40- end
41- string :expertise_academic , multiple : true
42- string :expertise_technical , multiple : true
43- string :fields , :multiple => true
44- string :interest , multiple : true
45- string :activity , multiple : true
46- string :language , multiple : true
47- string :social_media , multiple : true
48- time :updated_at
49- boolean :public
50- end
51- # :nocov:
52- end
53-
5420 def self . facet_fields
5521 field_list = %w( full_name )
5622 end
@@ -93,14 +59,14 @@ def check_public
9359 public ? self . type = 'Trainer' : self . type = 'Profile'
9460 end
9561
96- def reindex
97- if Rails . env . production?
98- Trainer . reindex
99- end
100- end
101-
10262 def should_generate_new_friendly_id?
10363 firstname_changed? or surname_changed?
10464 end
10565
66+ # This is needed if the `public` status of the profile changes when it is already instantiated - it won't be cast
67+ # to a Trainer object and indexed by solr (only Trainer class is `searchable`).
68+ def reindex_trainer
69+ return unless TeSS ::Config . solr_enabled
70+ becomes ( Trainer ) . solr_index
71+ end
10672end
0 commit comments