stadtratmonitor/app/controllers/search_controller.rb

23 lines
646 B
Ruby
Raw Normal View History

class SearchController < ApplicationController
def index
2015-06-22 20:38:24 +02:00
@paper_type = params[:paper_type]
2015-06-22 20:43:06 +02:00
@originator = params[:originator]
options = params.slice(:paper_type, :originator)
2015-06-22 20:38:24 +02:00
@response = Paper.search(params[:q], options)
2015-06-13 21:18:55 +02:00
@papers = @response.page(params[:page]).results
2015-06-22 21:11:51 +02:00
@paper_type_facets = extract_facets('paper_types')
@originator_facets = extract_facets('originators')
end
2015-06-22 21:11:51 +02:00
private
def extract_facets(name)
@response.
response['aggregations'][name.to_s]['buckets'].
# rewrite key => term, doc_count => count
map {|m| Hashie::Mash.new term: m['key'], count: m['doc_count'] }
end
end