From 2abba45f4c04adb327ccdfe528e5ca79e87ba07b Mon Sep 17 00:00:00 2001 From: Andreas Haller Date: Wed, 19 Nov 2014 21:54:36 +0100 Subject: [PATCH] Query ES, show results --- Gemfile | 4 ++-- Gemfile.lock | 9 ++++++++ .../{application.css => application.css.scss} | 6 +++-- .../stylesheets/objects/_search-result.scss | 3 +++ app/assets/stylesheets/sessions.css.scss | 3 --- app/controllers/search_controller.rb | 4 ++++ app/views/layouts/application.html.slim | 4 ++-- app/views/search/index.html.slim | 23 ++++++++++++++++--- 8 files changed, 44 insertions(+), 12 deletions(-) rename app/assets/stylesheets/{application.css => application.css.scss} (90%) create mode 100644 app/assets/stylesheets/objects/_search-result.scss delete mode 100644 app/assets/stylesheets/sessions.css.scss diff --git a/Gemfile b/Gemfile index 3c68a9e..f9ce526 100644 --- a/Gemfile +++ b/Gemfile @@ -14,12 +14,10 @@ gem 'coffee-rails', '~> 4.0.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby gem 'slim-rails' - # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' - # Assets gem 'foundation-rails' @@ -27,6 +25,8 @@ gem 'foundation-rails' gem 'omniauth' gem 'omniauth-browserid' +gem 'elasticsearch' + # 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 195ae07..1fb806e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,6 +44,14 @@ GEM coffee-script-source execjs coffee-script-source (1.8.0) + elasticsearch (1.0.6) + elasticsearch-api (= 1.0.6) + elasticsearch-transport (= 1.0.6) + elasticsearch-api (1.0.6) + multi_json + elasticsearch-transport (1.0.6) + faraday + multi_json erubis (2.7.0) execjs (2.2.2) faraday (0.9.0) @@ -151,6 +159,7 @@ PLATFORMS DEPENDENCIES capybara coffee-rails (~> 4.0.0) + elasticsearch foundation-rails jquery-rails launchy diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css.scss similarity index 90% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.css.scss index 541c939..9767c7c 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css.scss @@ -10,8 +10,10 @@ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new * file per style scope. * - *= require_tree . + *= require_self - *= require foundation_and_overrides */ + +@import 'foundation_and_overrides'; +@import 'objects/search-result'; diff --git a/app/assets/stylesheets/objects/_search-result.scss b/app/assets/stylesheets/objects/_search-result.scss new file mode 100644 index 0000000..29f6632 --- /dev/null +++ b/app/assets/stylesheets/objects/_search-result.scss @@ -0,0 +1,3 @@ +.search-result { + border-bottom: 1px solid $table-border-color; +} diff --git a/app/assets/stylesheets/sessions.css.scss b/app/assets/stylesheets/sessions.css.scss deleted file mode 100644 index 7bef9cf..0000000 --- a/app/assets/stylesheets/sessions.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the sessions controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index b69386a..5fff71d 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,4 +1,8 @@ class SearchController < ApplicationController def index + @result = if params[:q].present? + es = Elasticsearch::Client.new + es.search index: 'loris', q: params[:q] + end end end diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index c5dace5..776e58f 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -12,8 +12,8 @@ body = content_tag :div, msg, class: name .row .large-8.columns - h2#title - = link_to 'Willkommen in Leipzig', root_path + h1#title + = link_to 'Stadtratmonitor Leipzig', root_path .large-4.columns ul.inline-list.right li = render 'login_button' diff --git a/app/views/search/index.html.slim b/app/views/search/index.html.slim index 92c5639..51c71a1 100644 --- a/app/views/search/index.html.slim +++ b/app/views/search/index.html.slim @@ -1,4 +1,21 @@ = form_tag(search_path, method: :get) - = label_tag(:q, 'Suche:') - = text_field_tag(:q) - = submit_tag 'Suchen', class: 'button' + = text_field_tag(:q, params[:q], placeholder: 'Sucheā€¦') + +.row + - if @result + .small-9.columns + | #{@result['hits']['total']} Treffer + .small-3.columns + button.button.right TODO: Suche Abbonieren + +- if @result + ul.no-bullet + - @result['hits']['hits'].each do |doc| + li.search-result + small = doc['_source']['paperType'] + ' + small = doc['_source']['originator'].join(', ') + ' + small = doc['_source']['publishedDate'] + = link_to "https://ratsinfo.leipzig.de/bi/#{doc['_source']['mainFile']}", target: '_blank' do + div = doc['_source']['name']