thinking-sphinx 1.3.7 → 1.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -0
- data/VERSION +1 -1
- data/features/sphinx_scopes.feature +7 -0
- data/features/step_definitions/scope_steps.rb +4 -0
- data/features/support/env.rb +1 -2
- data/lib/thinking_sphinx.rb +4 -0
- data/lib/thinking_sphinx/active_record.rb +6 -0
- data/lib/thinking_sphinx/auto_version.rb +22 -0
- data/lib/thinking_sphinx/configuration.rb +38 -14
- data/lib/thinking_sphinx/context.rb +13 -4
- data/lib/thinking_sphinx/search.rb +3 -0
- data/rails/init.rb +1 -1
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +22 -0
- data/spec/thinking_sphinx/active_record_spec.rb +26 -0
- data/spec/thinking_sphinx/auto_version_spec.rb +39 -0
- data/tasks/distribution.rb +1 -1
- metadata +5 -5
- data/lib/thinking_sphinx/0.9.8.rb +0 -3
- data/lib/thinking_sphinx/0.9.9.rb +0 -3
data/README.textile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.8
|
@@ -33,3 +33,10 @@ Feature: Sphinx Scopes
|
|
33
33
|
And I am searching on people
|
34
34
|
When I use the ids_only scope
|
35
35
|
Then I should have an array of integers
|
36
|
+
|
37
|
+
Scenario: Counts with scopes
|
38
|
+
Given Sphinx is running
|
39
|
+
And I am searching on people
|
40
|
+
When I use the with_first_name scope set to "Andrew"
|
41
|
+
And I am retrieving the scoped result count
|
42
|
+
Then I should get a value of 7
|
data/features/support/env.rb
CHANGED
@@ -16,7 +16,6 @@ require 'cucumber/thinking_sphinx/internal_world'
|
|
16
16
|
world = Cucumber::ThinkingSphinx::InternalWorld.new
|
17
17
|
world.configure_database
|
18
18
|
|
19
|
-
|
20
|
-
require "thinking_sphinx/#{SphinxVersion}"
|
19
|
+
require "thinking_sphinx"
|
21
20
|
|
22
21
|
world.setup
|
data/lib/thinking_sphinx.rb
CHANGED
@@ -2,7 +2,9 @@ require 'active_record'
|
|
2
2
|
require 'after_commit'
|
3
3
|
require 'yaml'
|
4
4
|
require 'cgi'
|
5
|
+
require 'riddle'
|
5
6
|
|
7
|
+
require 'thinking_sphinx/auto_version'
|
6
8
|
require 'thinking_sphinx/core/array'
|
7
9
|
require 'thinking_sphinx/core/string'
|
8
10
|
require 'thinking_sphinx/property'
|
@@ -221,3 +223,5 @@ module ThinkingSphinx
|
|
221
223
|
|
222
224
|
extend ThinkingSphinx::SearchMethods::ClassMethods
|
223
225
|
end
|
226
|
+
|
227
|
+
ThinkingSphinx::AutoVersion.detect
|
@@ -177,6 +177,12 @@ module ThinkingSphinx
|
|
177
177
|
subclasses.each { |klass| klass.add_sphinx_index(index) }
|
178
178
|
end
|
179
179
|
|
180
|
+
def has_sphinx_indexes?
|
181
|
+
sphinx_indexes &&
|
182
|
+
sphinx_index_blocks &&
|
183
|
+
(sphinx_indexes.length > 0 || sphinx_index_blocks.length > 0)
|
184
|
+
end
|
185
|
+
|
180
186
|
def indexed_by_sphinx?
|
181
187
|
sphinx_indexes && sphinx_indexes.length > 0
|
182
188
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ThinkingSphinx
|
2
|
+
class AutoVersion
|
3
|
+
def self.detect
|
4
|
+
version = ThinkingSphinx::Configuration.instance.controller.sphinx_version
|
5
|
+
case version
|
6
|
+
when '0.9.8', '0.9.9'
|
7
|
+
require "riddle/#{version}"
|
8
|
+
else
|
9
|
+
STDERR.puts %Q{
|
10
|
+
Sphinx cannot be found on your system. You may need to configure the following
|
11
|
+
settings in your config/sphinx.yml file:
|
12
|
+
* bin_path
|
13
|
+
* searchd_binary_name
|
14
|
+
* indexer_binary_name
|
15
|
+
|
16
|
+
For more information, read the documentation:
|
17
|
+
http://freelancing-god.github.com/ts/en/advanced_config.html
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -64,14 +64,12 @@ module ThinkingSphinx
|
|
64
64
|
|
65
65
|
CustomOptions = %w( disable_range )
|
66
66
|
|
67
|
-
attr_accessor :
|
68
|
-
:
|
69
|
-
:database_yml_file, :app_root, :bin_path, :model_directories,
|
70
|
-
:delayed_job_priority, :searchd_binary_name, :indexer_binary_name
|
67
|
+
attr_accessor :searchd_file_path, :allow_star, :database_yml_file,
|
68
|
+
:app_root, :model_directories, :delayed_job_priority
|
71
69
|
|
72
70
|
attr_accessor :source_options, :index_options
|
73
71
|
|
74
|
-
attr_reader :environment, :configuration
|
72
|
+
attr_reader :environment, :configuration, :controller
|
75
73
|
|
76
74
|
# Load in the configuration settings - this will look for config/sphinx.yml
|
77
75
|
# and parse it according to the current environment.
|
@@ -101,11 +99,12 @@ module ThinkingSphinx
|
|
101
99
|
@configuration.searchd.log = "#{self.app_root}/log/searchd.log"
|
102
100
|
@configuration.searchd.query_log = "#{self.app_root}/log/searchd.query.log"
|
103
101
|
|
102
|
+
@controller = Riddle::Controller.new @configuration,
|
103
|
+
"#{self.app_root}/config/#{environment}.sphinx.conf"
|
104
|
+
|
104
105
|
self.database_yml_file = "#{self.app_root}/config/database.yml"
|
105
|
-
self.config_file = "#{self.app_root}/config/#{environment}.sphinx.conf"
|
106
106
|
self.searchd_file_path = "#{self.app_root}/db/sphinx/#{environment}"
|
107
107
|
self.allow_star = false
|
108
|
-
self.bin_path = ""
|
109
108
|
self.model_directories = ["#{app_root}/app/models/"] +
|
110
109
|
Dir.glob("#{app_root}/vendor/plugins/*/app/models/")
|
111
110
|
self.delayed_job_priority = 0
|
@@ -115,9 +114,6 @@ module ThinkingSphinx
|
|
115
114
|
:charset_type => "utf-8"
|
116
115
|
}
|
117
116
|
|
118
|
-
self.searchd_binary_name = "searchd"
|
119
|
-
self.indexer_binary_name = "indexer"
|
120
|
-
|
121
117
|
parse_config
|
122
118
|
|
123
119
|
self
|
@@ -133,10 +129,6 @@ module ThinkingSphinx
|
|
133
129
|
self.class.environment
|
134
130
|
end
|
135
131
|
|
136
|
-
def controller
|
137
|
-
@controller ||= Riddle::Controller.new(@configuration, self.config_file)
|
138
|
-
end
|
139
|
-
|
140
132
|
# Generate the config file for Sphinx by using all the settings defined and
|
141
133
|
# looping through all the models with indexes to build the relevant
|
142
134
|
# indexer and searchd configuration, and sources and indexes details.
|
@@ -197,6 +189,38 @@ module ThinkingSphinx
|
|
197
189
|
@configuration.searchd.query_log = file
|
198
190
|
end
|
199
191
|
|
192
|
+
def config_file
|
193
|
+
@controller.path
|
194
|
+
end
|
195
|
+
|
196
|
+
def config_file=(file)
|
197
|
+
@controller.path = file
|
198
|
+
end
|
199
|
+
|
200
|
+
def bin_path
|
201
|
+
@controller.bin_path
|
202
|
+
end
|
203
|
+
|
204
|
+
def bin_path=(path)
|
205
|
+
@controller.bin_path = path
|
206
|
+
end
|
207
|
+
|
208
|
+
def searchd_binary_name
|
209
|
+
@controller.searchd_binary_name
|
210
|
+
end
|
211
|
+
|
212
|
+
def searchd_binary_name=(name)
|
213
|
+
@controller.searchd_binary_name = name
|
214
|
+
end
|
215
|
+
|
216
|
+
def indexer_binary_name
|
217
|
+
@controller.indexer_binary_name
|
218
|
+
end
|
219
|
+
|
220
|
+
def indexer_binary_name=(name)
|
221
|
+
@controller.indexer_binary_name = name
|
222
|
+
end
|
223
|
+
|
200
224
|
def client
|
201
225
|
client = Riddle::Client.new address, port
|
202
226
|
client.max_matches = configuration.searchd.max_matches || 1000
|
@@ -7,6 +7,7 @@ class ThinkingSphinx::Context
|
|
7
7
|
|
8
8
|
def prepare
|
9
9
|
load_models
|
10
|
+
add_indexed_models if cached?
|
10
11
|
end
|
11
12
|
|
12
13
|
def define_indexes
|
@@ -32,15 +33,23 @@ class ThinkingSphinx::Context
|
|
32
33
|
|
33
34
|
private
|
34
35
|
|
36
|
+
def cached?
|
37
|
+
defined?(Rails) &&
|
38
|
+
Rails::VERSION::STRING.to_f > 2.1 &&
|
39
|
+
Rails.configuration.cache_classes
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_indexed_models
|
43
|
+
Object.subclasses_of(ActiveRecord::Base).each do |klass|
|
44
|
+
add_indexed_model klass if klass.has_sphinx_indexes?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
35
48
|
# Make sure all models are loaded - without reloading any that
|
36
49
|
# ActiveRecord::Base is already aware of (otherwise we start to hit some
|
37
50
|
# messy dependencies issues).
|
38
51
|
#
|
39
52
|
def load_models
|
40
|
-
return if defined?(Rails) &&
|
41
|
-
Rails::VERSION::STRING.to_f > 2.1 &&
|
42
|
-
Rails.configuration.cache_classes
|
43
|
-
|
44
53
|
ThinkingSphinx::Configuration.instance.model_directories.each do |base|
|
45
54
|
Dir["#{base}**/*.rb"].each do |file|
|
46
55
|
model_name = file.gsub(/^#{base}([\w_\/\\]+)\.rb/, '\1')
|
@@ -92,6 +92,9 @@ module ThinkingSphinx
|
|
92
92
|
if is_scope?(method)
|
93
93
|
add_scope(method, *args, &block)
|
94
94
|
return self
|
95
|
+
elsif method == :search_count
|
96
|
+
@options[:ids_only] = true
|
97
|
+
return self.total_entries
|
95
98
|
elsif method.to_s[/^each_with_.*/].nil? && !@array.respond_to?(method)
|
96
99
|
super
|
97
100
|
elsif !SafeMethods.include?(method.to_s)
|
data/rails/init.rb
CHANGED
@@ -2,7 +2,7 @@ Dir[File.join(File.dirname(__FILE__), '../vendor/*/lib')].each do |path|
|
|
2
2
|
$LOAD_PATH.unshift path
|
3
3
|
end
|
4
4
|
|
5
|
-
require 'thinking_sphinx
|
5
|
+
require 'thinking_sphinx'
|
6
6
|
require 'action_controller/dispatcher'
|
7
7
|
|
8
8
|
ActionController::Dispatcher.to_prepare :thinking_sphinx do
|
@@ -137,4 +137,26 @@ describe ThinkingSphinx::ActiveRecord::Scopes do
|
|
137
137
|
search.with_betas.options[:classes].should == [Alpha, Beta]
|
138
138
|
end
|
139
139
|
end
|
140
|
+
|
141
|
+
describe '.search_count_with_scope' do
|
142
|
+
before :each do
|
143
|
+
@config = ThinkingSphinx::Configuration.instance
|
144
|
+
@client = Riddle::Client.new
|
145
|
+
|
146
|
+
@config.stub!(:client => @client)
|
147
|
+
@client.stub!(:query => {:matches => [], :total_found => 43})
|
148
|
+
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should return the total number of results" do
|
152
|
+
Alpha.by_name('foo').search_count.should == 43
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should not make any calls to the database" do
|
156
|
+
Alpha.should_not_receive(:find)
|
157
|
+
|
158
|
+
Alpha.by_name('foo').search_count
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
140
162
|
end
|
@@ -16,6 +16,9 @@ describe ThinkingSphinx::ActiveRecord do
|
|
16
16
|
Alpha.sphinx_indexes.replace @existing_alpha_indexes
|
17
17
|
Beta.sphinx_indexes.replace @existing_beta_indexes
|
18
18
|
|
19
|
+
Alpha.send :defined_indexes=, true
|
20
|
+
Beta.send :defined_indexes=, true
|
21
|
+
|
19
22
|
Alpha.sphinx_index_blocks.clear
|
20
23
|
Beta.sphinx_index_blocks.clear
|
21
24
|
end
|
@@ -585,4 +588,27 @@ describe ThinkingSphinx::ActiveRecord do
|
|
585
588
|
Parent.sphinx_offset.should == 1
|
586
589
|
end
|
587
590
|
end
|
591
|
+
|
592
|
+
describe '.has_sphinx_indexes?' do
|
593
|
+
it "should return true if there are sphinx indexes defined" do
|
594
|
+
Alpha.sphinx_indexes.replace [stub('index')]
|
595
|
+
Alpha.sphinx_index_blocks.replace []
|
596
|
+
|
597
|
+
Alpha.should have_sphinx_indexes
|
598
|
+
end
|
599
|
+
|
600
|
+
it "should return true if there are sphinx index blocks defined" do
|
601
|
+
Alpha.sphinx_indexes.replace []
|
602
|
+
Alpha.sphinx_index_blocks.replace [stub('lambda')]
|
603
|
+
|
604
|
+
Alpha.should have_sphinx_indexes
|
605
|
+
end
|
606
|
+
|
607
|
+
it "should return false if there are no sphinx indexes or blocks" do
|
608
|
+
Alpha.sphinx_indexes.clear
|
609
|
+
Alpha.sphinx_index_blocks.clear
|
610
|
+
|
611
|
+
Alpha.should_not have_sphinx_indexes
|
612
|
+
end
|
613
|
+
end
|
588
614
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::AutoVersion do
|
4
|
+
describe '.detect' do
|
5
|
+
before :each do
|
6
|
+
@controller = ThinkingSphinx::Configuration.instance.controller
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should require 0.9.8 if that is the detected version" do
|
10
|
+
ThinkingSphinx::AutoVersion.should_receive(:require).
|
11
|
+
with('riddle/0.9.8')
|
12
|
+
|
13
|
+
@controller.stub!(:sphinx_version => '0.9.8')
|
14
|
+
ThinkingSphinx::AutoVersion.detect
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should require 0.9.9 if that is the detected version" do
|
18
|
+
ThinkingSphinx::AutoVersion.should_receive(:require).
|
19
|
+
with('riddle/0.9.9')
|
20
|
+
|
21
|
+
@controller.stub!(:sphinx_version => '0.9.9')
|
22
|
+
ThinkingSphinx::AutoVersion.detect
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should output a warning if the detected version is something else" do
|
26
|
+
STDERR.should_receive(:puts)
|
27
|
+
|
28
|
+
@controller.stub!(:sphinx_version => '0.9.7')
|
29
|
+
ThinkingSphinx::AutoVersion.detect
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should output a warning if the version cannot be determined" do
|
33
|
+
STDERR.should_receive(:puts)
|
34
|
+
|
35
|
+
@controller.stub!(:sphinx_version => nil)
|
36
|
+
ThinkingSphinx::AutoVersion.detect
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/tasks/distribution.rb
CHANGED
@@ -28,7 +28,7 @@ Jeweler::Tasks.new do |gem|
|
|
28
28
|
]
|
29
29
|
|
30
30
|
gem.add_dependency 'activerecord', '>= 1.15.6'
|
31
|
-
gem.add_dependency 'riddle', '>= 1.0.
|
31
|
+
gem.add_dependency 'riddle', '>= 1.0.6'
|
32
32
|
gem.add_dependency 'after_commit', '>= 1.0.5'
|
33
33
|
|
34
34
|
gem.post_install_message = <<-MESSAGE
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-02 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0.
|
33
|
+
version: 1.0.6
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: after_commit
|
@@ -58,8 +58,6 @@ files:
|
|
58
58
|
- lib/cucumber/thinking_sphinx/internal_world.rb
|
59
59
|
- lib/cucumber/thinking_sphinx/sql_logger.rb
|
60
60
|
- lib/thinking_sphinx.rb
|
61
|
-
- lib/thinking_sphinx/0.9.8.rb
|
62
|
-
- lib/thinking_sphinx/0.9.9.rb
|
63
61
|
- lib/thinking_sphinx/active_record.rb
|
64
62
|
- lib/thinking_sphinx/active_record/attribute_updates.rb
|
65
63
|
- lib/thinking_sphinx/active_record/delta.rb
|
@@ -70,6 +68,7 @@ files:
|
|
70
68
|
- lib/thinking_sphinx/adapters/postgresql_adapter.rb
|
71
69
|
- lib/thinking_sphinx/association.rb
|
72
70
|
- lib/thinking_sphinx/attribute.rb
|
71
|
+
- lib/thinking_sphinx/auto_version.rb
|
73
72
|
- lib/thinking_sphinx/class_facet.rb
|
74
73
|
- lib/thinking_sphinx/configuration.rb
|
75
74
|
- lib/thinking_sphinx/context.rb
|
@@ -218,6 +217,7 @@ test_files:
|
|
218
217
|
- spec/thinking_sphinx/active_record_spec.rb
|
219
218
|
- spec/thinking_sphinx/association_spec.rb
|
220
219
|
- spec/thinking_sphinx/attribute_spec.rb
|
220
|
+
- spec/thinking_sphinx/auto_version_spec.rb
|
221
221
|
- spec/thinking_sphinx/configuration_spec.rb
|
222
222
|
- spec/thinking_sphinx/context_spec.rb
|
223
223
|
- spec/thinking_sphinx/core/array_spec.rb
|