This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.rb
54 lines (46 loc) · 1.38 KB
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# main.rb
require 'sinatra'
require 'sinatra/json'
require 'sinatra/reloader'
require 'elasticsearch'
require 'dotenv/load'
set :bind, '0.0.0.0'
get '/api/v1/search' do
content_type :json, :charset => 'utf-8'
headers 'Access-Control-Allow-Origin' => 'https://wd-shiroma.github.io'
client = Elasticsearch::Client.new(hosts: [
{
host: ENV["ES_HOST"],
port: ENV["ES_PORT"]
}
])
sort = params.fetch('sort', '_score:desc')
from = [params.fetch('from', 0).to_i, 0].max
size = [params.fetch('size', 50).to_i, 100].min
query = params.fetch('q', 'mastodon')
# 2018/5/8 https://mstdn.jp/@tys/100020090139658680
query += ' -account.acct:@tys@mstdn.jp'
# 2019/3/19 https://garakuta.online/@ebi/101768398314539865
query += ' -account.acct:@ebi@garakuta.online'
# 2019/3/24 https://garakuta.online/@admin/101801466271694359
query += ' -account.acct:@garakuta.online'
# 2019/3/30 https://mstdn.taiyaki.online/@Yellow/101827870211401011
query += ' -account.acct:@Yellow@mstdn.taiyaki.online'
result = client.search sort: sort, from: from, size: size,
body: {
query: {
query_string: {
query: query,
default_field: "content",
default_operator: "and"
}
}
}
json result
end
get '/healthcheck' do
'OK ' + `hostname`.strip
end
get '/' do
send_file File.join(settings.public_folder, 'index.html')
end