diff --git a/app/controllers/client_prefixes_controller.rb b/app/controllers/client_prefixes_controller.rb index 831284118..f81833a41 100644 --- a/app/controllers/client_prefixes_controller.rb +++ b/app/controllers/client_prefixes_controller.rb @@ -34,8 +34,8 @@ def index total = response.results.total total_pages = page[:size].positive? ? (total.to_f / page[:size]).ceil : 0 years = total.positive? ? facet_by_year(response.response.aggregations.years.buckets) : nil - providers = total.positive? ? facet_by_provider(response.response.aggregations.providers.buckets) : nil - clients = total.positive? ? facet_by_client(response.response.aggregations.clients.buckets) : nil + providers = total.positive? ? facet_by_combined_key(response.response.aggregations.providers.buckets) : nil + clients = total.positive? ? facet_by_combined_key(response.response.aggregations.clients.buckets) : nil client_prefixes = response.results diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 5f9cff3c3..edd4f8941 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -42,7 +42,7 @@ def index total = response.results.total total_pages = page[:size] > 0 ? (total.to_f / page[:size]).ceil : 0 years = total > 0 ? facet_by_key_as_string(response.response.aggregations.years.buckets) : nil - providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil + providers = total > 0 ? facet_by_combined_key(response.response.aggregations.providers.buckets) : nil software = total > 0 ? facet_by_software(response.response.aggregations.software.buckets) : nil client_types = total > 0 ? facet_by_key(response.response.aggregations.client_types.buckets) : nil certificates = total > 0 ? facet_by_key(response.response.aggregations.certificates.buckets) : nil diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index 8f50b9029..bffc3b053 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -121,19 +121,6 @@ def facet_by_resource_type(arr) end end - def facet_by_provider(arr) - # generate hash with id and name for each provider in facet - - ids = arr.map { |hsh| hsh["key"] }.join(",") - providers = Provider.find_by_id(ids, size: 1000).records.pluck(:symbol, :name).to_h - - arr.map do |hsh| - { "id" => hsh["key"], - "title" => providers[hsh["key"].upcase], - "count" => hsh["doc_count"] } - end - end - def facet_by_year_month(arr) arr.map do |hsh| month = hsh["key_as_string"][5..6].to_i @@ -372,30 +359,6 @@ def clients_totals(arr) end end - def facet_by_provider_ids(arr) - # generate hash with id and name for each provider in facet - ids = arr.map { |hsh| hsh["key"] }.join(",") - providers = Provider.find_by_id_list(ids).records.pluck(:symbol, :name).to_h - - arr.map do |hsh| - { "id" => hsh["key"], - "title" => providers[hsh["key"].upcase], - "count" => hsh["doc_count"] } - end - end - - def facet_by_client(arr) - # generate hash with id and name for each client in facet - ids = arr.map { |hsh| hsh["key"] }.join(",") - clients = Client.find_by_id(ids).records.pluck(:symbol, :name).to_h - - arr.map do |hsh| - { "id" => hsh["key"], - "title" => clients[hsh["key"].upcase], - "count" => hsh["doc_count"] } - end - end - def facet_by_combined_key(arr) arr.map do |hsh| id, title = hsh["key"].split(":", 2) diff --git a/app/controllers/data_centers_controller.rb b/app/controllers/data_centers_controller.rb index 9004c0faa..e64170e26 100644 --- a/app/controllers/data_centers_controller.rb +++ b/app/controllers/data_centers_controller.rb @@ -32,7 +32,7 @@ def index total = response.results.total total_pages = page[:size] > 0 ? (total.to_f / page[:size]).ceil : 0 years = total > 0 ? facet_by_year(response.response.aggregations.years.buckets) : nil - providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil + providers = total > 0 ? facet_by_combined_key(response.response.aggregations.providers.buckets) : nil @clients = response.results diff --git a/app/controllers/prefixes_controller.rb b/app/controllers/prefixes_controller.rb index 43f7ef26b..d9303751d 100644 --- a/app/controllers/prefixes_controller.rb +++ b/app/controllers/prefixes_controller.rb @@ -34,8 +34,8 @@ def index total_pages = page[:size].positive? ? (total.to_f / page[:size]).ceil : 0 years = total.positive? ? facet_by_year(response.response.aggregations.years.buckets) : nil states = total.positive? ? facet_by_key(response.response.aggregations.states.buckets) : nil - providers = total.positive? ? facet_by_provider(response.response.aggregations.providers.buckets) : nil - clients = total.positive? ? facet_by_client(response.response.aggregations.clients.buckets) : nil + providers = total.positive? ? facet_by_combined_key(response.response.aggregations.providers.buckets) : nil + clients = total.positive? ? facet_by_combined_key(response.response.aggregations.clients.buckets) : nil prefixes = response.results diff --git a/app/controllers/provider_prefixes_controller.rb b/app/controllers/provider_prefixes_controller.rb index 7f12f3dd5..47cb3574a 100644 --- a/app/controllers/provider_prefixes_controller.rb +++ b/app/controllers/provider_prefixes_controller.rb @@ -35,7 +35,7 @@ def index total_pages = page[:size].positive? ? (total.to_f / page[:size]).ceil : 0 years = total.positive? ? facet_by_year(response.response.aggregations.years.buckets) : nil states = total.positive? ? facet_by_key(response.response.aggregations.states.buckets) : nil - providers = total.positive? ? facet_by_provider(response.response.aggregations.providers.buckets) : nil + providers = total.positive? ? facet_by_combined_key(response.response.aggregations.providers.buckets) : nil provider_prefixes = response.results diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index c2771b97e..be265ef6c 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -45,7 +45,7 @@ def index total = response.results.total total_pages = page[:size] > 0 ? (total.to_f / page[:size]).ceil : 0 years = total > 0 ? facet_by_year(response.response.aggregations.years.buckets) : nil - providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil + providers = total > 0 ? facet_by_combined_key(response.response.aggregations.providers.buckets) : nil software = total > 0 ? facet_by_software(response.response.aggregations.software.buckets) : nil certificates = total > 0 ? facet_by_key(response.response.aggregations.certificates.buckets) : nil client_types = total > 0 ? facet_by_key(response.response.aggregations.client_types.buckets) : nil diff --git a/app/controllers/repository_prefixes_controller.rb b/app/controllers/repository_prefixes_controller.rb index 89d562730..79f0cf1a9 100644 --- a/app/controllers/repository_prefixes_controller.rb +++ b/app/controllers/repository_prefixes_controller.rb @@ -33,8 +33,8 @@ def index total = response.results.total total_pages = page[:size].positive? ? (total.to_f / page[:size]).ceil : 0 years = total.positive? ? facet_by_year(response.response.aggregations.years.buckets) : nil - providers = total.positive? ? facet_by_provider(response.response.aggregations.providers.buckets) : nil - repositories = total.positive? ? facet_by_client(response.response.aggregations.clients.buckets) : nil + providers = total.positive? ? facet_by_combined_key(response.response.aggregations.providers.buckets) : nil + repositories = total.positive? ? facet_by_combined_key(response.response.aggregations.clients.buckets) : nil repository_prefixes = response.results diff --git a/app/graphql/types/base_connection.rb b/app/graphql/types/base_connection.rb index c8cca40ab..a21d0e91f 100644 --- a/app/graphql/types/base_connection.rb +++ b/app/graphql/types/base_connection.rb @@ -66,16 +66,4 @@ def facet_by_combined_key(arr) "count" => hsh["doc_count"] } end end - - def facet_by_client(arr) - # generate hash with id and name for each client in facet - ids = arr.map { |hsh| hsh["key"] }.join(",") - clients = Client.find_by_id(ids).records.pluck(:symbol, :name).to_h - - arr.map do |hsh| - { "id" => hsh["key"], - "title" => clients[hsh["key"].upcase], - "count" => hsh["doc_count"] } - end - end end diff --git a/app/graphql/types/book_chapter_connection_type.rb b/app/graphql/types/book_chapter_connection_type.rb index 14873d580..0b3955ff5 100644 --- a/app/graphql/types/book_chapter_connection_type.rb +++ b/app/graphql/types/book_chapter_connection_type.rb @@ -34,7 +34,7 @@ def repositories args = prepare_args(object.arguments) res = response(args) - res.results.total.positive? ? facet_by_client(res.response.aggregations.clients.buckets) : [] + res.results.total.positive? ? facet_by_combined_key(res.response.aggregations.clients.buckets) : [] end def affiliations diff --git a/app/models/client_prefix.rb b/app/models/client_prefix.rb index 35e2e7911..5d4856266 100644 --- a/app/models/client_prefix.rb +++ b/app/models/client_prefix.rb @@ -64,8 +64,8 @@ def self.query_aggregations { years: { date_histogram: { field: 'created_at', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 }, aggs: { bucket_truncate: { bucket_sort: { size: 10 } } } }, - providers: { terms: { field: "provider_id", size: 15, min_doc_count: 1 } }, - clients: { terms: { field: "client_id", size: 15, min_doc_count: 1 } }, + providers: { terms: { field: "provider_id_and_name", size: 10, min_doc_count: 1 } }, + clients: { terms: { field: "client_id_and_name", size: 10, min_doc_count: 1 } }, } end @@ -74,6 +74,10 @@ def client_id client.symbol.downcase end + def client_id_and_name + "#{client_id}:#{client.name}" if client.present? + end + # convert external id / internal id def client_id=(value) logger.warn value.inspect @@ -100,6 +104,10 @@ def provider_id client.provider_id if client.present? end + def provider_id_and_name + "#{client.provider_id}:#{client.provider.name}" if client.present? + end + def provider client.provider if client.present? end diff --git a/app/models/prefix.rb b/app/models/prefix.rb index 932823f00..f8bb96197 100644 --- a/app/models/prefix.rb +++ b/app/models/prefix.rb @@ -60,8 +60,8 @@ def self.query_aggregations states: { terms: { field: 'state', size: 3, min_doc_count: 1 } }, years: { date_histogram: { field: 'created_at', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 }, aggs: { bucket_truncate: { bucket_sort: { size: 10 } } } }, - providers: { terms: { field: 'provider_ids', size: 10, min_doc_count: 1 } }, - clients: { terms: { field: 'client_ids', size: 10, min_doc_count: 1 } }, + providers: { terms: { field: 'provider_ids_and_names', size: 10, min_doc_count: 1 } }, + clients: { terms: { field: 'client_ids_and_names', size: 10, min_doc_count: 1 } }, } end @@ -81,10 +81,22 @@ def client_ids clients.pluck(:symbol).map(&:downcase) end + def client_ids_and_name + clients.pluck(:symbol, :name).map do |p| + "#{p[0].downcase}:#{p[1]}" + end + end + def provider_ids providers.pluck(:symbol).map(&:downcase) end + def provider_ids_and_names + providers.pluck(:symbol, :name).map do |p| + "#{p[0].downcase}:#{p[1]}" + end + end + def client_prefix_ids client_prefixes.pluck(:uid) end diff --git a/app/models/provider.rb b/app/models/provider.rb index cca68ba01..2c0e2e91b 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -247,7 +247,7 @@ def self.query_aggregations { years: { date_histogram: { field: 'created', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 }, aggs: { bucket_truncate: { bucket_sort: { size: 10 } } } }, - cumulative_years: { terms: { field: 'cumulative_years', size: 15, min_doc_count: 1, order: { _count: "asc" } } }, + cumulative_years: { terms: { field: 'cumulative_years', size: 10, min_doc_count: 1, order: { _count: "asc" } } }, regions: { terms: { field: 'region', size: 10, min_doc_count: 1 } }, member_types: { terms: { field: 'member_type', size: 10, min_doc_count: 1 } }, organization_types: { terms: { field: 'organization_type', size: 10, min_doc_count: 1 } }, diff --git a/app/models/provider_prefix.rb b/app/models/provider_prefix.rb index b55e637c6..3cf040dc5 100644 --- a/app/models/provider_prefix.rb +++ b/app/models/provider_prefix.rb @@ -70,7 +70,7 @@ def self.query_aggregations states: { terms: { field: 'state', size: 2, min_doc_count: 1 } }, years: { date_histogram: { field: 'created_at', interval: 'year', format: 'year', order: { _key: "desc" }, min_doc_count: 1 }, aggs: { bucket_truncate: { bucket_sort: { size: 10 } } } }, - providers: { terms: { field: 'provider_id', size: 15, min_doc_count: 1 } }, + providers: { terms: { field: 'provider_id_and_name', size: 10, min_doc_count: 1 } }, } end @@ -83,6 +83,10 @@ def provider_id provider.symbol.downcase end + def provider_id_and_name + "#{provider_id}:#{provider.name}" if provider.present? + end + # convert external id / internal id def provider_id=(value) r = Provider.where(symbol: value).first