2014-11-19 17:07:05 +01:00
|
|
|
class SearchController < ApplicationController
|
|
|
|
def index
|
2015-05-18 22:14:46 +02:00
|
|
|
@paper_type = params[:paper_type]
|
|
|
|
@originator = params[:originator]
|
|
|
|
|
|
|
|
@show_search_result = @show_filters = params[:q].present?
|
2015-04-27 23:25:14 +02:00
|
|
|
papers_found = if @show_search_result
|
2015-05-17 19:18:23 +02:00
|
|
|
Paper.search(params[:q]).records
|
2015-04-27 22:35:11 +02:00
|
|
|
else
|
2015-05-18 22:14:46 +02:00
|
|
|
Paper.all
|
|
|
|
end
|
|
|
|
|
|
|
|
if @show_filters
|
|
|
|
|
|
|
|
@paper_types_found = papers_found.map(&:paper_type).uniq
|
|
|
|
@originators_found = papers_found.map(&:originator).uniq
|
|
|
|
|
|
|
|
if @paper_type.present?
|
|
|
|
papers_found = papers_found.where(paper_type: @paper_type)
|
|
|
|
end
|
|
|
|
|
|
|
|
if @originator.present?
|
|
|
|
papers_found = papers_found.where(originator: @originator)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@papers_count = papers_found.page(params[:page]).total_count
|
|
|
|
@papers = papers_found.page(params[:page])
|
|
|
|
# Fixme Pagination
|
|
|
|
#order(published_at: :desc).
|
|
|
|
# page(params[:page])
|
|
|
|
|
|
|
|
|
2014-11-19 21:54:36 +01:00
|
|
|
end
|
2014-11-19 17:07:05 +01:00
|
|
|
end
|