Module: ThinkingSphinx
- Defined in:
- lib/thinking_sphinx.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/property.rb,
lib/thinking_sphinx/attribute.rb,
lib/thinking_sphinx/collection.rb,
lib/thinking_sphinx/association.rb,
lib/thinking_sphinx/class_facet.rb,
lib/thinking_sphinx/core/string.rb,
lib/thinking_sphinx/active_record.rb,
lib/thinking_sphinx/configuration.rb,
lib/thinking_sphinx/index/builder.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/facet_collection.rb,
lib/thinking_sphinx/index/faux_column.rb,
lib/thinking_sphinx/active_record/delta.rb,
lib/thinking_sphinx/active_record/search.rb,
lib/thinking_sphinx/deltas/default_delta.rb,
lib/thinking_sphinx/deltas/delayed_delta.rb,
lib/thinking_sphinx/deltas/datetime_delta.rb,
lib/thinking_sphinx/adapters/mysql_adapter.rb,
lib/thinking_sphinx/deltas/delayed_delta/job.rb,
lib/thinking_sphinx/adapters/abstract_adapter.rb,
lib/thinking_sphinx/adapters/postgresql_adapter.rb,
lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb,
lib/thinking_sphinx/active_record/attribute_updates.rb,
lib/thinking_sphinx/active_record/has_many_association.rb,
lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.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, Version Classes: AbstractAdapter, Association, Attribute, ClassFacet, Collection, Configuration, ConnectionError, Facet, FacetCollection, Field, Index, MysqlAdapter, PostgreSQLAdapter, Property, Search, StaleIdsException
Constant Summary collapse
- @@deltas_enabled =
nil- @@updates_enabled =
nil- @@suppress_delta_output =
false
Class Method Summary collapse
-
.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.
-
.indexed_models ⇒ Object
The collection of indexed models.
- .jruby? ⇒ Boolean
- .microsoft? ⇒ Boolean
- .mysql? ⇒ Boolean
- .pid_active?(pid) ⇒ Boolean
- .sphinx_pid ⇒ Object
- .sphinx_running? ⇒ Boolean
- .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.
Class Method Details
.define_indexes=(value) ⇒ Object
Enable/disable indexes - you may want to do this while migrating data.
ThinkingSphinx.define_indexes = false
80 81 82 |
# File 'lib/thinking_sphinx.rb', line 80 def self.define_indexes=(value) @@define_indexes = value end |
.define_indexes? ⇒ Boolean
Check if index definition is disabled.
71 72 73 74 |
# File 'lib/thinking_sphinx.rb', line 71 def self.define_indexes? @@define_indexes = true unless defined?(@@define_indexes) @@define_indexes == true end |
.deltas_enabled=(value) ⇒ Object
Enable/disable all delta indexing.
ThinkingSphinx.deltas_enabled = false
97 98 99 |
# File 'lib/thinking_sphinx.rb', line 97 def self.deltas_enabled=(value) @@deltas_enabled = value end |
.deltas_enabled? ⇒ Boolean
Check if delta indexing is enabled.
88 89 90 91 |
# File 'lib/thinking_sphinx.rb', line 88 def self.deltas_enabled? @@deltas_enabled = (ThinkingSphinx::Configuration.environment != 'test') if @@deltas_enabled.nil? @@deltas_enabled end |
.indexed_models ⇒ Object
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.
61 62 63 |
# File 'lib/thinking_sphinx.rb', line 61 def self.indexed_models @@indexed_models ||= [] end |
.jruby? ⇒ Boolean
172 173 174 |
# File 'lib/thinking_sphinx.rb', line 172 def self.jruby? defined?(JRUBY_VERSION) end |
.microsoft? ⇒ Boolean
168 169 170 |
# File 'lib/thinking_sphinx.rb', line 168 def self.microsoft? RUBY_PLATFORM =~ /mswin/ end |
.mysql? ⇒ Boolean
176 177 178 179 180 |
# File 'lib/thinking_sphinx.rb', line 176 def self.mysql? ::ActiveRecord::Base.connection.class.name.demodulize == "MysqlAdapter" || ( jruby? && ::ActiveRecord::Base.connection.config[:adapter] == "jdbcmysql" ) end |
.pid_active?(pid) ⇒ Boolean
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/thinking_sphinx.rb', line 157 def self.pid_active?(pid) return true if microsoft? begin # In JRuby this returns -1 if the process doesn't exist Process.getpgid(pid.to_i) != -1 rescue Exception => e false end end |
.sphinx_pid ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/thinking_sphinx.rb', line 144 def self.sphinx_pid pid_file = ThinkingSphinx::Configuration.instance.pid_file cat_command = 'cat' return nil unless File.exists?(pid_file) if microsoft? pid_file.gsub!('/', '\\') cat_command = 'type' end `#{cat_command} #{pid_file}`[/\d+/] end |
.sphinx_running? ⇒ Boolean
140 141 142 |
# File 'lib/thinking_sphinx.rb', line 140 def self.sphinx_running? !!sphinx_pid && pid_active?(sphinx_pid) end |
.suppress_delta_output=(value) ⇒ Object
125 126 127 |
# File 'lib/thinking_sphinx.rb', line 125 def self.suppress_delta_output=(value) @@suppress_delta_output = value end |
.suppress_delta_output? ⇒ Boolean
121 122 123 |
# File 'lib/thinking_sphinx.rb', line 121 def self.suppress_delta_output? @@suppress_delta_output end |
.unique_id_expression(offset = nil) ⇒ Object
65 66 67 |
# File 'lib/thinking_sphinx.rb', line 65 def self.unique_id_expression(offset = nil) "* #{ThinkingSphinx.indexed_models.size} + #{offset || 0}" end |
.updates_enabled=(value) ⇒ Object
Enable/disable updates to Sphinx
ThinkingSphinx.updates_enabled = false
115 116 117 |
# File 'lib/thinking_sphinx.rb', line 115 def self.updates_enabled=(value) @@updates_enabled = value end |
.updates_enabled? ⇒ Boolean
Check if updates are enabled. True by default, unless within the test environment.
106 107 108 109 |
# File 'lib/thinking_sphinx.rb', line 106 def self.updates_enabled? @@updates_enabled = (ThinkingSphinx::Configuration.environment != 'test') if @@updates_enabled.nil? @@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.
132 133 134 135 136 137 138 |
# File 'lib/thinking_sphinx.rb', line 132 def self.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 |