Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update local development environment #15

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:2.3.0
FROM ruby:2.4.0

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev postgresql-client nodejs poppler-utils

Expand All @@ -13,4 +13,4 @@ RUN bundle install

ADD . /app

EXPOSE 5000
EXPOSE 5000
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ gem 'excon', '~> 0.48'
gem 'docsplit', '~> 0.7.6'

# search
gem 'searchkick', '~> 1.2.1'
gem 'typhoeus', '~> 1.0.1'
gem 'searchkick', '~> 4.5.2'
gem 'typhoeus', '~> 1.4.0'

# simple title and opengraph/twitter cards view helpers
gem 'tophat', '~> 2.2.1'
Expand Down
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,39 @@

Volltextsuche und Feeds für die Gutachten des [Wissenschaftlichen Dienstes des Bundestags](https://bundestag.de/ausarbeitungen/).


### Entwicklung

sehrgutachten ist eine Rails 5 (beta)-Anwendung. Du kannst dir eine Rails-Umgebung installieren, oder mittels [docker-compose](https://docs.docker.com/compose/) eine bereits fertig eingerichtete Umgebung benutzen.

#### docker-compose

Nachdem die docker-compose Umgebung mittels `docker-compose up` gestartet wurde,
muss beim ersten Start noch folgendes erledigt werden.

Alle nachfolgenden Befehle müssen innerhalb des `web` oder `worker` container
ausgeführt werden.

1. Datenbank initialisieren

Dieser Befehl legt die benötigten Datenbanken und, da wir uns in einer
Entwicklungsumgebung befinden, auch einige Testeinträge an.

```
RAILS_ENV=development rails db:setup
```

2. Suchindex initialisieren

Die Testeinträge werden hiermit in Elasticsearch bekannt gemacht.

```
RAILS_ENV=development rails searchkick:reindex:all
```

#### Logs

Logs der Rails Anwendung innerhalb des `web` und `worker` container landen in `/app/log/development.log`.

#### Abhängigkeiten

* `poppler-utils` (für [docsplit](http://documentcloud.github.io/docsplit/))
Expand All @@ -29,4 +57,4 @@ Je nach Setup musst du bei den folgenden Kommandos `bundle exec` davorpacken, so

```
rake 'papers:download_new[wd1]'
```
```
5 changes: 2 additions & 3 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def self.search_papers(term, conditions, options = {})
aggs: [:department],
execute: false,
misspellings: false,
include: [:department]
includes: [:department]
}.merge(options)

query = Paper.search(
Expand All @@ -29,11 +29,10 @@ def self.search_papers(term, conditions, options = {})
function_score: {
query: body[:query],
functions: [
{ boost_factor: 1 },
{
gauss: {
created_at: {
scale: '6w'
scale: '42d'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/paper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Paper < ApplicationRecord
text_start: [:title],
word_start: [:title],
highlight: [:title, :contents],
only_analyzed: [:contents],
searchable: [:contents],
index_prefix: 'sehrgutachten'

scope :search_import, -> { includes(:department) }
Expand Down
4 changes: 2 additions & 2 deletions app/views/search/search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<% if @papers.size > 0 %>

<ol class="paper-list paper-list--with-department">
<% @papers.with_details.each do |paper, details| %>
<% @papers.with_highlights.each do |paper, details| %>
<li>
<%
title = details[:highlight].try(:fetch, :title, nil).try(:html_safe) || paper.title
Expand Down Expand Up @@ -68,4 +68,4 @@
<%= link_to 'Anfrage bei kleineAnfragen.de', "https://kleineanfragen.de/search?#{extquery.to_query}" %>
zu deiner Suche.</p>
</div>
<% end %>
<% end %>
40 changes: 33 additions & 7 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
if Rails.env.development?
require 'time'

departments = [
["wd1", "Geschichte, Zeitgeschichte und Politik", "http://www.bundestag.de/dokumente/analysen/wd1", "wd1"],
["wd2", "Auswärtiges, Völkerrecht, wirtschaftliche Zusammenarbeit und Entwicklung, Verteidigung, Menschenrechte und humanitäre Hilfe", "http://www.bundestag.de/dokumente/analysen/wd2", "wd2"],
["wd3", "Verfassung und Verwaltung", "http://www.bundestag.de/dokumente/analysen/wd3", "wd3"],
["wd4", "Haushalt und Finanzen", "http://www.bundestag.de/dokumente/analysen/wd4", "wd4"],
["wd5", "Wirtschaft und Verkehr, Ernährung und Landwirtschaft", "http://www.bundestag.de/dokumente/analysen/wd5", "wd5"],
["wd6", "Arbeit und Soziales", "http://www.bundestag.de/dokumente/analysen/wd6", "wd6"],
["wd7", "Zivil-, Straf- und Verfahrensrecht, Bau und Stadtentwicklung", "http://www.bundestag.de/dokumente/analysen/wd7", "wd7"],
["wd8", "Umwelt, Naturschutz, Reaktorsicherheit, Bildung und Forschung", "http://www.bundestag.de/dokumente/analysen/wd8", "wd8"],
["wd9", "Gesundheit, Familie, Senioren, Frauen und Jugend", "http://www.bundestag.de/dokumente/analysen/wd9", "wd9"],
["wd10", "Kultur, Medien und Sport", "http://www.bundestag.de/dokumente/analysen/wd10", "wd10"],
["pe6", "Europa", "http://www.bundestag.de/dokumente/analysen/pe6", "pe6"],
]

departments.each do |short_name, subject, source_url, slug|
Department.create(short_name: short_name, subject: subject, source_url: source_url, slug: slug)
end

(1..25).each do |i|
Paper.create(
reference: "0#{rand(10..100)}/#{rand(100)}",
title: "Titel #{i}",
url: "https://example.com",
department_id: rand(1..departments.length()),
contents: ["TTIP", "Terrorismus"].sample,
page_count: rand(1..100),
downloaded_at: Time.now
)
end
end
124 changes: 70 additions & 54 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,75 @@
web:
build: .
command: bundle exec rails server -b 0.0.0.0
ports:
- "3000:3000"
volumes:
- .:/app
links:
- database
- elasticsearch
- tika
- redis
environment:
RACK_ENV: development
DATABASE_URL: postgres://sehrgutachten:@database/sehrgutachten
ELASTICSEARCH_URL: http://elasticsearch:9200/
TIKA_SERVER_URL: http://tika:9998
REDIS_URL: redis://redis:6379
SIDEKIQ_WEB_OPEN: "true"
version: "3"

worker:
build: .
command: bundle exec sidekiq -q default -c 5
volumes:
- .:/app
links:
- database
- elasticsearch
- tika
- redis
environment:
RACK_ENV: development
DATABASE_URL: postgres://sehrgutachten:@database/sehrgutachten
ELASTICSEARCH_URL: http://elasticsearch:9200/
TIKA_SERVER_URL: http://tika:9998
REDIS_URL: redis://redis:6379
services:
web:
build: .
command: bundle exec rails server -b 0.0.0.0
ports:
- "3000:3000"
depends_on:
- database
- elasticsearch
- tika
- redis
volumes:
- ./:/app
environment:
RACK_ENV: development
DATABASE_URL: postgres://sehrgutachten:sehrgutachten@database/sehrgutachten
ELASTICSEARCH_URL: http://elasticsearch:9200/
TIKA_SERVER_URL: http://tika:9998
REDIS_URL: redis://redis:6379
SIDEKIQ_WEB_OPEN: "true"

database:
image: postgres:9.4
environment:
POSTGRES_USER: sehrgutachten
ports:
- 5432
worker:
build: .
command: bundle exec sidekiq -q default -c 5
depends_on:
- database
- elasticsearch
- tika
- redis
volumes:
- ./:/app
environment:
RACK_ENV: development
DATABASE_URL: postgres://sehrgutachten:sehrgutachten@database/sehrgutachten
ELASTICSEARCH_URL: http://elasticsearch:9200/
TIKA_SERVER_URL: http://tika:9998
REDIS_URL: redis://redis:6379

elasticsearch:
image: elasticsearch:2.2
command: elasticsearch -Des.http.cors.enabled=true
ports:
- 9200
database:
image: postgres:13.4
environment:
POSTGRES_USER: sehrgutachten
POSTGRES_PASSWORD: sehrgutachten
volumes:
- postgres_data:/var/lib/postgresql/data/
ports:
- 5432

tika:
image: logicalspark/docker-tikaserver
ports:
- 9998
elasticsearch:
image: elasticsearch:7.14.0
environment:
discovery.type: single-node
xpack.security.enabled: 'false'
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
- elasticsearch-log:/var/log
ports:
- 9200

redis:
image: redis:3.0
ports:
- 6379
tika:
image: apache/tika:2.0.0
ports:
- 9998

redis:
image: redis:6.2
ports:
- 6379

volumes:
postgres_data: {}
elasticsearch-data: {}
elasticsearch-log: {}