diff --git a/Gemfile b/Gemfile index 8b7aedf..16e0264 100644 --- a/Gemfile +++ b/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 diff --git a/Gemfile.lock b/Gemfile.lock index 2b8f7b9..d16bc3c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 9401004..2853466 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -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 diff --git a/app/models/paper.rb b/app/models/paper.rb index 6758828..0791fa8 100644 --- a/app/models/paper.rb +++ b/app/models/paper.rb @@ -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| diff --git a/app/views/search/index.html.slim b/app/views/search/index.html.slim index 278e549..2b09b51 100644 --- a/app/views/search/index.html.slim +++ b/app/views/search/index.html.slim @@ -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