-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet_indexer.rb
40 lines (33 loc) · 847 Bytes
/
tweet_indexer.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
require 'open-uri'
require 'indextank_client'
class TweetIndexer
def self.index
@api ||= IndexTank::HerokuClient.new
@index = @api.get_index 'plixi'
create_index unless index.exists?
end
def self.create_index
index.create_index
while not index.running?
puts 'waiting for index to start...'
sleep 1
end
end
# retrieve tweets from IndexTank
def self.search(query)
{
:matches => 0,
:results => []
}
end
# load tweets from Plixi API into IndexTank
def self.index
uri = 'http://api.plixi.com/api/tpapi.svc/json/photos?getuser=true'
photos = JSON.parse(open(uri).read)
count, list = photos['Count'], photos['List']
list.each do |data|
tweet = Tweet.new(data)
index.add_document(tweet.id, tweet.to_document) if tweet.indexable?
end
end
end