diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 27537f4dc..cf4e915e5 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -122,18 +122,18 @@ def index registrants = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_registrants(response.response.aggregations.registrants.buckets) : nil pairings = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_pairings(response.response.aggregations.pairings.buckets) : nil dois = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_dois(response.response.aggregations.dois.buckets) : nil - dois_usage = total.positive? && params[:doi].present? ? EventsQuery.new.usage(params[:doi]) : nil + dois_usage = total.positive? ? EventsQuery.new.usage(params[:doi]) : nil # dois_citations = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_citations_by_year_v1(response.response.aggregations.dois_citations) : nil - citations = total.positive? && params[:doi].present? ? EventsQuery.new.citations(params[:doi]) : nil - citations_histogram = total.positive? && params[:doi].present? ? EventsQuery.new.citations_histogram(params[:doi]) : nil - references = total.positive? && params[:doi].present? && aggregations.include?("citations_aggregations") ? facet_citations_by_dois(response.response.aggregations.references.dois.buckets) : nil - relations = total.positive? && params[:doi].present? && aggregations.include?("citations_aggregations") ? facet_citations_by_dois(response.response.aggregations.relations.dois.buckets) : nil + citations = total.positive? ? EventsQuery.new.citations(params[:doi]) : nil + citations_histogram = total.positive? ? EventsQuery.new.citations_histogram(params[:doi]) : nil + references = total.positive? && aggregations.include?("citations_aggregations") ? facet_citations_by_dois(response.response.aggregations.references.dois.buckets) : nil + relations = total.positive? && aggregations.include?("citations_aggregations") ? facet_citations_by_dois(response.response.aggregations.relations.dois.buckets) : nil - views_histogram = total.positive? && params[:doi].present? ? EventsQuery.new.views_histogram(params[:doi]) : nil - downloads_histogram = total.positive? && params[:doi].present? ? EventsQuery.new.downloads_histogram(params[:doi]) : nil + views_histogram = total.positive? ? EventsQuery.new.views_histogram(params[:doi]) : nil + downloads_histogram = total.positive? ? EventsQuery.new.downloads_histogram(params[:doi]) : nil - views = total.positive? && params[:doi].present? ? EventsQuery.new.views(params[:doi]) : nil - downloads = total.positive? && params[:doi].present? ? EventsQuery.new.downloads(params[:doi]) : nil + # views = total.positive? ? EventsQuery.new.views(params[:doi]) : nil + # downloads = total.positive? ? EventsQuery.new.downloads(params[:doi]) : nil unique_obj_count = total.positive? && aggregations.include?("advanced_aggregations") ? response.response.aggregations.unique_obj_count.value : nil unique_subj_count = total.positive? && aggregations.include?("advanced_aggregations") ? response.response.aggregations.unique_subj_count.value : nil @@ -162,9 +162,9 @@ def index "subjCount": unique_subj_count }, "viewsHistogram": views_histogram, - "views": views, - "downloadsHistogram": downloads_histogram, - "downloads": downloads + # "views": views, + "downloadsHistogram": downloads_histogram + # "downloads": downloads }.compact options[:links] = { diff --git a/app/queries/events_query.rb b/app/queries/events_query.rb index d9ce825dd..0018fb7b4 100644 --- a/app/queries/events_query.rb +++ b/app/queries/events_query.rb @@ -19,6 +19,7 @@ def initialize end def doi_citations(doi) + return nil unless doi.present? pid = Event.new.normalize_doi(doi) query = "(subj_id:\"#{pid}\" AND (relation_type_id:#{PASSIVE_RELATION_TYPES.join(' OR relation_type_id:')})) OR (obj_id:\"#{pid}\" AND (relation_type_id:#{ACTIVE_RELATION_TYPES.join(' OR relation_type_id:')}))" results = Event.query(query, doi: doi, aggregations: "citation_count_aggregation", page: { size: 1, cursor: [] }).response.aggregations.citations.buckets @@ -26,12 +27,14 @@ def doi_citations(doi) end def citations(doi) + return {} unless doi.present? doi.downcase.split(",").map do |item| { id: item, count: EventsQuery.new.doi_citations(item) } end end def citations_histogram(doi) + return {} unless doi.present? pid = Event.new.normalize_doi(doi.downcase.split(",").first) query = "(subj_id:\"#{pid}\" AND (relation_type_id:#{PASSIVE_RELATION_TYPES.join(' OR relation_type_id:')})) OR (obj_id:\"#{pid}\" AND (relation_type_id:#{ACTIVE_RELATION_TYPES.join(' OR relation_type_id:')}))" results = Event.query(query, doi: doi, aggregations: "yearly_histogram_aggregation", page: { size: 1, cursor: [] }).response.aggregations @@ -40,18 +43,21 @@ def citations_histogram(doi) def doi_views(doi) + return nil unless doi.present? query = "(relation_type_id:unique-dataset-investigations-regular AND source_id:datacite-usage)" results = Event.query(query, doi: doi, aggregations: "usage_count_aggregation", page: { size: 1, cursor: [] }).response.aggregations.usage.buckets results.any? ? results.first.dig("total_by_type", "value") : 0 end def views(doi) + return {} unless doi.present? doi.downcase.split(",").map do |item| { id: item, count: EventsQuery.new.doi_views(item) } end end def views_histogram(doi) + return {} unless doi.present? doi = doi.downcase.split(",").first query = "(relation_type_id:unique-dataset-investigations-regular AND source_id:datacite-usage)" results = Event.query(query, doi: doi, aggregations: "monthly_histogram_aggregation", page: { size: 1, cursor: [] }).response.aggregations @@ -59,18 +65,21 @@ def views_histogram(doi) end def doi_downloads(doi) + return nil unless doi.present? query = "(relation_type_id:unique-dataset-requests-regular AND source_id:datacite-usage)" results = Event.query(query, doi: doi, aggregations: "usage_count_aggregation", page: { size: 1, cursor: [] }).response.aggregations.usage.buckets results.any? ? results.first.dig("total_by_type", "value") : 0 end def downloads(doi) + return {} unless doi.present? doi.downcase.split(",").map do |item| { id: item, count: EventsQuery.new.doi_downloads(item) } end end def downloads_histogram(doi) + return {} unless doi.present? doi = doi.downcase.split(",").first query = "(relation_type_id:unique-dataset-requests-regular AND source_id:datacite-usage)" results = Event.query(query, doi: doi, aggregations: "monthly_histogram_aggregation", page: { size: 1, cursor: [] }).response.aggregations @@ -78,6 +87,7 @@ def downloads_histogram(doi) end def usage(doi) + return {} unless doi.present? doi.downcase.split(",").map do |item| pid = Event.new.normalize_doi(item) requests = EventsQuery.new.doi_downloads(item)