mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2024-12-22 23:53:15 +01:00
Replace direct ES access with elasticsearch-model
This commit is contained in:
parent
5a07703166
commit
973af9f0d9
5 changed files with 18 additions and 9 deletions
1
Gemfile
1
Gemfile
|
@ -26,6 +26,7 @@ gem 'omniauth'
|
||||||
gem 'omniauth-browserid'
|
gem 'omniauth-browserid'
|
||||||
|
|
||||||
gem 'elasticsearch'
|
gem 'elasticsearch'
|
||||||
|
gem 'elasticsearch-model'
|
||||||
|
|
||||||
# bundle exec rake doc:rails generates the API under doc/api.
|
# bundle exec rake doc:rails generates the API under doc/api.
|
||||||
gem 'sdoc', '~> 0.4.0', group: :doc
|
gem 'sdoc', '~> 0.4.0', group: :doc
|
||||||
|
|
|
@ -58,6 +58,10 @@ GEM
|
||||||
elasticsearch-transport (= 1.0.7)
|
elasticsearch-transport (= 1.0.7)
|
||||||
elasticsearch-api (1.0.7)
|
elasticsearch-api (1.0.7)
|
||||||
multi_json
|
multi_json
|
||||||
|
elasticsearch-model (0.1.7)
|
||||||
|
activesupport (> 3)
|
||||||
|
elasticsearch (> 0.4)
|
||||||
|
hashie
|
||||||
elasticsearch-transport (1.0.7)
|
elasticsearch-transport (1.0.7)
|
||||||
faraday
|
faraday
|
||||||
multi_json
|
multi_json
|
||||||
|
@ -181,6 +185,7 @@ DEPENDENCIES
|
||||||
capybara
|
capybara
|
||||||
coffee-rails
|
coffee-rails
|
||||||
elasticsearch
|
elasticsearch
|
||||||
|
elasticsearch-model
|
||||||
foundation-rails
|
foundation-rails
|
||||||
jquery-rails
|
jquery-rails
|
||||||
launchy
|
launchy
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
class SearchController < ApplicationController
|
class SearchController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@result = if params[:q].present?
|
@result = if params[:q].present?
|
||||||
es = Elasticsearch::Client.new
|
|
||||||
# TODO: Add pagination
|
# TODO: Add pagination
|
||||||
es.search index: 'loris', q: params[:q], size: 30
|
Paper.search(params[:q]).records
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
|
require 'elasticsearch/model'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
|
||||||
class Paper < ActiveRecord::Base
|
class Paper < ActiveRecord::Base
|
||||||
|
include Elasticsearch::Model
|
||||||
|
include Elasticsearch::Model::Callbacks
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def import_from_json(json_string)
|
def import_from_json(json_string)
|
||||||
JSON.parse(json_string).each do |record|
|
JSON.parse(json_string).each do |record|
|
||||||
|
|
|
@ -5,18 +5,18 @@ div
|
||||||
.clearfix
|
.clearfix
|
||||||
- if @result
|
- if @result
|
||||||
.left
|
.left
|
||||||
| #{@result['hits']['total']} Treffer
|
| #{@result.size} Treffer
|
||||||
.right
|
.right
|
||||||
button.button. TODO: Suche Abbonieren
|
button.button. TODO: Suche Abbonieren
|
||||||
div
|
div
|
||||||
- if @result
|
- if @result
|
||||||
ul.no-bullet
|
ul.no-bullet
|
||||||
- @result['hits']['hits'].each do |doc|
|
- @result.each do |doc|
|
||||||
li.search-result
|
li.search-result
|
||||||
small = doc['_source']['paperType']
|
small = doc.paper_type
|
||||||
'
|
'
|
||||||
small = doc['_source']['originator'].join(', ')
|
small = doc.originator
|
||||||
'
|
'
|
||||||
small = doc['_source']['publishedDate']
|
small = doc.published_at
|
||||||
= link_to "https://ratsinfo.leipzig.de/bi/#{doc['_source']['mainFile']}", target: '_blank' do
|
= link_to doc.url, target: '_blank' do
|
||||||
div = doc['_source']['name']
|
div = doc.name
|
||||||
|
|
Loading…
Reference in a new issue