mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2025-07-14 16:31:33 +02:00
24 lines
672 B
Ruby
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
|