thinking-sphinx 1.5.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/README.textile +15 -48
  2. data/VERSION +1 -0
  3. data/features/attribute_transformation.feature +7 -7
  4. data/features/attribute_updates.feature +16 -18
  5. data/features/deleting_instances.feature +13 -16
  6. data/features/excerpts.feature +0 -8
  7. data/features/facets.feature +19 -25
  8. data/features/handling_edits.feature +20 -25
  9. data/features/searching_across_models.feature +1 -1
  10. data/features/searching_by_index.feature +5 -6
  11. data/features/searching_by_model.feature +29 -29
  12. data/features/sphinx_scopes.feature +0 -26
  13. data/features/step_definitions/common_steps.rb +6 -18
  14. data/features/step_definitions/scope_steps.rb +0 -4
  15. data/features/step_definitions/search_steps.rb +4 -9
  16. data/features/support/env.rb +10 -3
  17. data/features/thinking_sphinx/db/fixtures/alphas.rb +10 -8
  18. data/features/thinking_sphinx/db/fixtures/cats.rb +1 -1
  19. data/features/thinking_sphinx/db/fixtures/dogs.rb +1 -1
  20. data/features/thinking_sphinx/db/fixtures/foxes.rb +1 -1
  21. data/features/thinking_sphinx/db/fixtures/people.rb +1 -1
  22. data/features/thinking_sphinx/db/fixtures/posts.rb +1 -5
  23. data/features/thinking_sphinx/db/migrations/create_posts.rb +0 -1
  24. data/features/thinking_sphinx/models/alpha.rb +0 -1
  25. data/features/thinking_sphinx/models/beta.rb +0 -5
  26. data/features/thinking_sphinx/models/developer.rb +1 -6
  27. data/features/thinking_sphinx/models/music.rb +1 -3
  28. data/features/thinking_sphinx/models/person.rb +1 -2
  29. data/features/thinking_sphinx/models/post.rb +0 -1
  30. data/lib/cucumber/thinking_sphinx/external_world.rb +4 -8
  31. data/lib/cucumber/thinking_sphinx/internal_world.rb +27 -36
  32. data/lib/thinking_sphinx.rb +60 -132
  33. data/lib/thinking_sphinx/active_record.rb +98 -124
  34. data/lib/thinking_sphinx/active_record/attribute_updates.rb +13 -17
  35. data/lib/thinking_sphinx/active_record/delta.rb +15 -21
  36. data/lib/thinking_sphinx/active_record/has_many_association.rb +23 -16
  37. data/lib/thinking_sphinx/active_record/scopes.rb +0 -18
  38. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +15 -63
  39. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +0 -4
  40. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +24 -65
  41. data/lib/thinking_sphinx/association.rb +11 -36
  42. data/lib/thinking_sphinx/attribute.rb +85 -92
  43. data/lib/thinking_sphinx/auto_version.rb +3 -21
  44. data/lib/thinking_sphinx/class_facet.rb +3 -8
  45. data/lib/thinking_sphinx/configuration.rb +58 -114
  46. data/lib/thinking_sphinx/context.rb +20 -22
  47. data/lib/thinking_sphinx/core/array.rb +13 -0
  48. data/lib/thinking_sphinx/deltas.rb +0 -2
  49. data/lib/thinking_sphinx/deltas/default_delta.rb +22 -18
  50. data/lib/thinking_sphinx/deploy/capistrano.rb +31 -30
  51. data/lib/thinking_sphinx/excerpter.rb +1 -2
  52. data/lib/thinking_sphinx/facet.rb +35 -45
  53. data/lib/thinking_sphinx/facet_search.rb +24 -58
  54. data/lib/thinking_sphinx/field.rb +0 -18
  55. data/lib/thinking_sphinx/index.rb +36 -38
  56. data/lib/thinking_sphinx/index/builder.rb +59 -74
  57. data/lib/thinking_sphinx/property.rb +45 -66
  58. data/lib/thinking_sphinx/railtie.rb +35 -0
  59. data/lib/thinking_sphinx/search.rb +250 -506
  60. data/lib/thinking_sphinx/source.rb +31 -50
  61. data/lib/thinking_sphinx/source/internal_properties.rb +3 -8
  62. data/lib/thinking_sphinx/source/sql.rb +31 -71
  63. data/lib/thinking_sphinx/tasks.rb +27 -48
  64. data/spec/thinking_sphinx/active_record/delta_spec.rb +41 -36
  65. data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +0 -96
  66. data/spec/thinking_sphinx/active_record/scopes_spec.rb +29 -29
  67. data/spec/thinking_sphinx/active_record_spec.rb +169 -140
  68. data/spec/thinking_sphinx/association_spec.rb +2 -20
  69. data/spec/thinking_sphinx/attribute_spec.rb +97 -101
  70. data/spec/thinking_sphinx/auto_version_spec.rb +11 -75
  71. data/spec/thinking_sphinx/configuration_spec.rb +62 -63
  72. data/spec/thinking_sphinx/context_spec.rb +66 -66
  73. data/spec/thinking_sphinx/facet_search_spec.rb +99 -99
  74. data/spec/thinking_sphinx/facet_spec.rb +4 -30
  75. data/spec/thinking_sphinx/field_spec.rb +3 -17
  76. data/spec/thinking_sphinx/index/builder_spec.rb +132 -169
  77. data/spec/thinking_sphinx/index_spec.rb +39 -45
  78. data/spec/thinking_sphinx/search_methods_spec.rb +33 -37
  79. data/spec/thinking_sphinx/search_spec.rb +269 -491
  80. data/spec/thinking_sphinx/source_spec.rb +48 -62
  81. data/spec/thinking_sphinx_spec.rb +49 -49
  82. data/tasks/distribution.rb +46 -0
  83. data/tasks/testing.rb +74 -0
  84. metadata +123 -199
  85. data/features/field_sorting.feature +0 -18
  86. data/features/thinking_sphinx/db/.gitignore +0 -1
  87. data/features/thinking_sphinx/db/fixtures/post_keywords.txt +0 -1
  88. data/features/thinking_sphinx/models/andrew.rb +0 -17
  89. data/lib/thinking-sphinx.rb +0 -1
  90. data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +0 -21
  91. data/lib/thinking_sphinx/bundled_search.rb +0 -40
  92. data/lib/thinking_sphinx/connection.rb +0 -71
  93. data/lib/thinking_sphinx/deltas/delete_job.rb +0 -16
  94. data/lib/thinking_sphinx/deltas/index_job.rb +0 -17
  95. data/lib/thinking_sphinx/rails_additions.rb +0 -181
  96. data/spec/fixtures/data.sql +0 -32
  97. data/spec/fixtures/database.yml.default +0 -3
  98. data/spec/fixtures/models.rb +0 -161
  99. data/spec/fixtures/structure.sql +0 -146
  100. data/spec/spec_helper.rb +0 -54
  101. data/spec/sphinx_helper.rb +0 -67
  102. data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +0 -163
  103. data/spec/thinking_sphinx/connection_spec.rb +0 -77
  104. 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 => "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"
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)
@@ -2,5 +2,4 @@ ActiveRecord::Base.connection.create_table :posts, :force => true do |t|
2
2
  t.column :subject, :string, :null => false
3
3
  t.column :content, :text
4
4
  t.column :category_id, :integer, :null => false
5
- t.column :keywords_file, :string
6
5
  end
@@ -14,7 +14,6 @@ class Alpha < ActiveRecord::Base
14
14
 
15
15
  has value, created_at, created_on
16
16
  has cost, :facet => true
17
- has active
18
17
 
19
18
  set_property :field_weights => {'alternative_name' => 10}
20
19
 
@@ -2,11 +2,6 @@ class Beta < ActiveRecord::Base
2
2
  define_index do
3
3
  indexes :name, :sortable => true, :facet => true
4
4
  has value
5
- end
6
-
7
- define_index 'secondary_beta' do
8
- indexes :name, :sortable => true, :facet => true
9
- has value
10
5
 
11
6
  set_property :delta => true
12
7
  end
@@ -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
- has state, :as => :state_wordcount, :type => :wordcount
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
@@ -2,9 +2,7 @@ class Music < Medium
2
2
  set_table_name 'music'
3
3
 
4
4
  define_index do
5
- indexes artist, :with => :attribute
6
- indexes track
7
- indexes album, :with => :wordcount
5
+ indexes artist, track, album
8
6
  indexes genre(:name), :as => :genre
9
7
  end
10
8
  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
- module Cucumber
4
- module ThinkingSphinx
5
- class ExternalWorld
6
- def initialize(suppress_delta_output = true)
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 = (ENV['DATABASE'] || 'mysql')
18
+
19
+ @adapter = ENV['DATABASE'] || 'mysql'
20
20
  @database = 'thinking_sphinx'
21
- @username = ENV['USER']
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
@@ -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
- ActiveRecord::Base.send(:include, ThinkingSphinx::ActiveRecord)
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
- # A SphinxError occurs when Sphinx responds with an error due to problematic
59
- # queries or indexes.
60
- class SphinxError < RuntimeError
61
- attr_accessor :results
62
- def initialize(message = nil, results = nil)
63
- super(message)
64
- self.results = results
65
- end
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 = Mutex.new
72
- @@context = nil
73
- @@define_indexes = true
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
- mutex.synchronize do
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!(context = nil)
98
- mutex.synchronize do
99
- @@context = 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(adapter, offset = nil)
104
- "* #{adapter.cast_to_int context.indexed_models.size} + #{offset || 0}"
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
- @@define_indexes
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
- mutex.synchronize do
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/disabled.
104
+ # Check if delta indexing is enabled.
124
105
  #
125
106
  def self.deltas_enabled?
126
- if @@deltas_enabled.nil?
127
- mutex.synchronize do
128
- if @@deltas_enabled.nil?
129
- @@deltas_enabled = (
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
- @@deltas_enabled && !deltas_suspended?
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
- mutex.synchronize do
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 @@updates_enabled.nil?
172
- mutex.synchronize do
173
- if @@updates_enabled.nil?
174
- @@updates_enabled = (
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
- @@updates_enabled
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
- mutex.synchronize do
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
- @@suppress_delta_output
146
+ Thread.current[:thinking_sphinx_suppress_delta_output] ||= false
196
147
  end
197
148
 
198
149
  def self.suppress_delta_output=(value)
199
- mutex.synchronize do
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 @@use_group_by_shortcut.nil?
209
- mutex.synchronize do
210
- if @@use_group_by_shortcut.nil?
211
- @@use_group_by_shortcut = !!(
212
- mysql? && ::ActiveRecord::Base.connection.select_all(
213
- "SELECT @@global.sql_mode, @@session.sql_mode;"
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
- @@remote_sphinx
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
- mutex.synchronize do
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