From 351114e3c08ecaf52ab62b2e40dc4fd2f791de31 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Mon, 5 Feb 2024 14:59:22 +0000 Subject: [PATCH 1/3] Index on EDAM topic/operation synonyms (exact & narrow) Also ensure topics/operations are indexed for keyword search --- app/models/concerns/has_edam_terms.rb | 15 +++++++++++++++ app/models/event.rb | 11 +++++++++-- app/models/material.rb | 11 +++++++++-- app/models/workflow.rb | 6 +++++- test/models/event_test.rb | 17 +++++++++++++++++ 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 app/models/concerns/has_edam_terms.rb diff --git a/app/models/concerns/has_edam_terms.rb b/app/models/concerns/has_edam_terms.rb new file mode 100644 index 000000000..eb70114b6 --- /dev/null +++ b/app/models/concerns/has_edam_terms.rb @@ -0,0 +1,15 @@ +module HasEdamTerms + extend ActiveSupport::Concern + + def scientific_topics_and_synonyms + scientific_topics.map do |term| + [term.preferred_label] + term.has_exact_synonym + term.has_narrow_synonym + end.flatten.uniq + end + + def operations_and_synonyms + operations.map do |term| + [term.preferred_label] + term.has_exact_synonym + term.has_narrow_synonym + end.flatten.uniq + end +end diff --git a/app/models/event.rb b/app/models/event.rb index 6e3de6018..f4e8bc0e8 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -17,6 +17,7 @@ class Event < ApplicationRecord include HasFriendlyId include FuzzyDictionaryMatch include WithTimezone + include HasEdamTerms before_validation :fix_keywords, on: :create, if: :scraper_record before_validation :presence_default @@ -40,6 +41,12 @@ class Event < ApplicationRecord text :content_provider do content_provider.title unless content_provider.nil? end + text :scientific_topics do + scientific_topics_and_synonyms + end + text :operations do + scientific_topics_and_synonyms + end # sort title string :sort_title do title.downcase.gsub(/^(an?|the) /, '') @@ -70,10 +77,10 @@ class Event < ApplicationRecord associated_nodes.pluck(:name) end string :scientific_topics, multiple: true do - scientific_topic_names + scientific_topics_and_synonyms end string :operations, multiple: true do - operation_names + operations_and_synonyms end string :target_audience, multiple: true boolean :online do diff --git a/app/models/material.rb b/app/models/material.rb index 93fcf8d38..cf8a8f583 100644 --- a/app/models/material.rb +++ b/app/models/material.rb @@ -15,6 +15,7 @@ class Material < ApplicationRecord include IdentifiersDotOrg include HasFriendlyId include HasDifficultyLevel + include HasEdamTerms if TeSS::Config.solr_enabled # :nocov: @@ -32,6 +33,12 @@ class Material < ApplicationRecord text :content_provider do self.content_provider.try(:title) end + text :scientific_topics do + scientific_topics_and_synonyms + end + text :operations do + scientific_topics_and_synonyms + end # sort title string :sort_title do title.downcase.gsub(/^(an?|the) /, '') @@ -40,10 +47,10 @@ class Material < ApplicationRecord string :title string :authors, :multiple => true string :scientific_topics, :multiple => true do - self.scientific_topic_names + scientific_topics_and_synonyms end string :operations, :multiple => true do - self.operation_names + operations_and_synonyms end string :target_audience, :multiple => true string :keywords, :multiple => true diff --git a/app/models/workflow.rb b/app/models/workflow.rb index fdbdd57be..da471810f 100644 --- a/app/models/workflow.rb +++ b/app/models/workflow.rb @@ -10,6 +10,7 @@ class Workflow < ApplicationRecord include HasFriendlyId include CurationQueue include HasDifficultyLevel + include HasEdamTerms if TeSS::Config.solr_enabled # :nocov: @@ -28,9 +29,12 @@ class Workflow < ApplicationRecord node_index('description') end text :authors + text :scientific_topics do + scientific_topics_and_synonyms + end string :authors, :multiple => true string :scientific_topics, :multiple => true do - self.scientific_topic_names + scientific_topics_and_synonyms end text :target_audience string :target_audience, :multiple => true diff --git a/test/models/event_test.rb b/test/models/event_test.rb index e8a382393..ea55e3515 100644 --- a/test/models/event_test.rb +++ b/test/models/event_test.rb @@ -654,4 +654,21 @@ class EventTest < ActiveSupport::TestCase refute @event.valid? end end + + test 'scientific_topics_and_synonyms' do + @event.scientific_topic_names = ['Data governance'] + @event.save! + assert_equal ['Data governance', 'Data stewardship'], @event.reload.scientific_topics_and_synonyms + + @event.scientific_topic_names = ['Data governance', 'Data stewardship'] + @event.save! + assert_equal ['Data governance', 'Data stewardship'], @event.reload.scientific_topics_and_synonyms + end + + test 'operations_and_synonyms' do + @event.operation_names = ['Fold recognition', 'Fold prediction'] + @event.save! + assert_equal ['Fold recognition', 'Domain prediction', 'Fold prediction', 'Protein domain prediction', + 'Protein fold prediction', 'Protein fold recognition'], @event.reload.operations_and_synonyms + end end From 67decac96f2479ef350e97c0b29ef4686b6ad6dd Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Mon, 5 Feb 2024 15:39:18 +0000 Subject: [PATCH 2/3] Fix copy & paste --- app/models/event.rb | 2 +- app/models/material.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/event.rb b/app/models/event.rb index f4e8bc0e8..0fce3b6b8 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -45,7 +45,7 @@ class Event < ApplicationRecord scientific_topics_and_synonyms end text :operations do - scientific_topics_and_synonyms + operations_and_synonyms end # sort title string :sort_title do diff --git a/app/models/material.rb b/app/models/material.rb index cf8a8f583..8d7e4b7d8 100644 --- a/app/models/material.rb +++ b/app/models/material.rb @@ -37,7 +37,7 @@ class Material < ApplicationRecord scientific_topics_and_synonyms end text :operations do - scientific_topics_and_synonyms + operations_and_synonyms end # sort title string :sort_title do From 992e4100512076173be7d904b5360c00f1dba3d6 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Mon, 5 Feb 2024 15:39:48 +0000 Subject: [PATCH 3/3] DRY --- app/models/concerns/has_edam_terms.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/has_edam_terms.rb b/app/models/concerns/has_edam_terms.rb index eb70114b6..4c8169f11 100644 --- a/app/models/concerns/has_edam_terms.rb +++ b/app/models/concerns/has_edam_terms.rb @@ -2,13 +2,17 @@ module HasEdamTerms extend ActiveSupport::Concern def scientific_topics_and_synonyms - scientific_topics.map do |term| - [term.preferred_label] + term.has_exact_synonym + term.has_narrow_synonym - end.flatten.uniq + edam_term_names_and_synonyms(scientific_topics) end def operations_and_synonyms - operations.map do |term| + edam_term_names_and_synonyms(operations) + end + + private + + def edam_term_names_and_synonyms(terms) + terms.map do |term| [term.preferred_label] + term.has_exact_synonym + term.has_narrow_synonym end.flatten.uniq end