mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2024-12-22 15:43:14 +01:00
fix aggregations to work more like drill down
This commit is contained in:
parent
2b7ab65432
commit
d27f78afba
1 changed files with 36 additions and 26 deletions
|
@ -46,9 +46,6 @@ class Paper < ActiveRecord::Base
|
|||
def search(q, options={})
|
||||
@search_definition = Elasticsearch::DSL::Search.search do
|
||||
|
||||
query do
|
||||
filtered do
|
||||
|
||||
query do
|
||||
# search query
|
||||
unless q.blank?
|
||||
|
@ -61,8 +58,8 @@ class Paper < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# filters
|
||||
filter do
|
||||
# apply filter after aggregations
|
||||
post_filter do
|
||||
bool do
|
||||
must { term paper_type: options[:paper_type] } if options[:paper_type].present?
|
||||
must { term originator: options[:originator] } if options[:originator].present?
|
||||
|
@ -71,20 +68,33 @@ class Paper < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
aggregation :paper_types do
|
||||
# filter by originator
|
||||
f = Elasticsearch::DSL::Search::Filters::Bool.new
|
||||
f.must { match_all }
|
||||
f.must { term originator: options[:originator] } if options[:originator].present?
|
||||
filter f.to_hash do
|
||||
aggregation :paper_types do
|
||||
terms do
|
||||
field 'paper_type'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
aggregation :originators do
|
||||
# filter by paper_type
|
||||
f = Elasticsearch::DSL::Search::Filters::Bool.new
|
||||
f.must { match_all }
|
||||
f.must { term paper_type: options[:paper_type] } if options[:paper_type].present?
|
||||
filter f.to_hash do
|
||||
aggregation :originators do
|
||||
terms do
|
||||
field 'originator'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Rails.logger.debug "Query: #{@search_definition.to_json}"
|
||||
|
|
Loading…
Reference in a new issue