Skip to content

Commit

Permalink
added affiliation identifier query parameter and facet. #348
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 10, 2019
1 parent 7b3524f commit 7207959
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -119,6 +120,7 @@ def index
registered = nil
providers = nil
clients = nil
affiliations = nil
prefixes = nil
schema_versions = nil
sources = nil
Expand All @@ -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
Expand Down Expand Up @@ -168,6 +171,7 @@ def index
registered: registered,
providers: providers,
clients: clients,
affiliations: affiliations,
prefixes: prefixes,
certificates: certificates,
"schemaVersions" => schema_versions,
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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

Expand All @@ -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]
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
1 change: 1 addition & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
Expand Down

0 comments on commit 7207959

Please sign in to comment.