Class: Akane::Storages::Elasticsearch
- Inherits:
-
AbstractStorage
- Object
- AbstractStorage
- Akane::Storages::Elasticsearch
- Defined in:
- lib/akane/storages/elasticsearch.rb
Instance Method Summary collapse
-
#initialize ⇒ Elasticsearch
constructor
A new instance of Elasticsearch.
- #mark_as_deleted(account, user_id, tweet_id) ⇒ Object
- #name ⇒ Object
- #record_event(account, event) ⇒ Object
- #record_message(account, message) ⇒ Object
- #record_tweet(account, tweet) ⇒ Object
Methods inherited from AbstractStorage
Constructor Details
#initialize ⇒ Elasticsearch
Returns a new instance of Elasticsearch.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/akane/storages/elasticsearch.rb', line 7 def initialize(*) super @es = ::Elasticsearch::Client.new( hosts: [@config["host"]], logger: @config["enable_es_log"] ? @logger : nil ) @index_name = @config["index"] || 'akane' set_elasticsearch_up end |
Instance Method Details
#mark_as_deleted(account, user_id, tweet_id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/akane/storages/elasticsearch.rb', line 28 def mark_as_deleted(account, user_id, tweet_id) tweet = @es.get(index: @index_name, type: 'tweet', id: tweet_id.to_s)['_source'] tweet['deleted'] = true @es.index(index: @index_name, type: 'tweet', id: tweet_id.to_s, body: tweet) minimum_tweet = { id: tweet['id'], id_str: tweet['id_str'], text: tweet['text'], user: { id: tweet['user']['id'], id_str: tweet['user']['id_str'], screen_name: tweet['user']['screen_name'], } } @es.index(index: @index_name, type: 'deleted_tweet', id: tweet_id.to_s, body: {tweet: minimum_tweet, deleted_at: Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}) rescue ::Elasticsearch::Transport::Transport::Errors::NotFound => e @logger.debug "Due to 404, skipping Deletion for #{tweet_id}" # do nothing end |
#name ⇒ Object
18 19 20 |
# File 'lib/akane/storages/elasticsearch.rb', line 18 def name @name ||= "#{self.class.name}:#{@config["host"]}/#{@index_name}" end |
#record_event(account, event) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/akane/storages/elasticsearch.rb', line 48 def record_event(account, event) case event["event"] when 'favorite' when 'unfavorite' when 'block' when 'unblock' when 'follow' when 'unfollow' end end |
#record_message(account, message) ⇒ Object
59 60 61 |
# File 'lib/akane/storages/elasticsearch.rb', line 59 def (account, ) @es.index(index: @index_name, type: 'message', id: [:id_str], body: .attrs) end |
#record_tweet(account, tweet) ⇒ Object
22 23 24 25 26 |
# File 'lib/akane/storages/elasticsearch.rb', line 22 def record_tweet(account, tweet) tweet_hash = tweet.attrs tweet_hash[:deleted] = false @es.index(index: @index_name, type: 'tweet', id: tweet_hash[:id_str], body: tweet_hash) end |