mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2025-04-20 07:11:33 +02:00
use dsl for search definition and fix pagination
This commit is contained in:
parent
aa644818c4
commit
5b677ab3ca
5 changed files with 28 additions and 37 deletions
|
@ -29,5 +29,26 @@ class Paper < ActiveRecord::Base
|
|||
end
|
||||
puts "Imported #{count - old_count} Papers!"
|
||||
end
|
||||
|
||||
# use DSL to define search queries
|
||||
# see https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl
|
||||
# and https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-rails/lib/rails/templates
|
||||
def search(q)
|
||||
@search_definition = Elasticsearch::DSL::Search.search do
|
||||
query do
|
||||
unless q.blank?
|
||||
multi_match do
|
||||
query q
|
||||
fields ["name", "content"]
|
||||
end
|
||||
else
|
||||
match_all
|
||||
end
|
||||
end
|
||||
end
|
||||
puts @search_definition.to_hash
|
||||
__elasticsearch__.search(@search_definition)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue