display count of facets in filter selects

This commit is contained in:
Lars Henrik Mai 2015-06-22 22:08:45 +02:00 committed by Andreas Haller
parent d27f78afba
commit df8c525159
2 changed files with 10 additions and 4 deletions

View file

@ -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

View file

@ -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();"
)