From 6edf2c616867688f922a48b19203a798e2cb0834 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Thu, 21 Nov 2019 21:01:50 +0100 Subject: [PATCH] simplify facets for totals. datacite/datacite#359 --- app/controllers/concerns/facetable.rb | 12 ++--- app/models/doi.rb | 68 +++++++++++++-------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index e562e50cb..f601bc46a 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -33,10 +33,10 @@ def facet_by_year(arr) end end - def facet_anual(arr) + def facet_annual(arr) arr.map do |hsh| - { "id" => hsh["key"][0..3], - "title" => hsh["key"][0..3], + { "id" => hsh["key_as_string"], + "title" => hsh["key_as_string"], "count" => hsh["doc_count"] } end end @@ -323,7 +323,7 @@ def providers_totals(arr) { "id" => hsh["key"], "title" => providers[hsh["key"].upcase], "count" => hsh["doc_count"], - "year" => facet_anual(hsh.year.buckets) + "year" => facet_annual(hsh.year.buckets) # "this_month" => facet_anual(hsh.this_month.buckets), # "this_year" => facet_anual(hsh.this_year.buckets), @@ -339,7 +339,7 @@ def prefixes_totals(arr) { "id" => hsh["key"], "title" => hsh["key"], "count" => hsh["doc_count"], - "year" => facet_anual(hsh.year.buckets) + "year" => facet_annual(hsh.year.buckets) # "temporal" => { # "this_month" => facet_anual(hsh.this_month.buckets), # "this_year" => facet_anual(hsh.this_year.buckets), @@ -360,7 +360,7 @@ def clients_totals(arr) { "id" => hsh["key"], "title" => clients[hsh["key"].upcase], "count" => hsh["doc_count"], - "year" => facet_anual(hsh.year.buckets) + "year" => facet_annual(hsh.year.buckets) # "temporal" => { # "this_month" => facet_anual(hsh.this_month.buckets), # "this_year" => facet_anual(hsh.this_year.buckets), diff --git a/app/models/doi.rb b/app/models/doi.rb index 716dd008f..5ae313318 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -484,45 +484,45 @@ def self.query_aggregations end def self.totals_aggregations - { - providers_totals: { - composite: { - size: 50, - sources: [ - { provider: { terms: { field: "provider_id", size: ::Provider.__elasticsearch__.count, min_doc_count: 1 } } }, - { year: { date_histogram: { field: "created", interval: "year", format: "yyyy" } } } - ] - } - }, - clients_totals: { - composite: { - size: 50, - sources: [ - { client: { terms: { field: "client_id", size: ::Client.__elasticsearch__.count, min_doc_count: 1 } } }, - { year: { date_histogram: { field: "created", interval: "year", format: "yyyy" } } } - ] - } - }, - prefixes_totals: { - composite: { - size: 50, - sources: [ - { prefix: { terms: { field: "prefix", size: ::Prefix.count, min_doc_count: 1 } } }, - { year: { date_histogram: { field: "created", interval: "year", format: "yyyy" } } } - ] - } - } - } - # { - # providers_totals: { terms: { field: 'provider_id', size: 50, min_doc_count: 1 }, aggs: sub_aggregations }, - # clients_totals: { terms: { field: 'client_id', size: 50, min_doc_count: 1 }, aggs: sub_aggregations }, - # prefixes_totals: { terms: { field: 'prefix', size: 50, min_doc_count: 1 }, aggs: sub_aggregations }, + # providers_totals: { + # composite: { + # size: 50, + # sources: [ + # { provider: { terms: { field: "provider_id", size: ::Provider.__elasticsearch__.count, min_doc_count: 1 } } }, + # { year: { date_histogram: { field: "created", interval: "year", format: "yyyy" } } } + # ] + # } + # }, + # clients_totals: { + # composite: { + # size: 50, + # sources: [ + # { client: { terms: { field: "client_id", size: ::Client.__elasticsearch__.count, min_doc_count: 1 } } }, + # { year: { date_histogram: { field: "created", interval: "year", format: "yyyy" } } } + # ] + # } + # }, + # prefixes_totals: { + # composite: { + # size: 50, + # sources: [ + # { prefix: { terms: { field: "prefix", size: ::Prefix.count, min_doc_count: 1 } } }, + # { year: { date_histogram: { field: "created", interval: "year", format: "yyyy" } } } + # ] + # } + # } # } + + { + providers_totals: { terms: { field: 'provider_id', size: 25, min_doc_count: 1 }, aggs: sub_aggregations }, + clients_totals: { terms: { field: 'client_id', size: 25, min_doc_count: 1 }, aggs: sub_aggregations }, + prefixes_totals: { terms: { field: 'prefix', size: 25, min_doc_count: 1 }, aggs: sub_aggregations }, + } end def self.sub_aggregations - { year: { date_histogram: { field: "created", calendar_interval: "year", format: "yyyy" } } } + { year: { date_histogram: { field: "created", interval: "year", format: "yyyy" } } } # { # states: { terms: { field: 'aasm_state', size: 4, min_doc_count: 1 } },