thinking-sphinx 1.5.0 → 2.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +15 -48
- data/VERSION +1 -0
- data/features/attribute_transformation.feature +7 -7
- data/features/attribute_updates.feature +16 -18
- data/features/deleting_instances.feature +13 -16
- data/features/excerpts.feature +0 -8
- data/features/facets.feature +19 -25
- data/features/handling_edits.feature +20 -25
- data/features/searching_across_models.feature +1 -1
- data/features/searching_by_index.feature +5 -6
- data/features/searching_by_model.feature +29 -29
- data/features/sphinx_scopes.feature +0 -26
- data/features/step_definitions/common_steps.rb +6 -18
- data/features/step_definitions/scope_steps.rb +0 -4
- data/features/step_definitions/search_steps.rb +4 -9
- data/features/support/env.rb +10 -3
- data/features/thinking_sphinx/db/fixtures/alphas.rb +10 -8
- data/features/thinking_sphinx/db/fixtures/cats.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/dogs.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/foxes.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/people.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/posts.rb +1 -5
- data/features/thinking_sphinx/db/migrations/create_posts.rb +0 -1
- data/features/thinking_sphinx/models/alpha.rb +0 -1
- data/features/thinking_sphinx/models/beta.rb +0 -5
- data/features/thinking_sphinx/models/developer.rb +1 -6
- data/features/thinking_sphinx/models/music.rb +1 -3
- data/features/thinking_sphinx/models/person.rb +1 -2
- data/features/thinking_sphinx/models/post.rb +0 -1
- data/lib/cucumber/thinking_sphinx/external_world.rb +4 -8
- data/lib/cucumber/thinking_sphinx/internal_world.rb +27 -36
- data/lib/thinking_sphinx.rb +60 -132
- data/lib/thinking_sphinx/active_record.rb +98 -124
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +13 -17
- data/lib/thinking_sphinx/active_record/delta.rb +15 -21
- data/lib/thinking_sphinx/active_record/has_many_association.rb +23 -16
- data/lib/thinking_sphinx/active_record/scopes.rb +0 -18
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +15 -63
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +0 -4
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +24 -65
- data/lib/thinking_sphinx/association.rb +11 -36
- data/lib/thinking_sphinx/attribute.rb +85 -92
- data/lib/thinking_sphinx/auto_version.rb +3 -21
- data/lib/thinking_sphinx/class_facet.rb +3 -8
- data/lib/thinking_sphinx/configuration.rb +58 -114
- data/lib/thinking_sphinx/context.rb +20 -22
- data/lib/thinking_sphinx/core/array.rb +13 -0
- data/lib/thinking_sphinx/deltas.rb +0 -2
- data/lib/thinking_sphinx/deltas/default_delta.rb +22 -18
- data/lib/thinking_sphinx/deploy/capistrano.rb +31 -30
- data/lib/thinking_sphinx/excerpter.rb +1 -2
- data/lib/thinking_sphinx/facet.rb +35 -45
- data/lib/thinking_sphinx/facet_search.rb +24 -58
- data/lib/thinking_sphinx/field.rb +0 -18
- data/lib/thinking_sphinx/index.rb +36 -38
- data/lib/thinking_sphinx/index/builder.rb +59 -74
- data/lib/thinking_sphinx/property.rb +45 -66
- data/lib/thinking_sphinx/railtie.rb +35 -0
- data/lib/thinking_sphinx/search.rb +250 -506
- data/lib/thinking_sphinx/source.rb +31 -50
- data/lib/thinking_sphinx/source/internal_properties.rb +3 -8
- data/lib/thinking_sphinx/source/sql.rb +31 -71
- data/lib/thinking_sphinx/tasks.rb +27 -48
- data/spec/thinking_sphinx/active_record/delta_spec.rb +41 -36
- data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +0 -96
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +29 -29
- data/spec/thinking_sphinx/active_record_spec.rb +169 -140
- data/spec/thinking_sphinx/association_spec.rb +2 -20
- data/spec/thinking_sphinx/attribute_spec.rb +97 -101
- data/spec/thinking_sphinx/auto_version_spec.rb +11 -75
- data/spec/thinking_sphinx/configuration_spec.rb +62 -63
- data/spec/thinking_sphinx/context_spec.rb +66 -66
- data/spec/thinking_sphinx/facet_search_spec.rb +99 -99
- data/spec/thinking_sphinx/facet_spec.rb +4 -30
- data/spec/thinking_sphinx/field_spec.rb +3 -17
- data/spec/thinking_sphinx/index/builder_spec.rb +132 -169
- data/spec/thinking_sphinx/index_spec.rb +39 -45
- data/spec/thinking_sphinx/search_methods_spec.rb +33 -37
- data/spec/thinking_sphinx/search_spec.rb +269 -491
- data/spec/thinking_sphinx/source_spec.rb +48 -62
- data/spec/thinking_sphinx_spec.rb +49 -49
- data/tasks/distribution.rb +46 -0
- data/tasks/testing.rb +74 -0
- metadata +123 -199
- data/features/field_sorting.feature +0 -18
- data/features/thinking_sphinx/db/.gitignore +0 -1
- data/features/thinking_sphinx/db/fixtures/post_keywords.txt +0 -1
- data/features/thinking_sphinx/models/andrew.rb +0 -17
- data/lib/thinking-sphinx.rb +0 -1
- data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +0 -21
- data/lib/thinking_sphinx/bundled_search.rb +0 -40
- data/lib/thinking_sphinx/connection.rb +0 -71
- data/lib/thinking_sphinx/deltas/delete_job.rb +0 -16
- data/lib/thinking_sphinx/deltas/index_job.rb +0 -17
- data/lib/thinking_sphinx/rails_additions.rb +0 -181
- data/spec/fixtures/data.sql +0 -32
- data/spec/fixtures/database.yml.default +0 -3
- data/spec/fixtures/models.rb +0 -161
- data/spec/fixtures/structure.sql +0 -146
- data/spec/spec_helper.rb +0 -54
- data/spec/sphinx_helper.rb +0 -67
- data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +0 -163
- data/spec/thinking_sphinx/connection_spec.rb +0 -77
- data/spec/thinking_sphinx/rails_additions_spec.rb +0 -203
|
@@ -18,7 +18,7 @@ Person.create :gender => "male", :first_name => "Peter", :middle_initial => "C",
|
|
|
18
18
|
Person.create :gender => "female", :first_name => "Hollie", :middle_initial => "C", :last_name => "Hunter", :street_address => "34 Cornish Street", :city => "Kensington", :state => "VIC", :postcode => "3031", :email => "Hollie.C.Hunter@mailinator.com", :birthday => "1954/2/16 00:00:00"
|
|
19
19
|
Person.create :gender => "male", :first_name => "Jonathan", :middle_initial => "C", :last_name => "Turner", :street_address => "2 Kopkes Road", :city => "Carngham", :state => "VIC", :postcode => "3351", :email => "Jonathan.C.Turner@trashymail.com", :birthday => "1963/8/26 00:00:00"
|
|
20
20
|
Person.create :gender => "female", :first_name => "Kate", :middle_initial => "S", :last_name => "Doyle", :street_address => "42 Gregory Way", :city => "Mungalup", :state => "WA", :postcode => "6225", :email => "Kate.S.Doyle@mailinator.com", :birthday => "1974/1/5 00:00:00"
|
|
21
|
-
Person.create :gender => "male", :first_name => "Harley", :middle_initial => "M", :last_name => "
|
|
21
|
+
Person.create :gender => "male", :first_name => "Harley", :middle_initial => "M", :last_name => "Abbott", :street_address => "39 Faulkner Street", :city => "Tilbuster", :state => "NSW", :postcode => "2350", :email => "Harley.M.Abbott@trashymail.com", :birthday => "1953/10/4 00:00:00"
|
|
22
22
|
Person.create :gender => "male", :first_name => "Morgan", :middle_initial => "E", :last_name => "Iqbal", :street_address => "64 Carlisle Street", :city => "Dysart", :state => "VIC", :postcode => "3660", :email => "Morgan.E.Iqbal@spambob.com", :birthday => "1954/7/6 00:00:00"
|
|
23
23
|
Person.create :gender => "female", :first_name => "Phoebe", :middle_initial => "T", :last_name => "Wells", :street_address => "10 Mnimbah Road", :city => "Eccleston", :state => "NSW", :postcode => "2311", :email => "Phoebe.T.Wells@trashymail.com", :birthday => "1949/5/27 00:00:00"
|
|
24
24
|
Person.create :gender => "male", :first_name => "Finley", :middle_initial => "I", :last_name => "Martin", :street_address => "15 Thomas Lane", :city => "Epping", :state => "VIC", :postcode => "3076", :email => "Finley.I.Martin@dodgit.com", :birthday => "1983/3/12 00:00:00"
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
post = Post.create(
|
|
2
|
-
:subject => "Hello World",
|
|
3
|
-
:content => "Um Text",
|
|
4
|
-
:id => 1,
|
|
5
|
-
:category_id => 1,
|
|
6
|
-
:keywords_file => (File.dirname(__FILE__) + '/post_keywords.txt')
|
|
2
|
+
:subject => "Hello World", :content => "Um Text", :id => 1, :category_id => 1
|
|
7
3
|
)
|
|
8
4
|
|
|
9
5
|
post.authors << Author.find(:first)
|
|
@@ -9,13 +9,8 @@ class Developer < ActiveRecord::Base
|
|
|
9
9
|
indexes country, :facet => true
|
|
10
10
|
indexes state, :facet => true
|
|
11
11
|
indexes tags.text, :as => :tags, :facet => true
|
|
12
|
-
|
|
13
12
|
has age, :facet => true
|
|
14
13
|
has tags(:id), :as => :tag_ids, :facet => true
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
facet "LOWER(city)", :as => :city, :type => :string, :value => :city
|
|
18
|
-
|
|
19
|
-
group_by 'city'
|
|
14
|
+
facet city
|
|
20
15
|
end
|
|
21
16
|
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
class Person < ActiveRecord::Base
|
|
2
2
|
define_index do
|
|
3
|
-
indexes first_name, :sortable => true
|
|
4
|
-
indexes last_name, :sortable => :insensitive
|
|
3
|
+
indexes first_name, last_name, :sortable => true
|
|
5
4
|
|
|
6
5
|
has [first_name, middle_initial, last_name], :as => :name_sort
|
|
7
6
|
has birthday
|
|
@@ -11,7 +11,6 @@ class Post < ActiveRecord::Base
|
|
|
11
11
|
indexes tags.text, :as => :tags
|
|
12
12
|
indexes comments.content, :as => :comments
|
|
13
13
|
indexes authors.name, :as => :authors
|
|
14
|
-
indexes keywords_file, :as => :keywords, :file => true
|
|
15
14
|
|
|
16
15
|
has comments(:id), :as => :comment_ids, :source => :ranged_query,
|
|
17
16
|
:facet => true
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
require 'thinking_sphinx/test'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
::ThinkingSphinx::Test.init
|
|
8
|
-
::ThinkingSphinx::Test.start_with_autostop
|
|
9
|
-
end
|
|
10
|
-
end
|
|
3
|
+
class Cucumber::ThinkingSphinx::ExternalWorld
|
|
4
|
+
def initialize(suppress_delta_output = true)
|
|
5
|
+
::ThinkingSphinx::Test.init
|
|
6
|
+
::ThinkingSphinx::Test.start_with_autostop
|
|
11
7
|
end
|
|
12
8
|
end
|
|
@@ -7,7 +7,7 @@ module Cucumber
|
|
|
7
7
|
:models_directory, :fixtures_directory, :database_file
|
|
8
8
|
attr_accessor :adapter, :database, :username,
|
|
9
9
|
:password, :host
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
def initialize
|
|
12
12
|
pwd = Dir.pwd
|
|
13
13
|
@temporary_directory = "#{pwd}/tmp"
|
|
@@ -15,64 +15,55 @@ module Cucumber
|
|
|
15
15
|
@models_directory = "#{pwd}/features/thinking_sphinx/models"
|
|
16
16
|
@fixtures_directory = "#{pwd}/features/thinking_sphinx/db/fixtures"
|
|
17
17
|
@database_file = "#{pwd}/features/thinking_sphinx/database.yml"
|
|
18
|
-
|
|
19
|
-
@adapter =
|
|
18
|
+
|
|
19
|
+
@adapter = ENV['DATABASE'] || 'mysql'
|
|
20
20
|
@database = 'thinking_sphinx'
|
|
21
|
-
@username =
|
|
21
|
+
@username = 'thinking_sphinx'
|
|
22
|
+
# @password = 'thinking_sphinx'
|
|
22
23
|
@host = 'localhost'
|
|
23
|
-
|
|
24
|
-
if ActiveRecord.constants.include?('VERSION')
|
|
25
|
-
@adapter = @adapter.gsub /^mysql$/, 'mysql2'
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
if @adapter[/mysql/]
|
|
29
|
-
@username = 'root'
|
|
30
|
-
elsif ENV['TRAVIS']
|
|
31
|
-
@username = 'postgres'
|
|
32
|
-
end
|
|
33
24
|
end
|
|
34
|
-
|
|
25
|
+
|
|
35
26
|
def setup
|
|
36
27
|
make_temporary_directory
|
|
37
|
-
|
|
28
|
+
|
|
38
29
|
configure_cleanup
|
|
39
30
|
configure_thinking_sphinx
|
|
40
31
|
configure_active_record
|
|
41
|
-
|
|
32
|
+
|
|
42
33
|
prepare_data
|
|
43
34
|
setup_sphinx
|
|
44
|
-
|
|
35
|
+
|
|
45
36
|
self
|
|
46
37
|
end
|
|
47
|
-
|
|
38
|
+
|
|
48
39
|
def configure_database
|
|
49
40
|
ActiveRecord::Base.establish_connection database_settings
|
|
50
41
|
self
|
|
51
42
|
end
|
|
52
|
-
|
|
43
|
+
|
|
53
44
|
private
|
|
54
|
-
|
|
45
|
+
|
|
55
46
|
def config
|
|
56
47
|
@config ||= ::ThinkingSphinx::Configuration.instance
|
|
57
48
|
end
|
|
58
|
-
|
|
49
|
+
|
|
59
50
|
def make_temporary_directory
|
|
60
51
|
FileUtils.mkdir_p temporary_directory
|
|
61
52
|
Dir["#{temporary_directory}/*"].each do |file|
|
|
62
53
|
FileUtils.rm_rf file
|
|
63
54
|
end
|
|
64
55
|
end
|
|
65
|
-
|
|
56
|
+
|
|
66
57
|
def configure_thinking_sphinx
|
|
67
58
|
config.config_file = "#{temporary_directory}/sphinx.conf"
|
|
68
59
|
config.searchd_log_file = "#{temporary_directory}/searchd.log"
|
|
69
60
|
config.query_log_file = "#{temporary_directory}/searchd.query.log"
|
|
70
61
|
config.pid_file = "#{temporary_directory}/searchd.pid"
|
|
71
62
|
config.searchd_file_path = "#{temporary_directory}/indexes/"
|
|
72
|
-
|
|
63
|
+
|
|
73
64
|
::ThinkingSphinx.suppress_delta_output = true
|
|
74
65
|
end
|
|
75
|
-
|
|
66
|
+
|
|
76
67
|
def configure_cleanup
|
|
77
68
|
Kernel.at_exit do
|
|
78
69
|
::ThinkingSphinx::Configuration.instance.controller.stop
|
|
@@ -80,13 +71,13 @@ module Cucumber
|
|
|
80
71
|
ActiveRecord::Base.logger.close
|
|
81
72
|
end
|
|
82
73
|
end
|
|
83
|
-
|
|
74
|
+
|
|
84
75
|
def yaml_database_settings
|
|
85
76
|
return {} unless File.exist?(@database_file)
|
|
86
|
-
|
|
77
|
+
|
|
87
78
|
YAML.load open(@database_file)
|
|
88
79
|
end
|
|
89
|
-
|
|
80
|
+
|
|
90
81
|
def database_settings
|
|
91
82
|
{
|
|
92
83
|
'adapter' => @adapter,
|
|
@@ -96,37 +87,37 @@ module Cucumber
|
|
|
96
87
|
'host' => @host
|
|
97
88
|
}.merge yaml_database_settings
|
|
98
89
|
end
|
|
99
|
-
|
|
90
|
+
|
|
100
91
|
def configure_active_record
|
|
101
92
|
ActiveRecord::Base.logger = Logger.new(
|
|
102
93
|
open("#{temporary_directory}/active_record.log", "a")
|
|
103
94
|
)
|
|
104
|
-
|
|
95
|
+
|
|
105
96
|
ActiveRecord::Base.connection.class.send(
|
|
106
97
|
:include, Cucumber::ThinkingSphinx::SqlLogger
|
|
107
98
|
)
|
|
108
99
|
end
|
|
109
|
-
|
|
100
|
+
|
|
110
101
|
def prepare_data
|
|
111
102
|
::ThinkingSphinx.deltas_enabled = false
|
|
112
|
-
|
|
103
|
+
|
|
113
104
|
load_files migrations_directory
|
|
114
105
|
load_files models_directory
|
|
115
106
|
load_files fixtures_directory
|
|
116
|
-
|
|
107
|
+
|
|
117
108
|
::ThinkingSphinx.deltas_enabled = true
|
|
118
109
|
end
|
|
119
|
-
|
|
110
|
+
|
|
120
111
|
def load_files(path)
|
|
121
112
|
files = Dir["#{path}/*.rb"].sort!
|
|
122
113
|
files.each do |file|
|
|
123
114
|
require file.gsub(/\.rb$/, '')
|
|
124
115
|
end
|
|
125
116
|
end
|
|
126
|
-
|
|
117
|
+
|
|
127
118
|
def setup_sphinx
|
|
128
119
|
FileUtils.mkdir_p config.searchd_file_path
|
|
129
|
-
|
|
120
|
+
|
|
130
121
|
config.build
|
|
131
122
|
config.controller.index
|
|
132
123
|
config.controller.start
|
data/lib/thinking_sphinx.rb
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
require 'thread'
|
|
2
1
|
require 'active_record'
|
|
3
|
-
require 'after_commit'
|
|
4
|
-
require 'innertube'
|
|
5
2
|
require 'yaml'
|
|
6
3
|
require 'riddle'
|
|
7
4
|
|
|
8
5
|
require 'thinking_sphinx/auto_version'
|
|
6
|
+
require 'thinking_sphinx/core/array'
|
|
9
7
|
require 'thinking_sphinx/core/string'
|
|
10
8
|
require 'thinking_sphinx/property'
|
|
11
9
|
require 'thinking_sphinx/active_record'
|
|
12
10
|
require 'thinking_sphinx/association'
|
|
13
11
|
require 'thinking_sphinx/attribute'
|
|
14
|
-
require 'thinking_sphinx/bundled_search'
|
|
15
12
|
require 'thinking_sphinx/configuration'
|
|
16
|
-
require 'thinking_sphinx/connection'
|
|
17
13
|
require 'thinking_sphinx/context'
|
|
18
14
|
require 'thinking_sphinx/excerpter'
|
|
19
15
|
require 'thinking_sphinx/facet'
|
|
@@ -23,7 +19,6 @@ require 'thinking_sphinx/field'
|
|
|
23
19
|
require 'thinking_sphinx/index'
|
|
24
20
|
require 'thinking_sphinx/join'
|
|
25
21
|
require 'thinking_sphinx/source'
|
|
26
|
-
require 'thinking_sphinx/rails_additions'
|
|
27
22
|
require 'thinking_sphinx/search'
|
|
28
23
|
require 'thinking_sphinx/search_methods'
|
|
29
24
|
require 'thinking_sphinx/deltas'
|
|
@@ -32,15 +27,9 @@ require 'thinking_sphinx/adapters/abstract_adapter'
|
|
|
32
27
|
require 'thinking_sphinx/adapters/mysql_adapter'
|
|
33
28
|
require 'thinking_sphinx/adapters/postgresql_adapter'
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Merb::Plugins.add_rakefiles(
|
|
38
|
-
File.join(File.dirname(__FILE__), "thinking_sphinx", "tasks")
|
|
39
|
-
) if defined?(Merb)
|
|
30
|
+
require 'thinking_sphinx/railtie'
|
|
40
31
|
|
|
41
32
|
module ThinkingSphinx
|
|
42
|
-
mattr_accessor :database_adapter
|
|
43
|
-
|
|
44
33
|
# A ConnectionError will get thrown when a connection to Sphinx can't be
|
|
45
34
|
# made.
|
|
46
35
|
class ConnectionError < StandardError
|
|
@@ -54,60 +43,54 @@ module ThinkingSphinx
|
|
|
54
43
|
self.ids = ids
|
|
55
44
|
end
|
|
56
45
|
end
|
|
57
|
-
|
|
58
|
-
#
|
|
59
|
-
#
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
end
|
|
67
|
-
|
|
46
|
+
|
|
47
|
+
# The current version of Thinking Sphinx.
|
|
48
|
+
#
|
|
49
|
+
# @return [String] The version number as a string
|
|
50
|
+
#
|
|
51
|
+
def self.version
|
|
52
|
+
open(File.join(File.dirname(__FILE__), '../VERSION')) { |f|
|
|
53
|
+
f.read.strip
|
|
54
|
+
}
|
|
55
|
+
end
|
|
56
|
+
|
|
68
57
|
# The collection of indexed models. Keep in mind that Rails lazily loads
|
|
69
58
|
# its classes, so this may not actually be populated with _all_ the models
|
|
70
59
|
# that have Sphinx indexes.
|
|
71
|
-
@@sphinx_mutex
|
|
72
|
-
@@context
|
|
73
|
-
|
|
74
|
-
@@deltas_enabled = nil
|
|
75
|
-
@@updates_enabled = nil
|
|
76
|
-
@@suppress_delta_output = false
|
|
77
|
-
@@remote_sphinx = false
|
|
78
|
-
@@use_group_by_shortcut = nil
|
|
79
|
-
|
|
80
|
-
def self.mutex
|
|
81
|
-
@@sphinx_mutex
|
|
82
|
-
end
|
|
83
|
-
|
|
60
|
+
@@sphinx_mutex = Mutex.new
|
|
61
|
+
@@context = nil
|
|
62
|
+
|
|
84
63
|
def self.context
|
|
85
64
|
if @@context.nil?
|
|
86
|
-
|
|
65
|
+
@@sphinx_mutex.synchronize do
|
|
87
66
|
if @@context.nil?
|
|
88
67
|
@@context = ThinkingSphinx::Context.new
|
|
89
68
|
@@context.prepare
|
|
90
69
|
end
|
|
91
70
|
end
|
|
92
71
|
end
|
|
93
|
-
|
|
72
|
+
|
|
94
73
|
@@context
|
|
95
74
|
end
|
|
96
|
-
|
|
97
|
-
def self.reset_context!
|
|
98
|
-
|
|
99
|
-
@@context =
|
|
75
|
+
|
|
76
|
+
def self.reset_context!
|
|
77
|
+
@@sphinx_mutex.synchronize do
|
|
78
|
+
@@context = nil
|
|
100
79
|
end
|
|
101
80
|
end
|
|
102
81
|
|
|
103
|
-
def self.unique_id_expression(
|
|
104
|
-
"* #{
|
|
82
|
+
def self.unique_id_expression(offset = nil)
|
|
83
|
+
"* #{context.indexed_models.size} + #{offset || 0}"
|
|
105
84
|
end
|
|
106
85
|
|
|
107
86
|
# Check if index definition is disabled.
|
|
108
87
|
#
|
|
109
88
|
def self.define_indexes?
|
|
110
|
-
|
|
89
|
+
if Thread.current[:thinking_sphinx_define_indexes].nil?
|
|
90
|
+
Thread.current[:thinking_sphinx_define_indexes] = true
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
Thread.current[:thinking_sphinx_define_indexes]
|
|
111
94
|
end
|
|
112
95
|
|
|
113
96
|
# Enable/disable indexes - you may want to do this while migrating data.
|
|
@@ -115,70 +98,40 @@ module ThinkingSphinx
|
|
|
115
98
|
# ThinkingSphinx.define_indexes = false
|
|
116
99
|
#
|
|
117
100
|
def self.define_indexes=(value)
|
|
118
|
-
|
|
119
|
-
@@define_indexes = value
|
|
120
|
-
end
|
|
101
|
+
Thread.current[:thinking_sphinx_define_indexes] = value
|
|
121
102
|
end
|
|
122
103
|
|
|
123
|
-
# Check if delta indexing is enabled
|
|
104
|
+
# Check if delta indexing is enabled.
|
|
124
105
|
#
|
|
125
106
|
def self.deltas_enabled?
|
|
126
|
-
if
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
ThinkingSphinx::Configuration.environment != "test"
|
|
131
|
-
)
|
|
132
|
-
end
|
|
133
|
-
end
|
|
107
|
+
if Thread.current[:thinking_sphinx_deltas_enabled].nil?
|
|
108
|
+
Thread.current[:thinking_sphinx_deltas_enabled] = (
|
|
109
|
+
ThinkingSphinx::Configuration.environment != "test"
|
|
110
|
+
)
|
|
134
111
|
end
|
|
135
|
-
|
|
136
|
-
|
|
112
|
+
|
|
113
|
+
Thread.current[:thinking_sphinx_deltas_enabled]
|
|
137
114
|
end
|
|
138
115
|
|
|
139
|
-
# Enable/disable delta indexing.
|
|
116
|
+
# Enable/disable all delta indexing.
|
|
140
117
|
#
|
|
141
118
|
# ThinkingSphinx.deltas_enabled = false
|
|
142
119
|
#
|
|
143
120
|
def self.deltas_enabled=(value)
|
|
144
|
-
|
|
145
|
-
@@deltas_enabled = value
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# Check if delta indexing is suspended.
|
|
150
|
-
#
|
|
151
|
-
def self.deltas_suspended?
|
|
152
|
-
if Thread.current[:thinking_sphinx_deltas_suspended].nil?
|
|
153
|
-
Thread.current[:thinking_sphinx_deltas_suspended] = false
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
Thread.current[:thinking_sphinx_deltas_suspended]
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
# Suspend/resume delta indexing.
|
|
160
|
-
#
|
|
161
|
-
# ThinkingSphinx.deltas_suspended = false
|
|
162
|
-
#
|
|
163
|
-
def self.deltas_suspended=(value)
|
|
164
|
-
Thread.current[:thinking_sphinx_deltas_suspended] = value
|
|
121
|
+
Thread.current[:thinking_sphinx_deltas_enabled] = value
|
|
165
122
|
end
|
|
166
123
|
|
|
167
124
|
# Check if updates are enabled. True by default, unless within the test
|
|
168
125
|
# environment.
|
|
169
126
|
#
|
|
170
127
|
def self.updates_enabled?
|
|
171
|
-
if
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
ThinkingSphinx::Configuration.environment != "test"
|
|
176
|
-
)
|
|
177
|
-
end
|
|
178
|
-
end
|
|
128
|
+
if Thread.current[:thinking_sphinx_updates_enabled].nil?
|
|
129
|
+
Thread.current[:thinking_sphinx_updates_enabled] = (
|
|
130
|
+
ThinkingSphinx::Configuration.environment != "test"
|
|
131
|
+
)
|
|
179
132
|
end
|
|
180
|
-
|
|
181
|
-
|
|
133
|
+
|
|
134
|
+
Thread.current[:thinking_sphinx_updates_enabled]
|
|
182
135
|
end
|
|
183
136
|
|
|
184
137
|
# Enable/disable updates to Sphinx
|
|
@@ -186,53 +139,37 @@ module ThinkingSphinx
|
|
|
186
139
|
# ThinkingSphinx.updates_enabled = false
|
|
187
140
|
#
|
|
188
141
|
def self.updates_enabled=(value)
|
|
189
|
-
|
|
190
|
-
@@updates_enabled = value
|
|
191
|
-
end
|
|
142
|
+
Thread.current[:thinking_sphinx_updates_enabled] = value
|
|
192
143
|
end
|
|
193
144
|
|
|
194
145
|
def self.suppress_delta_output?
|
|
195
|
-
|
|
146
|
+
Thread.current[:thinking_sphinx_suppress_delta_output] ||= false
|
|
196
147
|
end
|
|
197
148
|
|
|
198
149
|
def self.suppress_delta_output=(value)
|
|
199
|
-
|
|
200
|
-
@@suppress_delta_output = value
|
|
201
|
-
end
|
|
150
|
+
Thread.current[:thinking_sphinx_suppress_delta_output] = value
|
|
202
151
|
end
|
|
203
|
-
|
|
152
|
+
|
|
204
153
|
# Checks to see if MySQL will allow simplistic GROUP BY statements. If not,
|
|
205
154
|
# or if not using MySQL, this will return false.
|
|
206
155
|
#
|
|
207
156
|
def self.use_group_by_shortcut?
|
|
208
|
-
if
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
@@
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
).all? { |key, value|
|
|
215
|
-
value.nil? || value[/ONLY_FULL_GROUP_BY/].nil?
|
|
216
|
-
}
|
|
217
|
-
)
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
@@use_group_by_shortcut
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
def self.reset_use_group_by_shortcut
|
|
226
|
-
mutex.synchronize do
|
|
227
|
-
@@use_group_by_shortcut = nil
|
|
157
|
+
if Thread.current[:thinking_sphinx_use_group_by_shortcut].nil?
|
|
158
|
+
Thread.current[:thinking_sphinx_use_group_by_shortcut] = !!(
|
|
159
|
+
mysql? && ::ActiveRecord::Base.connection.select_all(
|
|
160
|
+
"SELECT @@global.sql_mode, @@session.sql_mode;"
|
|
161
|
+
).all? { |key,value| value.nil? || value[/ONLY_FULL_GROUP_BY/].nil? }
|
|
162
|
+
)
|
|
228
163
|
end
|
|
164
|
+
|
|
165
|
+
Thread.current[:thinking_sphinx_use_group_by_shortcut]
|
|
229
166
|
end
|
|
230
167
|
|
|
231
168
|
# An indication of whether Sphinx is running on a remote machine instead of
|
|
232
169
|
# the same machine.
|
|
233
170
|
#
|
|
234
171
|
def self.remote_sphinx?
|
|
235
|
-
|
|
172
|
+
Thread.current[:thinking_sphinx_remote_sphinx] ||= false
|
|
236
173
|
end
|
|
237
174
|
|
|
238
175
|
# Tells Thinking Sphinx that Sphinx is running on a different machine, and
|
|
@@ -244,9 +181,7 @@ module ThinkingSphinx
|
|
|
244
181
|
# ThinkingSphinx.remote_sphinx = true
|
|
245
182
|
#
|
|
246
183
|
def self.remote_sphinx=(value)
|
|
247
|
-
|
|
248
|
-
@@remote_sphinx = value
|
|
249
|
-
end
|
|
184
|
+
Thread.current[:thinking_sphinx_remote_sphinx] = value
|
|
250
185
|
end
|
|
251
186
|
|
|
252
187
|
# Check if Sphinx is running. If remote_sphinx is set to true (indicating
|
|
@@ -290,18 +225,11 @@ module ThinkingSphinx
|
|
|
290
225
|
|
|
291
226
|
def self.mysql?
|
|
292
227
|
::ActiveRecord::Base.connection.class.name.demodulize == "MysqlAdapter" ||
|
|
293
|
-
::ActiveRecord::Base.connection.class.name.demodulize == "Mysql2Adapter" ||
|
|
294
228
|
::ActiveRecord::Base.connection.class.name.demodulize == "MysqlplusAdapter" || (
|
|
295
229
|
jruby? && ::ActiveRecord::Base.connection.config[:adapter] == "jdbcmysql"
|
|
296
230
|
)
|
|
297
231
|
end
|
|
298
|
-
|
|
299
|
-
def self.before_index_hooks
|
|
300
|
-
@before_index_hooks
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
@before_index_hooks = []
|
|
304
|
-
|
|
232
|
+
|
|
305
233
|
extend ThinkingSphinx::SearchMethods::ClassMethods
|
|
306
234
|
end
|
|
307
235
|
|