From a9dd3b7148f426434cdce965a118f5d271a9434e Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Thu, 7 Nov 2024 05:32:42 +0100 Subject: [PATCH] Fix: Search federation duplicated results merging issue (#830) * replace unexisting key :ontology_acronym and get the ontology acronym from the ontology_id when checking ontology duplication in federation * clean code of merge federated results method --- app/controllers/concerns/search_aggregator.rb | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/controllers/concerns/search_aggregator.rb b/app/controllers/concerns/search_aggregator.rb index 078c89c5c..f1f074272 100644 --- a/app/controllers/concerns/search_aggregator.rb +++ b/app/controllers/concerns/search_aggregator.rb @@ -251,17 +251,15 @@ def blacklist_cls_id_components(cls_id, blacklist_words) def merge_federated_results(search_results) search_results.each do |element| element[:root][:other_portals] = [] + element[:reuses].reject! do |reuse| - if (element[:root][:ontology_acronym] == reuse[:root][:ontology_acronym]) && (element[:root][:uri] == reuse[:root][:uri]) - portal_name = reuse[:root][:portal_name] - link = reuse[:root][:link] - element[:root][:other_portals] << { - name: portal_name, - color: federated_portal_color(portal_name), - light_color: federated_portal_light_color(portal_name), - link: link, - ontology_id: reuse[:root][:ontology_id] - } + element_ontology_id = element[:root][:ontology_id].split('/').last + element_uri = element[:root][:uri] + reuse_ontology_id = reuse[:root][:ontology_id].split('/').last + reuse_uri = reuse[:root][:uri] + + if element_ontology_id == reuse_ontology_id && element_uri == reuse_uri + element[:root][:other_portals] << build_other_portal_entry(reuse) true else false @@ -270,6 +268,16 @@ def merge_federated_results(search_results) end end + def build_other_portal_entry(reuse) + { + name: reuse[:root][:portal_name], + color: federated_portal_color(reuse[:root][:portal_name]), + light_color: federated_portal_light_color(reuse[:root][:portal_name]), + link: reuse[:root][:link], + ontology_id: reuse[:root][:ontology_id] + } + end + def swap_canonical_portal_results_first(search_results) all_submissions = LinkedData::Client::Models::OntologySubmission.all(include: 'pullLocation', include_views: true, display_links: false, display_context: false)