Skip to content

Commit

Permalink
index submission and ontologies metadata on save
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Feb 9, 2024
1 parent db96af1 commit ff61cce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/ontologies_linked_data/models/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class Contact < LinkedData::Models::Base
attribute :email, enforce: [:existence]

embedded true

def embedded_doc
"#{self.name} #{self.email}"
end

end
end
end
6 changes: 6 additions & 0 deletions lib/ontologies_linked_data/models/ontology.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class OntologyAnalyticsError < StandardError; end
# Cache
cache_timeout 3600

enable_indexing(:ontology_metadata)

def self.validate_acronym(inst, attr)
inst.bring(attr) if inst.bring?(attr)
acronym = inst.send(attr)
Expand Down Expand Up @@ -447,6 +449,10 @@ def unindex(commit=true)
unindex_by_acronym(commit)
end

def embedded_doc
"#{self.acronym} #{self.name} #{self.viewingRestriction}"
end

def unindex_properties(commit=true)
self.bring(:acronym) if self.bring?(:acronym)
query = "submissionAcronym:#{acronym}"
Expand Down
7 changes: 4 additions & 3 deletions lib/ontologies_linked_data/models/ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def self.embed_values_hash
read_restriction_based_on ->(sub) { sub.ontology }
access_control_load ontology: %i[administeredBy acl viewingRestriction]

enable_indexing(:ontology_metadata)
def initialize(*args)
super(*args)
@mutex = Mutex.new
Expand Down Expand Up @@ -1214,7 +1215,7 @@ def process_submission(logger, options = {})
raise Exception, "The submission #{self.ontology.acronym}/submissions/#{self.submissionId} cannot be indexed because it has not been successfully parsed" unless parsed
status = LinkedData::Models::SubmissionStatus.find("INDEXED").first
begin
index(logger, index_commit, false)
index_terms(logger, index_commit, false)
add_submission_status(status)
rescue Exception => e
logger.error("#{e.class}: #{e.message}\n#{e.backtrace.join("\n\t")}")
Expand Down Expand Up @@ -1324,7 +1325,7 @@ def process_metrics(logger)
self
end

def index(logger, commit = true, optimize = true)
def index_terms(logger, commit = true, optimize = true)
page = 0
size = 1000
count_classes = 0
Expand Down Expand Up @@ -1560,7 +1561,7 @@ def delete(*args)
prev_sub = self.ontology.latest_submission()

if prev_sub
prev_sub.index(LinkedData::Parser.logger || Logger.new($stderr))
prev_sub.index_terms(LinkedData::Parser.logger || Logger.new($stderr))
prev_sub.index_properties(LinkedData::Parser.logger || Logger.new($stderr))
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ontologies_linked_data/sample_data/ontology.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def self.create_ontologies_and_submissions(options = {})

o = LinkedData::Models::Ontology.new({
acronym: acronym_count,
name: name || "#{acronym_count} Ontology",
name: name ? "#{name}#{count > 0 ? count : ''}" : "#{acronym_count} Ontology",
administeredBy: [u],
summaryOnly: false,
ontologyType: ontology_type
Expand Down

0 comments on commit ff61cce

Please sign in to comment.