Skip to content

Commit

Permalink
Fix: Federated search/browse results count by portal (#870)
Browse files Browse the repository at this point in the history
* include non canonical portals in counting results for each portal

* include non canonical portals in counting results for each portal in federated search

* use portal_api and portal_ui in counting federation results instead of portal_name
  • Loading branch information
Bilelkihal authored Nov 27, 2024
1 parent edd1cc0 commit aec6da8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app/helpers/federation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,18 @@ def init_federation_portals_status
end

def federated_search_counts(search_results)
ids = search_results.map do |result|
result.dig(:root, :ontology_id) || rest_url
end
ids = search_results.flat_map do |result|
ontology_id = result.dig(:root, :ontology_id) || rest_url
other_portal_ids = result.dig(:root, :other_portals)&.map { |portal| portal[:link].split('?').first } || []
[ontology_id] + other_portal_ids
end.uniq
counts_ontology_ids_by_portal_name(ids)
end

def federated_browse_counts(ontologies)
ids = ontologies.map { |ontology| ontology[:id] }
ids = ontologies.flat_map do |ontology|
[ontology[:id]] + (ontology[:sources] || [])
end.uniq
counts_ontology_ids_by_portal_name(ids)
end

Expand All @@ -239,8 +243,9 @@ def counts_ontology_ids_by_portal_name(portals_ids)
counts[current_portal.downcase] += 1 if id.include?(current_portal.to_s.downcase)

federation_portals.each do |portal|
portal_api = federated_portals[portal.downcase.to_sym][:api]
counts[portal.downcase] += 1 if id.include?(portal_api)
portal_api = federated_portals[portal.downcase.to_sym][:api].sub(/^https?:\/\//, '')
portal_ui = federated_portals[portal.downcase.to_sym][:ui].sub(/^https?:\/\//, '')
counts[portal.downcase] += 1 if (id.include?(portal_api) || id.include?(portal_ui))
end
end

Expand Down

0 comments on commit aec6da8

Please sign in to comment.