diff options
| author | hukl <contact@smyck.org> | 2011-02-10 14:19:00 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2011-02-10 14:19:00 +0100 |
| commit | 7379daad1c73bd3610ed296436250b417ac3673d (patch) | |
| tree | 04f722efc678de9d3aa5bf8f1c96e3be33b18bc4 /vendor/plugins/thinking-sphinx/lib/thinking_sphinx.rb | |
| parent | 91633ac4419d839661e35ae8f2efe5c9089cfb67 (diff) | |
removed thinking_sphinx plugin and replaced it with gem.
also tuned dependencies
Diffstat (limited to 'vendor/plugins/thinking-sphinx/lib/thinking_sphinx.rb')
| -rw-r--r-- | vendor/plugins/thinking-sphinx/lib/thinking_sphinx.rb | 180 |
1 files changed, 0 insertions, 180 deletions
diff --git a/vendor/plugins/thinking-sphinx/lib/thinking_sphinx.rb b/vendor/plugins/thinking-sphinx/lib/thinking_sphinx.rb deleted file mode 100644 index 745643f..0000000 --- a/vendor/plugins/thinking-sphinx/lib/thinking_sphinx.rb +++ /dev/null | |||
| @@ -1,180 +0,0 @@ | |||
| 1 | Dir[File.join(File.dirname(__FILE__), '../vendor/*/lib')].each do |path| | ||
| 2 | $LOAD_PATH.unshift path | ||
| 3 | end | ||
| 4 | |||
| 5 | require 'active_record' | ||
| 6 | require 'riddle' | ||
| 7 | require 'after_commit' | ||
| 8 | |||
| 9 | require 'thinking_sphinx/core/string' | ||
| 10 | require 'thinking_sphinx/active_record' | ||
| 11 | require 'thinking_sphinx/association' | ||
| 12 | require 'thinking_sphinx/attribute' | ||
| 13 | require 'thinking_sphinx/collection' | ||
| 14 | require 'thinking_sphinx/configuration' | ||
| 15 | require 'thinking_sphinx/facet' | ||
| 16 | require 'thinking_sphinx/class_facet' | ||
| 17 | require 'thinking_sphinx/facet_collection' | ||
| 18 | require 'thinking_sphinx/field' | ||
| 19 | require 'thinking_sphinx/index' | ||
| 20 | require 'thinking_sphinx/rails_additions' | ||
| 21 | require 'thinking_sphinx/search' | ||
| 22 | require 'thinking_sphinx/deltas' | ||
| 23 | |||
| 24 | require 'thinking_sphinx/adapters/abstract_adapter' | ||
| 25 | require 'thinking_sphinx/adapters/mysql_adapter' | ||
| 26 | require 'thinking_sphinx/adapters/postgresql_adapter' | ||
| 27 | |||
| 28 | ActiveRecord::Base.send(:include, ThinkingSphinx::ActiveRecord) | ||
| 29 | |||
| 30 | Merb::Plugins.add_rakefiles( | ||
| 31 | File.join(File.dirname(__FILE__), "thinking_sphinx", "tasks") | ||
| 32 | ) if defined?(Merb) | ||
| 33 | |||
| 34 | module ThinkingSphinx | ||
| 35 | module Version #:nodoc: | ||
| 36 | Major = 1 | ||
| 37 | Minor = 1 | ||
| 38 | Tiny = 6 | ||
| 39 | |||
| 40 | String = [Major, Minor, Tiny].join('.') | ||
| 41 | end | ||
| 42 | |||
| 43 | # A ConnectionError will get thrown when a connection to Sphinx can't be | ||
| 44 | # made. | ||
| 45 | class ConnectionError < StandardError | ||
| 46 | end | ||
| 47 | |||
| 48 | # A StaleIdsException is thrown by Collection.instances_from_matches if there | ||
| 49 | # are records in Sphinx but not in the database, so the search can be retried. | ||
| 50 | class StaleIdsException < StandardError | ||
| 51 | attr_accessor :ids | ||
| 52 | def initialize(ids) | ||
| 53 | self.ids = ids | ||
| 54 | end | ||
| 55 | end | ||
| 56 | |||
| 57 | # The collection of indexed models. Keep in mind that Rails lazily loads | ||
| 58 | # its classes, so this may not actually be populated with _all_ the models | ||
| 59 | # that have Sphinx indexes. | ||
| 60 | def self.indexed_models | ||
| 61 | @@indexed_models ||= [] | ||
| 62 | end | ||
| 63 | |||
| 64 | def self.unique_id_expression(offset = nil) | ||
| 65 | "* #{ThinkingSphinx.indexed_models.size} + #{offset || 0}" | ||
| 66 | end | ||
| 67 | |||
| 68 | # Check if index definition is disabled. | ||
| 69 | # | ||
| 70 | def self.define_indexes? | ||
| 71 | @@define_indexes = true unless defined?(@@define_indexes) | ||
| 72 | @@define_indexes == true | ||
| 73 | end | ||
| 74 | |||
| 75 | # Enable/disable indexes - you may want to do this while migrating data. | ||
| 76 | # | ||
| 77 | # ThinkingSphinx.define_indexes = false | ||
| 78 | # | ||
| 79 | def self.define_indexes=(value) | ||
| 80 | @@define_indexes = value | ||
| 81 | end | ||
| 82 | |||
| 83 | @@deltas_enabled = nil | ||
| 84 | |||
| 85 | # Check if delta indexing is enabled. | ||
| 86 | # | ||
| 87 | def self.deltas_enabled? | ||
| 88 | @@deltas_enabled = (ThinkingSphinx::Configuration.environment != 'test') if @@deltas_enabled.nil? | ||
| 89 | @@deltas_enabled | ||
| 90 | end | ||
| 91 | |||
| 92 | # Enable/disable all delta indexing. | ||
| 93 | # | ||
| 94 | # ThinkingSphinx.deltas_enabled = false | ||
| 95 | # | ||
| 96 | def self.deltas_enabled=(value) | ||
| 97 | @@deltas_enabled = value | ||
| 98 | end | ||
| 99 | |||
| 100 | @@updates_enabled = nil | ||
| 101 | |||
| 102 | # Check if updates are enabled. True by default, unless within the test | ||
| 103 | # environment. | ||
| 104 | # | ||
| 105 | def self.updates_enabled? | ||
| 106 | @@updates_enabled = (ThinkingSphinx::Configuration.environment != 'test') if @@updates_enabled.nil? | ||
| 107 | @@updates_enabled | ||
| 108 | end | ||
| 109 | |||
| 110 | # Enable/disable updates to Sphinx | ||
| 111 | # | ||
| 112 | # ThinkingSphinx.updates_enabled = false | ||
| 113 | # | ||
| 114 | def self.updates_enabled=(value) | ||
| 115 | @@updates_enabled = value | ||
| 116 | end | ||
| 117 | |||
| 118 | @@suppress_delta_output = false | ||
| 119 | |||
| 120 | def self.suppress_delta_output? | ||
| 121 | @@suppress_delta_output | ||
| 122 | end | ||
| 123 | |||
| 124 | def self.suppress_delta_output=(value) | ||
| 125 | @@suppress_delta_output = value | ||
| 126 | end | ||
| 127 | |||
| 128 | # Checks to see if MySQL will allow simplistic GROUP BY statements. If not, | ||
| 129 | # or if not using MySQL, this will return false. | ||
| 130 | # | ||
| 131 | def self.use_group_by_shortcut? | ||
| 132 | !!( | ||
| 133 | mysql? && ::ActiveRecord::Base.connection.select_all( | ||
| 134 | "SELECT @@global.sql_mode, @@session.sql_mode;" | ||
| 135 | ).all? { |key,value| value.nil? || value[/ONLY_FULL_GROUP_BY/].nil? } | ||
| 136 | ) | ||
| 137 | end | ||
| 138 | |||
| 139 | def self.sphinx_running? | ||
| 140 | !!sphinx_pid && pid_active?(sphinx_pid) | ||
| 141 | end | ||
| 142 | |||
| 143 | def self.sphinx_pid | ||
| 144 | pid_file = ThinkingSphinx::Configuration.instance.pid_file | ||
| 145 | cat_command = 'cat' | ||
| 146 | return nil unless File.exists?(pid_file) | ||
| 147 | |||
| 148 | if microsoft? | ||
| 149 | pid_file.gsub!('/', '\\') | ||
| 150 | cat_command = 'type' | ||
| 151 | end | ||
| 152 | |||
| 153 | `#{cat_command} #{pid_file}`[/\d+/] | ||
| 154 | end | ||
| 155 | |||
| 156 | def self.pid_active?(pid) | ||
| 157 | return true if microsoft? | ||
| 158 | |||
| 159 | begin | ||
| 160 | # In JRuby this returns -1 if the process doesn't exist | ||
| 161 | Process.getpgid(pid.to_i) != -1 | ||
| 162 | rescue Exception => e | ||
| 163 | false | ||
| 164 | end | ||
| 165 | end | ||
| 166 | |||
| 167 | def self.microsoft? | ||
| 168 | RUBY_PLATFORM =~ /mswin/ | ||
| 169 | end | ||
| 170 | |||
| 171 | def self.jruby? | ||
| 172 | defined?(JRUBY_VERSION) | ||
| 173 | end | ||
| 174 | |||
| 175 | def self.mysql? | ||
| 176 | ::ActiveRecord::Base.connection.class.name.demodulize == "MysqlAdapter" || ( | ||
| 177 | jruby? && ::ActiveRecord::Base.connection.config[:adapter] == "jdbcmysql" | ||
| 178 | ) | ||
| 179 | end | ||
| 180 | end | ||
