Skip to content

Commit

Permalink
use occured_at for events
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 20, 2021
1 parent 566bce7 commit 76e35fc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
8 changes: 4 additions & 4 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def index
if total.positive?
facet_by_source(response.response.aggregations.sources.buckets)
end
citation_years =
if total.positive?
facet_by_cumulative_year(response.response.aggregations.citation_years.buckets)
occurred =
if total > 0
facet_by_year(response.aggregations.occurred.buckets)
end
prefixes =
if total.positive?
Expand Down Expand Up @@ -218,7 +218,7 @@ def index
page:
page[:cursor].nil? && page[:number].present? ? page[:number] : nil,
sources: sources,
citation_years: citation_years,
occurred: occurred,
prefixes: prefixes,
"citationTypes" => citation_types,
"relationTypes" => relation_types,
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/old_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ def index
if total > 0
facet_by_source(response.aggregations.prefixes.buckets)
end
citation_years =
occurred =
if total > 0
facet_by_cumulative_year(response.aggregations.citation_years.buckets)
facet_by_year(response.aggregations.occurred.buckets)
end
citation_types =
if total > 0
Expand All @@ -203,7 +203,7 @@ def index
page:
page[:cursor].nil? && page[:number].present? ? page[:number] : nil,
sources: sources,
citation_years: citation_years,
occurred: occurred,
prefixes: prefixes,
"citation-types" => citation_types,
"relation-types" => relation_types,
Expand Down
28 changes: 17 additions & 11 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,15 @@ def self.query_aggregations
{
sources: { terms: { field: "source_id", size: 10, min_doc_count: 1 } },
prefixes: { terms: { field: "prefix", size: 10, min_doc_count: 1 } },
citation_years: {
date_histogram: {
field: "citation_year",
interval: "year",
format: "year",
order: {
_key: "desc",
occurred: {
date_histogram: {
field: "occurred_at",
interval: "year",
format: "year",
order: { _key: "desc" },
min_doc_count: 1,
},
min_doc_count: 1,
},
aggs: { bucket_truncate: { bucket_sort: { size: 10 } } },
},
registrants: {
terms: { field: "registrant_id", size: 10, min_doc_count: 1 },
Expand Down Expand Up @@ -958,10 +957,17 @@ def obj_cache_key
end

def citation_year
unless (INCLUDED_RELATION_TYPES + RELATIONS_RELATION_TYPES).include?(
relation_type_id,
)
""
end
subj_publication =
subj["datePublished"] || subj["date_published"]
subj["datePublished"] || subj["date_published"] ||
(date_published(subj_id) || year_month)
obj_publication =
obj["datePublished"] || obj["date_published"]
obj["datePublished"] || obj["date_published"] ||
(date_published(obj_id) || year_month)
[subj_publication[0..3].to_i, obj_publication[0..3].to_i].max
end

Expand Down

0 comments on commit 76e35fc

Please sign in to comment.