From 76e35fc61f1771be5385a281fde594854d323a9e Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Tue, 20 Apr 2021 11:51:34 +0200 Subject: [PATCH] use occured_at for events --- app/controllers/events_controller.rb | 8 +++---- app/controllers/old_events_controller.rb | 6 ++--- app/models/event.rb | 28 ++++++++++++++---------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 20da27e2d..5e4b445c3 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -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? @@ -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, diff --git a/app/controllers/old_events_controller.rb b/app/controllers/old_events_controller.rb index 712a802d2..4e565be96 100644 --- a/app/controllers/old_events_controller.rb +++ b/app/controllers/old_events_controller.rb @@ -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 @@ -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, diff --git a/app/models/event.rb b/app/models/event.rb index 981b226a4..6732a640c 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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 }, @@ -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