diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 743c0f3..6bac42a 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -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 diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 9b88590..908199c 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -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();" )