stadtratmonitor/app/controllers/search_controller.rb
2015-07-18 12:44:40 +02:00

24 lines
672 B
Ruby

class SearchController < ApplicationController
def index
@paper_type = params[:paper_type]
@originator = params[:originator]
options = params.slice(:paper_type, :originator)
@show_filters = true
@response = Paper.search(params[:q], options)
@papers = @response.page(params[:page]).results
@paper_type_facets = extract_facets('paper_types')
@originator_facets = extract_facets('originators')
end
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