flying-sphinx 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/HISTORY +48 -0
- data/README.textile +36 -1
- data/flying-sphinx.gemspec +1 -2
- data/lib/flying_sphinx/api.rb +1 -1
- data/lib/flying_sphinx/configuration.rb +24 -0
- data/lib/flying_sphinx/index_request.rb +16 -1
- data/lib/flying_sphinx/rails.rb +1 -1
- data/lib/flying_sphinx/railtie.rb +1 -1
- data/spec/specs/index_request_spec.rb +28 -1
- metadata +4 -2
data/.travis.yml
ADDED
data/HISTORY
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
0.5.2 - 28th July 2011
|
2
|
+
* Log SSH exceptions during indexing (when we're being verbose).
|
3
|
+
* This history file now exists (pre-populated).
|
4
|
+
* An actual README, courtesy of some prodding by Mislav.
|
5
|
+
* Added support for wordforms (automatically sent through to the server).
|
6
|
+
* Don't presume that ENV['DATABASE_URL'] exists - it won't in non-Heroku environments.
|
7
|
+
|
8
|
+
0.5.1 - 23rd June 2011
|
9
|
+
* Adding rake as a development dependency, just for Travis CI.
|
10
|
+
* Have a default database port - Cedar stack doesn't set it by default.
|
11
|
+
* Allow for newer net-ssh gem versions (including 2.1).
|
12
|
+
* Sinatra loader (equivalent of a Railtie).
|
13
|
+
* Fixed bug for handling JSON always as a Hash (sometimes it's an Array).
|
14
|
+
* Better error checking when index requests don't get created as expected.
|
15
|
+
|
16
|
+
0.5.0 - 12th May 2011
|
17
|
+
* Rake tasks for latest actions and last index log.
|
18
|
+
* Switching to version 2 of the API.
|
19
|
+
* Adding default rake task for Travis CI.
|
20
|
+
* Allow for Rails 2 versions of Delayed Job.
|
21
|
+
* Set client_key for connections, configuration if supported by Riddle and Thinking Sphinx.
|
22
|
+
* Allow server to automatically close SSH connections.
|
23
|
+
* Adding logging on API calls (Josh Kalderimis).
|
24
|
+
* Allow for non-tunnelled index requests (for RDS).
|
25
|
+
* Don't use custom database adapter if the database is MySQL.
|
26
|
+
* Fall back to environment variables for connection settings.
|
27
|
+
* Switching from JSON and HTTParty to MultiJSON and Faraday (Josh Kalderimis).
|
28
|
+
* Using Bundler as gem driver instead of Jeweler (Josh Kalderimis).
|
29
|
+
* More flexible JSON dependency.
|
30
|
+
|
31
|
+
0.4.4 - 7th February 2011
|
32
|
+
* Using ActiveRecord's connection information, as we can't rely on heroku_env.yml to be around.
|
33
|
+
|
34
|
+
0.4.3 - 4th February 2011
|
35
|
+
* Wait until the SSH session and forward is prepared before making the index request.
|
36
|
+
* If credentials are invalid, raise an appropriate error instead of letting the JSON parsing fail.
|
37
|
+
|
38
|
+
0.4.2 - 29th January 2011
|
39
|
+
* Set the Thinking Sphinx database adapter when loaded, instead of requiring the Rails dispatcher to setup.
|
40
|
+
|
41
|
+
0.4.1 - 24th January 2011
|
42
|
+
* Comparing against response bodies for consistency (and avoiding HTTParty magic).
|
43
|
+
|
44
|
+
0.4.0 - 18th January 2011
|
45
|
+
* Using HTTPS for API calls.
|
46
|
+
* Using Flying Sphinx server's account identifier instead of the heroku id from the environment (the latter being unreliable and not part of any official Heroku add-on documentation).
|
47
|
+
|
48
|
+
Note: Any releases before this were most definitely experimental and pre-alpha.
|
data/README.textile
CHANGED
@@ -1,3 +1,38 @@
|
|
1
1
|
h1. Flying Sphinx
|
2
2
|
|
3
|
-
|
3
|
+
This library is the code behind the @flying-sphinx@ gem. Its sole purpose is to connect Thinking Sphinx to the "Flying Sphinx Heroku addon":http://addons.heroku.com/flying_sphinx - and so you can just use Thinking Sphinx as normal on Heroku-hosted sites.
|
4
|
+
|
5
|
+
h2. Installation and Usage
|
6
|
+
|
7
|
+
This is all covered pretty well on "the Flying Sphinx site":http://flying-sphinx.com/docs, but if you're reading this on Github, you're probably keen on using this repository as the source instead of the gem. Here's the code snippet for your @Gemfile@:
|
8
|
+
|
9
|
+
<pre><code>gem 'flying-sphinx',
|
10
|
+
:git => 'git://github.com/flying-sphinx/flying-sphinx.git'</code></pre>
|
11
|
+
|
12
|
+
h2. Compatibility and Limitations
|
13
|
+
|
14
|
+
Flying Sphinx is built with support for Rails 2.3.6 and beyond. Sadly, earlier versions of Rails aren't supported due to a requirement of a recent version of Rack deep in the dependency tree. It's not tested against Rails 3.1 at this time, but in theory should work fine. Let me know if I'm wrong!
|
15
|
+
|
16
|
+
It works with Rails 1.8.7 and 1.9.2, and on both Heroku's Bamboo and Cedar stacks. You _do_ need to use it with Heroku at this point - allowing others hosting elsewhere to use Flying Sphinx is something I'm considering, but it's not possible right now.
|
17
|
+
|
18
|
+
There are limitations with Heroku's setup and Sphinx/Thinking Sphinx functionality - again, the official documentation "covers this":http://flying-sphinx.com/docs#limitations, so have a read there.
|
19
|
+
|
20
|
+
h2. Contributing
|
21
|
+
|
22
|
+
Patches are indeed welcome - though I understand it's a little tricky to test them thoroughly. It's best to give your changes a spin on your Heroku app that's running Flying Sphinx (and if you don't have one of those, I'm a little confused as to why you're contributing).
|
23
|
+
|
24
|
+
API documentation is required - consider this paragraph a placeholder for that.
|
25
|
+
|
26
|
+
In the meantime, please keep in mind the following:
|
27
|
+
|
28
|
+
* Write tests using RSpec
|
29
|
+
* Keep your commits in a separate branch
|
30
|
+
* Don't change the version or History file in your feature branch - makes merging changes much easier.
|
31
|
+
|
32
|
+
h2. Contributors
|
33
|
+
|
34
|
+
* "Josh Kalderimis":http://blog.cookiestack.com/ for switching the API calls to Faraday, improving the specs, a ton of debugging, and encouraging a versioned API.
|
35
|
+
|
36
|
+
h2. Licence
|
37
|
+
|
38
|
+
Copyright © 2011 Pat Allan, released under an MIT licence.
|
data/flying-sphinx.gemspec
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'flying-sphinx'
|
4
|
-
s.version = '0.5.
|
4
|
+
s.version = '0.5.2'
|
5
5
|
s.authors = ['Pat Allan']
|
6
6
|
s.email = 'pat@freelancing-gods.com'
|
7
|
-
s.date = '2011-05-12'
|
8
7
|
s.summary = 'Sphinx in the Cloud'
|
9
8
|
s.description = 'Hooks Thinking Sphinx into the Flying Sphinx service'
|
10
9
|
s.homepage = 'https://flying-sphinx.com'
|
data/lib/flying_sphinx/api.rb
CHANGED
@@ -16,9 +16,20 @@ class FlyingSphinx::Configuration
|
|
16
16
|
def sphinx_configuration
|
17
17
|
thinking_sphinx.generate
|
18
18
|
set_database_settings
|
19
|
+
set_wordforms
|
19
20
|
|
20
21
|
riddle.render
|
21
22
|
end
|
23
|
+
|
24
|
+
def wordform_file_pairs
|
25
|
+
@wordform_file_pairs ||= begin
|
26
|
+
pairs = {}
|
27
|
+
wordform_sources.each_with_index do |source, index|
|
28
|
+
pairs[source] = "#{base_path}/wordforms/#{index}.txt"
|
29
|
+
end
|
30
|
+
pairs
|
31
|
+
end
|
32
|
+
end
|
22
33
|
|
23
34
|
def start_sphinx
|
24
35
|
api.post('start')
|
@@ -112,6 +123,19 @@ class FlyingSphinx::Configuration
|
|
112
123
|
end
|
113
124
|
end
|
114
125
|
end
|
126
|
+
|
127
|
+
def set_wordforms
|
128
|
+
riddle.indexes.each do |index|
|
129
|
+
next unless index.respond_to?(:wordforms)
|
130
|
+
index.wordforms = wordform_file_pairs[index.wordforms]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def wordform_sources
|
135
|
+
@wordform_sources ||= riddle.indexes.collect { |index|
|
136
|
+
index.respond_to?(:wordforms) ? index.wordforms : nil
|
137
|
+
}.flatten.compact.uniq
|
138
|
+
end
|
115
139
|
|
116
140
|
def identifier_from_env
|
117
141
|
ENV['FLYING_SPHINX_IDENTIFIER']
|
@@ -30,6 +30,7 @@ class FlyingSphinx::IndexRequest
|
|
30
30
|
|
31
31
|
def update_and_index
|
32
32
|
update_sphinx_configuration
|
33
|
+
update_sphinx_reference_files
|
33
34
|
index
|
34
35
|
end
|
35
36
|
|
@@ -68,6 +69,15 @@ class FlyingSphinx::IndexRequest
|
|
68
69
|
def update_sphinx_configuration
|
69
70
|
api.put('/', :configuration => configuration.sphinx_configuration)
|
70
71
|
end
|
72
|
+
|
73
|
+
def update_sphinx_reference_files
|
74
|
+
configuration.wordform_file_pairs.each do |local, remote|
|
75
|
+
api.post '/add_file',
|
76
|
+
:setting => 'wordforms',
|
77
|
+
:file_name => remote.split('/').last,
|
78
|
+
:content => open(local).read
|
79
|
+
end
|
80
|
+
end
|
71
81
|
|
72
82
|
def index
|
73
83
|
if FlyingSphinx::Tunnel.required?
|
@@ -75,9 +85,10 @@ class FlyingSphinx::IndexRequest
|
|
75
85
|
else
|
76
86
|
direct_index
|
77
87
|
end
|
78
|
-
rescue Net::SSH::Exception
|
88
|
+
rescue Net::SSH::Exception => err
|
79
89
|
# Server closed the connection on us. That's (hopefully) expected, nothing
|
80
90
|
# to worry about.
|
91
|
+
puts "SSH/Indexing Error: #{err.message}" if log?
|
81
92
|
rescue RuntimeError => err
|
82
93
|
puts err.message
|
83
94
|
end
|
@@ -137,4 +148,8 @@ class FlyingSphinx::IndexRequest
|
|
137
148
|
def api
|
138
149
|
configuration.api
|
139
150
|
end
|
151
|
+
|
152
|
+
def log?
|
153
|
+
ENV['VERBOSE_LOGGING'] && ENV['VERBOSE_LOGGING'].length > 0
|
154
|
+
end
|
140
155
|
end
|
data/lib/flying_sphinx/rails.rb
CHANGED
@@ -10,7 +10,7 @@ unless Rails.env.development? || Rails.env.test?
|
|
10
10
|
config.client_key
|
11
11
|
end
|
12
12
|
|
13
|
-
if ENV['DATABASE_URL'][/^mysql/].nil?
|
13
|
+
if ENV['DATABASE_URL'] && ENV['DATABASE_URL'][/^mysql/].nil?
|
14
14
|
ThinkingSphinx.database_adapter = FlyingSphinx::HerokuSharedAdapter
|
15
15
|
end
|
16
16
|
end
|
@@ -11,7 +11,7 @@ class FlyingSphinx::Railtie < Rails::Railtie
|
|
11
11
|
ThinkingSphinx::Configuration.instance.configuration.searchd.client_key =
|
12
12
|
config.client_key
|
13
13
|
|
14
|
-
if ENV['DATABASE_URL'][/^mysql/].nil?
|
14
|
+
if ENV['DATABASE_URL'] && ENV['DATABASE_URL'][/^mysql/].nil?
|
15
15
|
ThinkingSphinx.database_adapter = FlyingSphinx::HerokuSharedAdapter
|
16
16
|
end
|
17
17
|
end unless Rails.env.development? || Rails.env.test?
|
@@ -3,7 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe FlyingSphinx::IndexRequest do
|
4
4
|
let(:api) { FlyingSphinx::API.new 'foo', 'bar' }
|
5
5
|
let(:configuration) {
|
6
|
-
stub(:configuration, :api => api, :sphinx_configuration => 'foo {}'
|
6
|
+
stub(:configuration, :api => api, :sphinx_configuration => 'foo {}',
|
7
|
+
:wordform_file_pairs => {})
|
7
8
|
}
|
8
9
|
|
9
10
|
let(:index_response) {
|
@@ -67,6 +68,32 @@ describe FlyingSphinx::IndexRequest do
|
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
71
|
+
context 'with wordforms' do
|
72
|
+
let(:file_params) {
|
73
|
+
{:setting => 'wordforms', :file_name => 'bar.txt', :content => 'baz'}
|
74
|
+
}
|
75
|
+
|
76
|
+
before :each do
|
77
|
+
configuration.stub!(:wordform_file_pairs => {'foo.txt' => 'bar.txt'})
|
78
|
+
index_request.stub!(:open => double('file', :read => 'baz'))
|
79
|
+
end
|
80
|
+
|
81
|
+
it "sends the wordform file" do
|
82
|
+
api.should_receive(:put).with('/', conf_params).and_return('ok')
|
83
|
+
api.should_receive(:post).with('/add_file', file_params).
|
84
|
+
and_return('ok')
|
85
|
+
api.should_receive(:post).
|
86
|
+
with('indices', index_params).and_return(index_response)
|
87
|
+
|
88
|
+
begin
|
89
|
+
Timeout::timeout(0.2) {
|
90
|
+
index_request.update_and_index
|
91
|
+
}
|
92
|
+
rescue Timeout::Error
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
70
97
|
context 'delta request without delta support' do
|
71
98
|
it "should explain why the request failed" do
|
72
99
|
api.should_receive(:put).
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: flying-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.5.
|
5
|
+
version: 0.5.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Pat Allan
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-28 00:00:00 +10:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -166,7 +166,9 @@ extra_rdoc_files:
|
|
166
166
|
- README.textile
|
167
167
|
files:
|
168
168
|
- .gitignore
|
169
|
+
- .travis.yml
|
169
170
|
- Gemfile
|
171
|
+
- HISTORY
|
170
172
|
- LICENCE
|
171
173
|
- README.textile
|
172
174
|
- Rakefile
|