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/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/rails_additions.rb,
lib/thinking_sphinx/rails_additions.rb,
lib/thinking_sphinx/rails_additions.rb,
lib/thinking_sphinx/rails_additions.rb,
lib/thinking_sphinx/rails_additions.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/attribute_updates.rb,
lib/thinking_sphinx/active_record/has_many_association.rb,
lib/thinking_sphinx/rails_additions.rb,
lib/thinking_sphinx/rails_additions.rb,
lib/thinking_sphinx/rails_additions.rb
Defined Under Namespace
Modules: AbstractQuotedTableName, ActiveRecord, ActiveRecordQuotedName, ActiveRecordStoreFullSTIClass, ArrayExtractOptions, ClassAttributeMethods, Core, Deltas, HashExcept, MysqlQuotedTableName, SearchMethods, SingletonClass Classes: AbstractAdapter, Association, Attribute, AutoVersion, BundledSearch, ClassFacet, Configuration, ConnectionError, Context, Excerpter, Facet, FacetSearch, Field, Index, Join, MysqlAdapter, PostgreSQLAdapter, Property, Search, Source, StaleIdsException, Test
Constant Summary collapse
- @@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
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 all delta indexing.
-
.deltas_enabled? ⇒ Boolean
Check if delta indexing is enabled.
- .jruby? ⇒ Boolean
- .microsoft? ⇒ Boolean
- .mysql? ⇒ Boolean
- .pid_active?(pid) ⇒ 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! ⇒ 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(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.
-
.version ⇒ String
The current version of Thinking Sphinx.
Methods included from SearchMethods::ClassMethods
count, facets, search, search_context, search_count, search_for_id, search_for_ids
Class Method Details
.context ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/thinking_sphinx.rb', line 70 def self.context if @@context.nil? @@sphinx_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
107 108 109 |
# File 'lib/thinking_sphinx.rb', line 107 def self.define_indexes=(value) Thread.current[:thinking_sphinx_define_indexes] = value end |
.define_indexes? ⇒ Boolean
Check if index definition is disabled.
95 96 97 98 99 100 101 |
# File 'lib/thinking_sphinx.rb', line 95 def self.define_indexes? if Thread.current[:thinking_sphinx_define_indexes].nil? Thread.current[:thinking_sphinx_define_indexes] = true end Thread.current[:thinking_sphinx_define_indexes] end |
.deltas_enabled=(value) ⇒ Object
Enable/disable all delta indexing.
ThinkingSphinx.deltas_enabled = false
127 128 129 |
# File 'lib/thinking_sphinx.rb', line 127 def self.deltas_enabled=(value) Thread.current[:thinking_sphinx_deltas_enabled] = value end |
.deltas_enabled? ⇒ Boolean
Check if delta indexing is enabled.
113 114 115 116 117 118 119 120 121 |
# File 'lib/thinking_sphinx.rb', line 113 def self.deltas_enabled? if Thread.current[:thinking_sphinx_deltas_enabled].nil? Thread.current[:thinking_sphinx_deltas_enabled] = ( ThinkingSphinx::Configuration.environment != "test" ) end Thread.current[:thinking_sphinx_deltas_enabled] end |
.jruby? ⇒ Boolean
229 230 231 |
# File 'lib/thinking_sphinx.rb', line 229 def self.jruby? defined?(JRUBY_VERSION) end |
.microsoft? ⇒ Boolean
225 226 227 |
# File 'lib/thinking_sphinx.rb', line 225 def self.microsoft? RUBY_PLATFORM =~ /mswin/ end |
.mysql? ⇒ Boolean
233 234 235 236 237 238 |
# File 'lib/thinking_sphinx.rb', line 233 def self.mysql? ::ActiveRecord::Base.connection.class.name.demodulize == "MysqlAdapter" || ::ActiveRecord::Base.connection.class.name.demodulize == "MysqlplusAdapter" || ( jruby? && ::ActiveRecord::Base.connection.config[:adapter] == "jdbcmysql" ) end |
.pid_active?(pid) ⇒ Boolean
217 218 219 220 221 222 223 |
# File 'lib/thinking_sphinx.rb', line 217 def self.pid_active?(pid) !!Process.kill(0, pid.to_i) rescue Errno::EPERM => e true rescue Exception => e false 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
190 191 192 |
# File 'lib/thinking_sphinx.rb', line 190 def self.remote_sphinx=(value) Thread.current[:thinking_sphinx_remote_sphinx] = value end |
.remote_sphinx? ⇒ Boolean
An indication of whether Sphinx is running on a remote machine instead of the same machine.
178 179 180 |
# File 'lib/thinking_sphinx.rb', line 178 def self.remote_sphinx? Thread.current[:thinking_sphinx_remote_sphinx] ||= false end |
.reset_context! ⇒ Object
83 84 85 86 87 |
# File 'lib/thinking_sphinx.rb', line 83 def self.reset_context! @@sphinx_mutex.synchronize do @@context = nil end end |
.sphinx_pid ⇒ Object
209 210 211 212 213 214 215 |
# File 'lib/thinking_sphinx.rb', line 209 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.
198 199 200 |
# File 'lib/thinking_sphinx.rb', line 198 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.
205 206 207 |
# File 'lib/thinking_sphinx.rb', line 205 def self.sphinx_running_by_pid? !!sphinx_pid && pid_active?(sphinx_pid) end |
.suppress_delta_output=(value) ⇒ Object
156 157 158 |
# File 'lib/thinking_sphinx.rb', line 156 def self.suppress_delta_output=(value) Thread.current[:thinking_sphinx_suppress_delta_output] = value end |
.suppress_delta_output? ⇒ Boolean
152 153 154 |
# File 'lib/thinking_sphinx.rb', line 152 def self.suppress_delta_output? Thread.current[:thinking_sphinx_suppress_delta_output] ||= false end |
.unique_id_expression(offset = nil) ⇒ Object
89 90 91 |
# File 'lib/thinking_sphinx.rb', line 89 def self.unique_id_expression(offset = nil) "* #{context.indexed_models.size} + #{offset || 0}" end |
.updates_enabled=(value) ⇒ Object
Enable/disable updates to Sphinx
ThinkingSphinx.updates_enabled = false
148 149 150 |
# File 'lib/thinking_sphinx.rb', line 148 def self.updates_enabled=(value) Thread.current[:thinking_sphinx_updates_enabled] = value end |
.updates_enabled? ⇒ Boolean
Check if updates are enabled. True by default, unless within the test environment.
134 135 136 137 138 139 140 141 142 |
# File 'lib/thinking_sphinx.rb', line 134 def self.updates_enabled? if Thread.current[:thinking_sphinx_updates_enabled].nil? Thread.current[:thinking_sphinx_updates_enabled] = ( ThinkingSphinx::Configuration.environment != "test" ) end Thread.current[:thinking_sphinx_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.
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/thinking_sphinx.rb', line 163 def self.use_group_by_shortcut? if Thread.current[:thinking_sphinx_use_group_by_shortcut].nil? Thread.current[:thinking_sphinx_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 Thread.current[:thinking_sphinx_use_group_by_shortcut] end |
.version ⇒ String
The current version of Thinking Sphinx.
58 59 60 61 62 |
# File 'lib/thinking_sphinx.rb', line 58 def self.version open(File.join(File.dirname(__FILE__), '../VERSION')) { |f| f.read.strip } end |