mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2024-12-22 23:53:15 +01:00
display count of facets in filter selects
This commit is contained in:
parent
d27f78afba
commit
df8c525159
2 changed files with 10 additions and 4 deletions
|
@ -1,3 +1,10 @@
|
|||
SearchFacet = Struct.new("SearchFacet", :term, :count) do
|
||||
def term_with_count
|
||||
"#{term} (#{count})"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class SearchController < ApplicationController
|
||||
def index
|
||||
@paper_type = params[:paper_type]
|
||||
|
@ -16,9 +23,8 @@ class SearchController < ApplicationController
|
|||
|
||||
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'] }
|
||||
response['aggregations'][name.to_s][name.to_s]['buckets'].
|
||||
map {|m| SearchFacet.new(m['key'], m['doc_count'])}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ module SearchHelper
|
|||
concat(label name, desc)
|
||||
concat(
|
||||
select_tag name,
|
||||
options_from_collection_for_select(facets, :term, :term, selected),
|
||||
options_from_collection_for_select(facets, :term, :term_with_count, selected),
|
||||
include_blank: true,
|
||||
onchange: "this.form.submit();"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue