flying-sphinx 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/flying_sphinx.rb +2 -1
- data/lib/flying_sphinx/configuration.rb +78 -3
- data/lib/flying_sphinx/index_request.rb +1 -35
- data/lib/flying_sphinx/tasks.rb +10 -3
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/flying_sphinx.rb
CHANGED
@@ -4,10 +4,11 @@ end
|
|
4
4
|
|
5
5
|
require 'httparty'
|
6
6
|
require 'net/ssh'
|
7
|
+
require 'riddle/0.9.9'
|
7
8
|
|
8
9
|
require 'flying_sphinx/api'
|
9
10
|
require 'flying_sphinx/configuration'
|
10
11
|
require 'flying_sphinx/index_request'
|
11
12
|
require 'flying_sphinx/tunnel'
|
12
13
|
|
13
|
-
require 'flying_sphinx/railtie' if defined?(Rails)
|
14
|
+
require 'flying_sphinx/railtie' if defined?(Rails) && defined?(Rails::Railtie)
|
@@ -1,17 +1,37 @@
|
|
1
1
|
class FlyingSphinx::Configuration
|
2
2
|
attr_reader :heroku_id, :api_key, :host, :port, :database_port
|
3
3
|
|
4
|
-
def initialize(heroku_id, api_key)
|
5
|
-
@heroku_id = heroku_id
|
6
|
-
@api_key = api_key
|
4
|
+
def initialize(heroku_id = nil, api_key = nil)
|
5
|
+
@heroku_id = heroku_id || heroku_id_from_env
|
6
|
+
@api_key = api_key || api_key_from_env
|
7
7
|
|
8
8
|
set_from_server
|
9
|
+
setup_environment_settings
|
9
10
|
end
|
10
11
|
|
11
12
|
def api
|
12
13
|
@api ||= FlyingSphinx::API.new(heroku_id, api_key)
|
13
14
|
end
|
14
15
|
|
16
|
+
def app_name
|
17
|
+
@app_name = heroku_id.split('@').first
|
18
|
+
end
|
19
|
+
|
20
|
+
def sphinx_configuration
|
21
|
+
thinking_sphinx.generate
|
22
|
+
set_database_settings
|
23
|
+
|
24
|
+
riddle.render
|
25
|
+
end
|
26
|
+
|
27
|
+
def start_sphinx
|
28
|
+
api.post('/app/start')
|
29
|
+
end
|
30
|
+
|
31
|
+
def stop_sphinx
|
32
|
+
api.post('/app/stop')
|
33
|
+
end
|
34
|
+
|
15
35
|
private
|
16
36
|
|
17
37
|
def set_from_server
|
@@ -21,4 +41,59 @@ class FlyingSphinx::Configuration
|
|
21
41
|
@port = json['port']
|
22
42
|
@database_port = json['database_port']
|
23
43
|
end
|
44
|
+
|
45
|
+
def base_path
|
46
|
+
"/mnt/sphinx/flying-sphinx/#{app_name}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def log_path
|
50
|
+
"#{base_path}/log"
|
51
|
+
end
|
52
|
+
|
53
|
+
def thinking_sphinx
|
54
|
+
ThinkingSphinx::Configuration.instance
|
55
|
+
end
|
56
|
+
|
57
|
+
def riddle
|
58
|
+
thinking_sphinx.configuration
|
59
|
+
end
|
60
|
+
|
61
|
+
def setup_environment_settings
|
62
|
+
ThinkingSphinx.remote_sphinx = true
|
63
|
+
|
64
|
+
set_searchd_settings
|
65
|
+
set_path_settings
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_path_settings
|
69
|
+
thinking_sphinx.searchd_file_path = "#{base_path}/indexes"
|
70
|
+
|
71
|
+
riddle.searchd.pid_file = "#{base_path}/searchd.pid"
|
72
|
+
riddle.searchd.log = "#{log_path}/searchd.log"
|
73
|
+
riddle.searchd.query_log = "#{log_path}/searchd.query.log"
|
74
|
+
end
|
75
|
+
|
76
|
+
def set_searchd_settings
|
77
|
+
thinking_sphinx_configuration.port = port
|
78
|
+
thinking_sphinx_configuration.address = host
|
79
|
+
end
|
80
|
+
|
81
|
+
def set_database_settings
|
82
|
+
riddle.indexes.each do |index|
|
83
|
+
next unless index.respond_to?(:sources)
|
84
|
+
|
85
|
+
index.sources.each do |source|
|
86
|
+
source.sql_host = '127.0.0.1'
|
87
|
+
source.sql_port = configuration.database_port
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def heroku_id_from_env
|
93
|
+
ENV['APP_NAME'] + '@heroku.com'
|
94
|
+
end
|
95
|
+
|
96
|
+
def api_key_from_env
|
97
|
+
ENV['FLYING_SPHINX_API_KEY']
|
98
|
+
end
|
24
99
|
end
|
@@ -16,41 +16,7 @@ class FlyingSphinx::IndexRequest
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def update_sphinx_configuration
|
19
|
-
api.put '/app', :configuration => sphinx_configuration
|
20
|
-
end
|
21
|
-
|
22
|
-
def sphinx_configuration
|
23
|
-
ts_config = ThinkingSphinx::Configuration.instance
|
24
|
-
ts_config.port = configuration.port
|
25
|
-
ts_config.address = configuration.host
|
26
|
-
|
27
|
-
riddle_config = ts_config.configuration
|
28
|
-
|
29
|
-
app_name = configuration.heroku_id.split('@').first
|
30
|
-
base_path = "/mnt/sphinx/flying-sphinx/#{app_name}"
|
31
|
-
ts_config.searchd_file_path = "#{base_path}/indexes"
|
32
|
-
riddle_config.searchd.pid_file = "#{base_path}/searchd.pid"
|
33
|
-
riddle_config.searchd.log = "#{base_path}/log/searchd.log"
|
34
|
-
riddle_config.searchd.query_log = "#{base_path}/log/searchd.query.log"
|
35
|
-
|
36
|
-
riddle_config.indexes.clear
|
37
|
-
|
38
|
-
ThinkingSphinx.context.indexed_models.each do |model|
|
39
|
-
model = model.constantize
|
40
|
-
model.define_indexes
|
41
|
-
riddle_config.indexes.concat model.to_riddle
|
42
|
-
end
|
43
|
-
|
44
|
-
riddle_config.indexes.each do |index|
|
45
|
-
next unless index.respond_to?(:sources)
|
46
|
-
|
47
|
-
index.sources.each do |source|
|
48
|
-
source.sql_host = '127.0.0.1'
|
49
|
-
source.sql_port = configuration.database_port
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
riddle_config.render
|
19
|
+
api.put '/app', :configuration => configuration.sphinx_configuration
|
54
20
|
end
|
55
21
|
|
56
22
|
def begin_request
|
data/lib/flying_sphinx/tasks.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
namespace :fs do
|
2
|
-
task :index => :environment
|
2
|
+
task :index => :environment do
|
3
|
+
FlyingSphinx::IndexRequest.new FlyingSphinx::Configuration.new
|
4
|
+
end
|
3
5
|
|
4
|
-
task :start => :environment
|
6
|
+
task :start => :environment do
|
7
|
+
FlyingSphinx::Configuration.new.start_sphinx
|
8
|
+
end
|
5
9
|
|
6
|
-
task :stop => :environment
|
10
|
+
task :stop => :environment do
|
11
|
+
FlyingSphinx::Configuration.new.stop_sphinx
|
12
|
+
end
|
7
13
|
|
8
14
|
task :restart => [:environment, :stop, :start]
|
15
|
+
task :rebuild => [:environment, :stop, :index, :start]
|
9
16
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flying-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pat Allan
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-16 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|