Skip to content

Commit

Permalink
show provider facets for repositories and prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 8, 2020
1 parent c334e3d commit 90ad0ce
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/controllers/provider_prefixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def index
begin
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
states = total.positive? ? facet_by_key(response.response.aggregations.states.buckets) : nil
providers = total.positive? ? facet_by_combined_key(response.response.aggregations.providers.buckets) : nil
years = total.positive? ? facet_by_year(response.aggregations.years.buckets) : nil
states = total.positive? ? facet_by_key(response.aggregations.states.buckets) : nil
providers = total.positive? ? facet_by_combined_key(response.aggregations.providers.buckets) : nil

provider_prefixes = response.results

Expand Down
8 changes: 7 additions & 1 deletion app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class Client < ActiveRecord::Base
indexes :uid, type: :keyword, normalizer: "keyword_lowercase"
indexes :symbol, type: :keyword
indexes :provider_id, type: :keyword
indexes :provider_id_and_name, type: :keyword
indexes :consortium_id, type: :keyword
indexes :re3data_id, type: :keyword
indexes :opendoar_id, type: :integer
Expand Down Expand Up @@ -211,6 +212,7 @@ def as_indexed_json(options={})
"id" => uid,
"uid" => uid,
"provider_id" => provider_id,
"provider_id_and_name" => provider_id_and_name,
"consortium_id" => consortium_id,
"re3data_id" => re3data_id,
"opendoar_id" => opendoar_id,
Expand Down Expand Up @@ -252,7 +254,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: 10, min_doc_count: 1, order: { _count: "asc" } } },
providers: { terms: { field: 'provider_id', size: 10, min_doc_count: 1 } },
providers: { terms: { field: 'provider_id_and_name', size: 10, min_doc_count: 1 } },
software: { terms: { field: 'software.keyword', size: 10, min_doc_count: 1 } },
client_types: { terms: { field: 'client_type', size: 10, min_doc_count: 1 } },
repository_types: { terms: { field: 'repository_type', size: 10, min_doc_count: 1 } },
Expand Down Expand Up @@ -291,6 +293,10 @@ def provider_id
provider_symbol.downcase
end

def provider_id_and_name
"#{provider_id}:#{provider.name}"
end

def provider_id=(value)
r = Provider.where(symbol: value).first
return nil unless r.present?
Expand Down
2 changes: 2 additions & 0 deletions app/models/provider_prefix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ProviderPrefix < ActiveRecord::Base
indexes :uid, type: :keyword
indexes :state, type: :keyword
indexes :provider_id, type: :keyword
indexes :provider_id_and_name, type: :keyword
indexes :consortium_id, type: :keyword
indexes :prefix_id, type: :keyword
indexes :client_ids, type: :keyword
Expand Down Expand Up @@ -51,6 +52,7 @@ def as_indexed_json(options={})
"id" => uid,
"uid" => uid,
"provider_id" => provider_id,
"provider_id_and_name" => provider_id_and_name,
"consortium_id" => consortium_id,
"prefix_id" => prefix_id,
"client_ids" => client_ids,
Expand Down
3 changes: 3 additions & 0 deletions spec/requests/provider_prefixes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

expect(last_response.status).to eq(200)
expect(json["data"].size).to eq(3)
expect(json.dig('meta', 'years')).to eq([{"count"=>3, "id"=>"2020", "title"=>"2020"}])
expect(json.dig('meta', 'states')).to eq([{"count"=>3, "id"=>"without-repository", "title"=>"Without Repository"}])
expect(json.dig('meta', 'providers')).to eq([{"count"=>3, "id"=>provider.symbol.downcase, "title"=>"My provider"}])
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/requests/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
expect(last_response.status).to eq(200)
expect(json['data'].size).to eq(4)
expect(json.dig('meta', 'total')).to eq(4)
expect(json.dig('meta', 'providers').length).to eq(4)
expect(json.dig('meta', 'providers').first).to eq("count"=>1, "id"=>provider.symbol.downcase, "title"=>"My provider")
end
end

Expand Down

0 comments on commit 90ad0ce

Please sign in to comment.