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 'elasticsearch'
|
||||
gem 'elasticsearch-model'
|
||||
|
||||
# bundle exec rake doc:rails generates the API under doc/api.
|
||||
gem 'sdoc', '~> 0.4.0', group: :doc
|
||||
|
|
|
@ -58,6 +58,10 @@ GEM
|
|||
elasticsearch-transport (= 1.0.7)
|
||||
elasticsearch-api (1.0.7)
|
||||
multi_json
|
||||
elasticsearch-model (0.1.7)
|
||||
activesupport (> 3)
|
||||
elasticsearch (> 0.4)
|
||||
hashie
|
||||
elasticsearch-transport (1.0.7)
|
||||
faraday
|
||||
multi_json
|
||||
|
@ -181,6 +185,7 @@ DEPENDENCIES
|
|||
capybara
|
||||
coffee-rails
|
||||
elasticsearch
|
||||
elasticsearch-model
|
||||
foundation-rails
|
||||
jquery-rails
|
||||
launchy
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
class SearchController < ApplicationController
|
||||
def index
|
||||
@result = if params[:q].present?
|
||||
es = Elasticsearch::Client.new
|
||||
# TODO: Add pagination
|
||||
es.search index: 'loris', q: params[:q], size: 30
|
||||
Paper.search(params[:q]).records
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require 'elasticsearch/model'
|
||||
require 'json'
|
||||
|
||||
class Paper < ActiveRecord::Base
|
||||
include Elasticsearch::Model
|
||||
include Elasticsearch::Model::Callbacks
|
||||
|
||||
class << self
|
||||
def import_from_json(json_string)
|
||||
JSON.parse(json_string).each do |record|
|
||||
|
|
|
@ -5,18 +5,18 @@ div
|
|||
.clearfix
|
||||
- if @result
|
||||
.left
|
||||
| #{@result['hits']['total']} Treffer
|
||||
| #{@result.size} Treffer
|
||||
.right
|
||||
button.button. TODO: Suche Abbonieren
|
||||
div
|
||||
- if @result
|
||||
ul.no-bullet
|
||||
- @result['hits']['hits'].each do |doc|
|
||||
- @result.each do |doc|
|
||||
li.search-result
|
||||
small = doc['_source']['paperType']
|
||||
small = doc.paper_type
|
||||
'
|
||||
small = doc['_source']['originator'].join(', ')
|
||||
small = doc.originator
|
||||
'
|
||||
small = doc['_source']['publishedDate']
|
||||
= link_to "https://ratsinfo.leipzig.de/bi/#{doc['_source']['mainFile']}", target: '_blank' do
|
||||
div = doc['_source']['name']
|
||||
small = doc.published_at
|
||||
= link_to doc.url, target: '_blank' do
|
||||
div = doc.name
|
||||
|
|
Loading…
Reference in a new issue