2015-06-22 22:08:45 +02:00
|
|
|
SearchFacet = Struct.new("SearchFacet", :term, :count) do
|
|
|
|
def term_with_count
|
|
|
|
"#{term} (#{count})"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-11-19 17:07:05 +01:00
|
|
|
class SearchController < ApplicationController
|
|
|
|
def index
|
2015-10-05 22:13:53 +02:00
|
|
|
@search_definition = PaperSearch.new(query: params[:q],
|
|
|
|
paper_type: params[:paper_type],
|
|
|
|
originator: params[:originator],
|
2015-10-05 22:25:29 +02:00
|
|
|
sort_by: params[:paper_search][:sort_by])
|
|
|
|
|
|
|
|
# @search = PaperSearch.new params[:paper_search]
|
2015-06-22 20:38:24 +02:00
|
|
|
|
2015-10-05 22:13:53 +02:00
|
|
|
@response = Paper.search(@search_definition)
|
2015-06-13 21:18:55 +02:00
|
|
|
@papers = @response.page(params[:page]).results
|
2015-06-22 21:11:51 +02:00
|
|
|
@paper_type_facets = extract_facets('paper_types')
|
|
|
|
@originator_facets = extract_facets('originators')
|
2015-06-01 23:53:45 +02:00
|
|
|
end
|
2015-06-22 21:11:51 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def extract_facets(name)
|
|
|
|
@response.
|
2015-06-22 22:08:45 +02:00
|
|
|
response['aggregations'][name.to_s][name.to_s]['buckets'].
|
|
|
|
map {|m| SearchFacet.new(m['key'], m['doc_count'])}
|
2015-06-22 21:11:51 +02:00
|
|
|
end
|
|
|
|
|
2014-11-19 17:07:05 +01:00
|
|
|
end
|