fix facets attribute access

This commit is contained in:
Lars Henrik Mai 2015-06-22 21:11:51 +02:00 committed by Andreas Haller
parent 4aa0b2424b
commit 2caec3d721
2 changed files with 13 additions and 3 deletions

View file

@ -6,7 +6,17 @@ class SearchController < ApplicationController
@response = Paper.search(params[:q], options)
@papers = @response.page(params[:page]).results
@paper_type_facets = @response.response['aggregations']['paper_types']['buckets']
@originator_facets = @response.response['aggregations']['originators']['buckets']
@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

View file

@ -4,7 +4,7 @@ module SearchHelper
content_tag(:ul) do
facets.each do |facet|
concat content_tag(:li,
"#{facet['key']} (#{facet['doc_count']})",
"#{facet.term} (#{facet.count})",
class: "facet"
)
end