Skip to content

Commit

Permalink
remove filter and correct "supplemented" filter
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Nov 29, 2019
1 parent e3df759 commit 597f535
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
13 changes: 3 additions & 10 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ def self.yearly_histogram_aggregation
}

{
histogram: {
filter: { script: { script: "true"}},
aggs: { years: { histogram: { field: "citation_year", interval: 1 , min_doc_count: 1 }, aggs: { "total_by_year" => { sum: { field: "total" } } } }, "sum_distribution" => sum_year_distribution }
},
years: { histogram: { field: "citation_year", interval: 1 , min_doc_count: 1 }, aggs: { "total_by_year" => { sum: { field: "total" } } } }, "sum_distribution" => sum_year_distribution
}
end

Expand All @@ -264,12 +261,8 @@ def self.monthly_histogram_aggregation
}
}
{
histogram: {
filter: { script: { script: "true"}},
aggs: {
year_months: { date_histogram: { field: "occurred_at", interval: "month", min_doc_count: 1 }, aggs: { "total_by_year_month" => { sum: { field: "total" } } } }, "sum_distribution" => sum_distribution
}
}}
year_months: { date_histogram: { field: "occurred_at", interval: "month", min_doc_count: 1 }, aggs: { "total_by_year_month" => { sum: { field: "total" } } } }, "sum_distribution" => sum_distribution
}
end


Expand Down
10 changes: 5 additions & 5 deletions app/queries/events_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class EventsQuery

ACTIVE_RELATION_TYPES = [
"cites",
"is-supplement-by",
"is-supplemented-by",
"references"
]

PASSIVE_RELATION_TYPES = [
"is-cited-by",
"is-supplemented-to",
"is-supplement-to",
"is-referenced-by"
]

Expand All @@ -34,7 +34,7 @@ def citations(doi)
def citations_histogram(doi)
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.histogram
results = Event.query(query, doi: doi, aggregations: "yearly_histogram_aggregation", page: { size: 1, cursor: [] }).response.aggregations
facet_citations_by_year(results)
end

Expand All @@ -54,7 +54,7 @@ def views(doi)
def views_histogram(doi)
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.histogram
results = Event.query(query, doi: doi, aggregations: "monthly_histogram_aggregation", page: { size: 1, cursor: [] }).response.aggregations
facet_counts_by_year_month(results)
end

Expand All @@ -73,7 +73,7 @@ def downloads(doi)
def downloads_histogram(doi)
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.histogram
results = Event.query(query, doi: doi, aggregations: "monthly_histogram_aggregation", page: { size: 1, cursor: [] }).response.aggregations
facet_counts_by_year_month(results)
end

Expand Down

0 comments on commit 597f535

Please sign in to comment.