Skip to content

Commit

Permalink
simplify facets for totals. datacite/datacite#359
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Nov 21, 2019
1 parent 5aaca85 commit 6edf2c6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
68 changes: 34 additions & 34 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
Expand Down

0 comments on commit 6edf2c6

Please sign in to comment.