mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2024-12-22 15:43:14 +01:00
Make PaperSearch persistent
This commit is contained in:
parent
82c2e7e6b8
commit
fce65636f7
3 changed files with 23 additions and 12 deletions
|
@ -7,16 +7,30 @@ end
|
||||||
|
|
||||||
class SearchController < ApplicationController
|
class SearchController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@search_definition = PaperSearch.new(params[:paper_search])
|
@search_definition = params[:paper_search].present? ? PaperSearch.new(search_params) : PaperSearch.new
|
||||||
@search_definition.sort_by ||= "score"
|
@search_definition.sort_by ||= "score"
|
||||||
|
|
||||||
@response = Paper.search(@search_definition)
|
execute_search
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@search_definition = PaperSearch.find params[:id]
|
||||||
|
execute_search
|
||||||
|
render action: "index"
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def execute_search
|
||||||
|
@response = Paper.search(@search_definition.to_definition)
|
||||||
@papers = @response.page(params[:page]).results
|
@papers = @response.page(params[:page]).results
|
||||||
@paper_type_facets = extract_facets('paper_types')
|
@paper_type_facets = extract_facets('paper_types')
|
||||||
@originator_facets = extract_facets('originators')
|
@originator_facets = extract_facets('originators')
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def search_params
|
||||||
|
params.require(:paper_search).permit(:query, :paper_type, :originator, :sort_by)
|
||||||
|
end
|
||||||
|
|
||||||
def extract_facets(name)
|
def extract_facets(name)
|
||||||
@response.
|
@response.
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
class PaperSearch
|
class PaperSearch < ActiveRecord::Base
|
||||||
|
|
||||||
include ActiveModel::Model
|
def to_definition
|
||||||
|
options = {paper_type: paper_type, originator: originator, sort_by: sort_by}
|
||||||
attr_accessor :query, :paper_type, :originator, :sort_by
|
PaperSearch.definition(query, options)
|
||||||
|
|
||||||
def to_hash
|
|
||||||
options = {paper_type: @paper_type, originator: @originator, sort_by: @sort_by}
|
|
||||||
PaperSearch.definition(@query, options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.definition(q, options={})
|
def self.definition(q, options={})
|
||||||
|
|
|
@ -2,7 +2,8 @@ Rails.application.routes.draw do
|
||||||
root to: redirect { |path_params| "/leipzig" }
|
root to: redirect { |path_params| "/leipzig" }
|
||||||
|
|
||||||
scope ':body' do
|
scope ':body' do
|
||||||
get '/' => 'search#index', as: :search
|
get '/' => 'search#index', as: :search
|
||||||
|
get '/:id' => 'search#show', as: :saved_search
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/auth/:provider/callback', to: 'sessions#create'
|
post '/auth/:provider/callback', to: 'sessions#create'
|
||||||
|
|
Loading…
Reference in a new issue