diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index 731b29d12..1c96c607f 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -101,6 +101,19 @@ def facet_by_resource_type(arr) end end + def facet_by_affiliation(arr) + # generate hash with id and name for each provider in facet + + ids = arr.map { |hsh| "\"#{hsh["key"]}\"" }.join(" ") + affiliations = Organization.query(ids, size: 1000)[:data] + + arr.map do |hsh| + { "id" => hsh["key"], + "title" => affiliations.find { |a| a["id"] == hsh["key"] }.to_h["name"], + "count" => hsh["doc_count"] } + end + end + def facet_by_provider(arr) # generate hash with id and name for each provider in facet diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index f5a758c5a..c12eb9762 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -59,6 +59,7 @@ def index provider_id: params[:provider_id], consortium_id: params[:consortium_id], client_id: params[:client_id], + affiliation_id: params[:affiliation_id], re3data_id: params[:re3data_id], opendoar_id: params[:opendoar_id], certificate: params[:certificate], @@ -119,6 +120,7 @@ def index registered = nil providers = nil clients = nil + affiliations = nil prefixes = nil schema_versions = nil sources = nil @@ -137,6 +139,7 @@ def index registered = total > 0 ? facet_by_year(response.response.aggregations.registered.buckets) : nil providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil clients = total > 0 ? facet_by_client(response.response.aggregations.clients.buckets) : nil + affiliations = total > 0 ? facet_by_affiliation(response.response.aggregations.affiliations.buckets) : nil prefixes = total > 0 ? facet_by_key(response.response.aggregations.prefixes.buckets) : nil schema_versions = total > 0 ? facet_by_schema(response.response.aggregations.schema_versions.buckets) : nil sources = total > 0 ? facet_by_key(response.response.aggregations.sources.buckets) : nil @@ -168,6 +171,7 @@ def index registered: registered, providers: providers, clients: clients, + affiliations: affiliations, prefixes: prefixes, certificates: certificates, "schemaVersions" => schema_versions, diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index 1d48faf52..337573e14 100644 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -39,6 +39,7 @@ def index registered: params[:registered], provider_id: params[:member_id], client_id: params[:data_center_id], + affiliation_id: params[:affiliation_id], prefix: params[:prefix], user_id: params[:person_id], resource_type_id: params[:resource_type_id], @@ -58,6 +59,7 @@ def index registered = total > 0 ? facet_by_year(response.response.aggregations.registered.buckets) : nil providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil clients = total > 0 ? facet_by_client(response.response.aggregations.clients.buckets) : nil + affiliations = total > 0 ? facet_by_affiliation(response.response.aggregations.affiliations.buckets) : nil @dois = response.results @@ -66,6 +68,7 @@ def index "resource-types" => resource_types, registered: registered, "data-centers" => clients, + affiliations: affiliations, total: total, "total-pages" => total_pages, page: page[:number] diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 6f1a42a10..e9e22da5b 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -203,6 +203,7 @@ def query(query, options={}) must << { terms: { aasm_state: options[:state].to_s.split(",") }} if options[:state].present? must << { range: { registered: { gte: "#{options[:registered].split(",").min}||/y", lte: "#{options[:registered].split(",").max}||/y", format: "yyyy" }}} if options[:registered].present? must << { term: { "creators.nameIdentifiers.nameIdentifier" => "https://orcid.org/#{options[:user_id]}" }} if options[:user_id].present? + must << { term: { "creators.affiliation.affiliationIdentifier" => "https://#{options[:affiliation_id]}" }} if options[:affiliation_id].present? must << { term: { consortium_id: options[:consortium_id] }} if options[:consortium_id].present? must << { term: { "client.re3data_id" => options[:re3data_id].upcase.gsub("/", '\/') }} if options[:re3data_id].present? must << { term: { "client.opendoar_id" => options[:opendoar_id] }} if options[:opendoar_id].present? diff --git a/app/models/doi.rb b/app/models/doi.rb index f361dd82f..49770a54a 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -468,6 +468,7 @@ def self.query_aggregations registered: { date_histogram: { field: 'registered', interval: 'year', min_doc_count: 1 } }, providers: { terms: { field: 'provider_id', size: 15, min_doc_count: 1} }, clients: { terms: { field: 'client_id', size: 15, min_doc_count: 1 } }, + affiliations: { terms: { field: 'creators.affiliation.affiliationIdentifier', size: 15, min_doc_count: 1 } }, prefixes: { terms: { field: 'prefix', size: 15, min_doc_count: 1 } }, schema_versions: { terms: { field: 'schema_version', size: 15, min_doc_count: 1 } }, link_checks_status: { terms: { field: 'landing_page.status', size: 15, min_doc_count: 1 } },