Skip to content

Commit

Permalink
Merge pull request #760 from datacite/pr_create_agg
Browse files Browse the repository at this point in the history
added created aggregation for events endpoint
  • Loading branch information
kjgarza authored Feb 8, 2022
2 parents 202f8da + 037d3ba commit b01ad5a
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ def index
if total > 0
facet_by_year(response.aggregations.occurred.buckets)
end
created =
if total > 0
facet_by_year(response.aggregations.created.buckets)
end
prefixes =
if total.positive?
facet_by_key(response.response.aggregations.prefixes.buckets)
Expand Down Expand Up @@ -219,6 +223,7 @@ def index
page[:cursor].nil? && page[:number].present? ? page[:number] : nil,
sources: sources,
occurred: occurred,
created: created,
prefixes: prefixes,
"citationTypes" => citation_types,
"relationTypes" => relation_types,
Expand Down
10 changes: 10 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ def self.query_aggregations
},
aggs: { bucket_truncate: { bucket_sort: { size: 10 } } },
},
created: {
date_histogram: {
field: "created_at",
interval: "year",
format: "year",
order: { _key: "desc" },
min_doc_count: 1,
},
aggs: { bucket_truncate: { bucket_sort: { size: 10 } } },
},
registrants: {
terms: { field: "registrant_id", size: 10, min_doc_count: 1 },
aggs: {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions spec/requests/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,17 @@
"datacite.crossref.citations",
)
end

it "has created aggregation" do
post uri, params, headers

Event.import
sleep 2
get uri, nil, headers

expect(json.dig("meta", "created", 0, "count")).to eq(1)
expect(json.dig("meta", "occurred", 0, "count")).to eq(1)
end
end

context "with nested attributes" do
Expand Down

0 comments on commit b01ad5a

Please sign in to comment.