Module: ThinkingSphinx
- Extended by:
- SearchMethods::ClassMethods
- Defined in:
- lib/thinking_sphinx.rb,
lib/thinking_sphinx/join.rb,
lib/thinking_sphinx/facet.rb,
lib/thinking_sphinx/field.rb,
lib/thinking_sphinx/index.rb,
lib/thinking_sphinx/deltas.rb,
lib/thinking_sphinx/search.rb,
lib/thinking_sphinx/source.rb,
lib/thinking_sphinx/railtie.rb,
lib/thinking_sphinx/version.rb,
lib/thinking_sphinx/property.rb,
lib/thinking_sphinx/attribute.rb,
lib/thinking_sphinx/excerpter.rb,
lib/thinking_sphinx/source/sql.rb,
lib/thinking_sphinx/association.rb,
lib/thinking_sphinx/class_facet.rb,
lib/thinking_sphinx/core/string.rb,
lib/thinking_sphinx/auto_version.rb,
lib/thinking_sphinx/facet_search.rb,
lib/thinking_sphinx/active_record.rb,
lib/thinking_sphinx/configuration.rb,
lib/thinking_sphinx/index/builder.rb,
lib/thinking_sphinx/bundled_search.rb,
lib/thinking_sphinx/search_methods.rb,
lib/thinking_sphinx/action_controller.rb,
lib/thinking_sphinx/index/faux_column.rb,
lib/thinking_sphinx/active_record/delta.rb,
lib/thinking_sphinx/active_record/scopes.rb,
lib/thinking_sphinx/deltas/default_delta.rb,
lib/thinking_sphinx/adapters/mysql_adapter.rb,
lib/thinking_sphinx/adapters/abstract_adapter.rb,
lib/thinking_sphinx/source/internal_properties.rb,
lib/thinking_sphinx/adapters/postgresql_adapter.rb,
lib/thinking_sphinx/active_record/log_subscriber.rb,
lib/thinking_sphinx/active_record/collection_proxy.rb,
lib/thinking_sphinx/active_record/attribute_updates.rb,
lib/thinking_sphinx/active_record/has_many_association.rb,
lib/thinking_sphinx/active_record/collection_proxy_with_scopes.rb,
lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb
Defined Under Namespace
Modules: ActionController, ActiveRecord, Core, Deltas, SearchMethods Classes: AbstractAdapter, Association, Attribute, AutoVersion, BundledSearch, ClassFacet, Configuration, Connection, ConnectionError, Context, Excerpter, Facet, FacetSearch, Field, Index, Join, MysqlAdapter, PostgreSQLAdapter, Property, Railtie, Search, Source, SphinxError, StaleIdsException, Test
Constant Summary collapse
- Version =
'2.0.14.1'
- @@sphinx_mutex =
The collection of indexed models. Keep in mind that Rails lazily loads its classes, so this may not actually be populated with all the models that have Sphinx indexes.
Mutex.new
- @@context =
nil
- @@define_indexes =
true
- @@deltas_enabled =
nil
- @@updates_enabled =
nil
- @@suppress_delta_output =
false
- @@remote_sphinx =
false
- @@use_group_by_shortcut =
nil
Class Method Summary collapse
- .context ⇒ Object
-
.define_indexes=(value) ⇒ Object
Enable/disable indexes - you may want to do this while migrating data.
-
.define_indexes? ⇒ Boolean
Check if index definition is disabled.
-
.deltas_enabled=(value) ⇒ Object
Enable/disable delta indexing.
-
.deltas_enabled? ⇒ Boolean
Check if delta indexing is enabled/disabled.
-
.deltas_suspended=(value) ⇒ Object
Suspend/resume delta indexing.
-
.deltas_suspended? ⇒ Boolean
Check if delta indexing is suspended.
- .jruby? ⇒ Boolean
- .microsoft? ⇒ Boolean
- .mutex ⇒ Object
- .mysql? ⇒ Boolean
- .pid_active?(pid) ⇒ Boolean
- .rails_3_1? ⇒ Boolean
-
.remote_sphinx=(value) ⇒ Object
Tells Thinking Sphinx that Sphinx is running on a different machine, and thus it can’t reliably guess whether it is running or not (ie: the #sphinx_running? method), and so just assumes it is.
-
.remote_sphinx? ⇒ Boolean
An indication of whether Sphinx is running on a remote machine instead of the same machine.
- .reset_context!(context = nil) ⇒ Object
- .reset_use_group_by_shortcut ⇒ Object
- .sphinx_pid ⇒ Object
-
.sphinx_running? ⇒ Boolean
Check if Sphinx is running.
-
.sphinx_running_by_pid? ⇒ Boolean
Check if Sphinx is actually running, provided the pid is on the same machine as this code.
- .suppress_delta_output=(value) ⇒ Object
- .suppress_delta_output? ⇒ Boolean
- .unique_id_expression(adapter, offset = nil) ⇒ Object
-
.updates_enabled=(value) ⇒ Object
Enable/disable updates to Sphinx.
-
.updates_enabled? ⇒ Boolean
Check if updates are enabled.
-
.use_group_by_shortcut? ⇒ Boolean
Checks to see if MySQL will allow simplistic GROUP BY statements.
Methods included from SearchMethods::ClassMethods
count, facets, search, search_context, search_count, search_for_id, search_for_ids
Class Method Details
.context ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/thinking_sphinx.rb', line 79 def self.context if @@context.nil? mutex.synchronize do if @@context.nil? @@context = ThinkingSphinx::Context.new @@context.prepare end end end @@context end |
.define_indexes=(value) ⇒ Object
Enable/disable indexes - you may want to do this while migrating data.
ThinkingSphinx.define_indexes = false
112 113 114 115 116 |
# File 'lib/thinking_sphinx.rb', line 112 def self.define_indexes=(value) mutex.synchronize do @@define_indexes = value end end |
.define_indexes? ⇒ Boolean
Check if index definition is disabled.
104 105 106 |
# File 'lib/thinking_sphinx.rb', line 104 def self.define_indexes? @@define_indexes end |
.deltas_enabled=(value) ⇒ Object
Enable/disable delta indexing.
ThinkingSphinx.deltas_enabled = false
138 139 140 141 142 |
# File 'lib/thinking_sphinx.rb', line 138 def self.deltas_enabled=(value) mutex.synchronize do @@deltas_enabled = value end end |
.deltas_enabled? ⇒ Boolean
Check if delta indexing is enabled/disabled.
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/thinking_sphinx.rb', line 120 def self.deltas_enabled? if @@deltas_enabled.nil? mutex.synchronize do if @@deltas_enabled.nil? @@deltas_enabled = ( ThinkingSphinx::Configuration.environment != "test" ) end end end @@deltas_enabled && !deltas_suspended? end |
.deltas_suspended=(value) ⇒ Object
Suspend/resume delta indexing.
ThinkingSphinx.deltas_suspended = false
158 159 160 |
# File 'lib/thinking_sphinx.rb', line 158 def self.deltas_suspended=(value) Thread.current[:thinking_sphinx_deltas_suspended] = value end |
.deltas_suspended? ⇒ Boolean
Check if delta indexing is suspended.
146 147 148 149 150 151 152 |
# File 'lib/thinking_sphinx.rb', line 146 def self.deltas_suspended? if Thread.current[:thinking_sphinx_deltas_suspended].nil? Thread.current[:thinking_sphinx_deltas_suspended] = false end Thread.current[:thinking_sphinx_deltas_suspended] end |
.jruby? ⇒ Boolean
282 283 284 |
# File 'lib/thinking_sphinx.rb', line 282 def self.jruby? defined?(JRUBY_VERSION) end |
.microsoft? ⇒ Boolean
278 279 280 |
# File 'lib/thinking_sphinx.rb', line 278 def self.microsoft? RUBY_PLATFORM =~ /mswin/ end |
.mutex ⇒ Object
75 76 77 |
# File 'lib/thinking_sphinx.rb', line 75 def self.mutex @@sphinx_mutex end |
.mysql? ⇒ Boolean
286 287 288 289 290 291 292 |
# File 'lib/thinking_sphinx.rb', line 286 def self.mysql? ::ActiveRecord::Base.connection.class.name.demodulize == "MysqlAdapter" || ::ActiveRecord::Base.connection.class.name.demodulize == "Mysql2Adapter" || ::ActiveRecord::Base.connection.class.name.demodulize == "MysqlplusAdapter" || ( jruby? && ::ActiveRecord::Base.connection.config[:adapter] == "jdbcmysql" ) end |
.pid_active?(pid) ⇒ Boolean
270 271 272 273 274 275 276 |
# File 'lib/thinking_sphinx.rb', line 270 def self.pid_active?(pid) !!Process.kill(0, pid.to_i) rescue Errno::EPERM => e true rescue Exception => e false end |
.rails_3_1? ⇒ Boolean
294 295 296 |
# File 'lib/thinking_sphinx.rb', line 294 def self.rails_3_1? !!defined?(::ActiveRecord::Associations::CollectionProxy) end |
.remote_sphinx=(value) ⇒ Object
Tells Thinking Sphinx that Sphinx is running on a different machine, and thus it can’t reliably guess whether it is running or not (ie: the #sphinx_running? method), and so just assumes it is.
Useful for multi-machine deployments. Set it in your production.rb file.
ThinkingSphinx.remote_sphinx = true
241 242 243 244 245 |
# File 'lib/thinking_sphinx.rb', line 241 def self.remote_sphinx=(value) mutex.synchronize do @@remote_sphinx = value end end |
.remote_sphinx? ⇒ Boolean
An indication of whether Sphinx is running on a remote machine instead of the same machine.
229 230 231 |
# File 'lib/thinking_sphinx.rb', line 229 def self.remote_sphinx? @@remote_sphinx end |
.reset_context!(context = nil) ⇒ Object
92 93 94 95 96 |
# File 'lib/thinking_sphinx.rb', line 92 def self.reset_context!(context = nil) mutex.synchronize do @@context = context end end |
.reset_use_group_by_shortcut ⇒ Object
220 221 222 223 224 |
# File 'lib/thinking_sphinx.rb', line 220 def self.reset_use_group_by_shortcut mutex.synchronize do @@use_group_by_shortcut = nil end end |
.sphinx_pid ⇒ Object
262 263 264 265 266 267 268 |
# File 'lib/thinking_sphinx.rb', line 262 def self.sphinx_pid if File.exists?(ThinkingSphinx::Configuration.instance.pid_file) File.read(ThinkingSphinx::Configuration.instance.pid_file)[/\d+/] else nil end end |
.sphinx_running? ⇒ Boolean
Check if Sphinx is running. If remote_sphinx is set to true (indicating Sphinx is on a different machine), this will always return true, and you will have to handle any connection errors yourself.
251 252 253 |
# File 'lib/thinking_sphinx.rb', line 251 def self.sphinx_running? remote_sphinx? || sphinx_running_by_pid? end |
.sphinx_running_by_pid? ⇒ Boolean
Check if Sphinx is actually running, provided the pid is on the same machine as this code.
258 259 260 |
# File 'lib/thinking_sphinx.rb', line 258 def self.sphinx_running_by_pid? !!sphinx_pid && pid_active?(sphinx_pid) end |
.suppress_delta_output=(value) ⇒ Object
193 194 195 196 197 |
# File 'lib/thinking_sphinx.rb', line 193 def self.suppress_delta_output=(value) mutex.synchronize do @@suppress_delta_output = value end end |
.suppress_delta_output? ⇒ Boolean
189 190 191 |
# File 'lib/thinking_sphinx.rb', line 189 def self.suppress_delta_output? @@suppress_delta_output end |
.unique_id_expression(adapter, offset = nil) ⇒ Object
98 99 100 |
# File 'lib/thinking_sphinx.rb', line 98 def self.unique_id_expression(adapter, offset = nil) "* #{adapter.cast_to_int context.indexed_models.size} + #{offset || 0}" end |
.updates_enabled=(value) ⇒ Object
Enable/disable updates to Sphinx
ThinkingSphinx.updates_enabled = false
183 184 185 186 187 |
# File 'lib/thinking_sphinx.rb', line 183 def self.updates_enabled=(value) mutex.synchronize do @@updates_enabled = value end end |
.updates_enabled? ⇒ Boolean
Check if updates are enabled. True by default, unless within the test environment.
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/thinking_sphinx.rb', line 165 def self.updates_enabled? if @@updates_enabled.nil? mutex.synchronize do if @@updates_enabled.nil? @@updates_enabled = ( ThinkingSphinx::Configuration.environment != "test" ) end end end @@updates_enabled end |
.use_group_by_shortcut? ⇒ Boolean
Checks to see if MySQL will allow simplistic GROUP BY statements. If not, or if not using MySQL, this will return false.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/thinking_sphinx.rb', line 202 def self.use_group_by_shortcut? if @@use_group_by_shortcut.nil? mutex.synchronize do if @@use_group_by_shortcut.nil? @@use_group_by_shortcut = !!( mysql? && ::ActiveRecord::Base.connection.select_all( "SELECT @@global.sql_mode, @@session.sql_mode;" ).all? { |key, value| value.nil? || value[/ONLY_FULL_GROUP_BY/].nil? } ) end end end @@use_group_by_shortcut end |