Skip to content

Commit

Permalink
Try to fix problem with large identifiers for Postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
tonic20 committed Mar 28, 2011
1 parent 088d9aa commit 5e08986
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ rdoc
database.yml
tmp
*.gem
*~
33 changes: 17 additions & 16 deletions lib/thinking_sphinx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

module ThinkingSphinx
mattr_accessor :database_adapter

# A ConnectionError will get thrown when a connection to Sphinx can't be
# made.
class ConnectionError < StandardError
Expand All @@ -47,7 +47,7 @@ def initialize(ids)
self.ids = ids
end
end

# A SphinxError occurs when Sphinx responds with an error due to problematic
# queries or indexes.
class SphinxError < RuntimeError
Expand All @@ -57,23 +57,23 @@ def initialize(message = nil, results = nil)
self.results = results
end
end

# The current version of Thinking Sphinx.
#
#
# @return [String] The version number as a string
#
#
def self.version
open(File.join(File.dirname(__FILE__), '../VERSION')) { |f|
f.read.strip
}
end

# 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.
@@sphinx_mutex = Mutex.new
@@context = nil

def self.context
if @@context.nil?
@@sphinx_mutex.synchronize do
Expand All @@ -83,18 +83,18 @@ def self.context
end
end
end

@@context
end

def self.reset_context!
@@sphinx_mutex.synchronize do
@@context = nil
end
end

def self.unique_id_expression(offset = nil)
"* #{context.indexed_models.size} + #{offset || 0}"
"* #{context.indexed_models.size}::INT8 + #{offset || 0}"
end

# Check if index definition is disabled.
Expand All @@ -103,7 +103,7 @@ 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

Expand All @@ -123,7 +123,7 @@ def self.deltas_enabled?
ThinkingSphinx::Configuration.environment != "test"
)
end

Thread.current[:thinking_sphinx_deltas_enabled]
end

Expand All @@ -144,7 +144,7 @@ def self.updates_enabled?
ThinkingSphinx::Configuration.environment != "test"
)
end

Thread.current[:thinking_sphinx_updates_enabled]
end

Expand All @@ -163,7 +163,7 @@ def self.suppress_delta_output?
def self.suppress_delta_output=(value)
Thread.current[:thinking_sphinx_suppress_delta_output] = value
end

# Checks to see if MySQL will allow simplistic GROUP BY statements. If not,
# or if not using MySQL, this will return false.
#
Expand All @@ -175,7 +175,7 @@ def self.use_group_by_shortcut?
).all? { |key,value| value.nil? || value[/ONLY_FULL_GROUP_BY/].nil? }
)
end

Thread.current[:thinking_sphinx_use_group_by_shortcut]
end

Expand Down Expand Up @@ -243,8 +243,9 @@ def self.mysql?
jruby? && ::ActiveRecord::Base.connection.config[:adapter] == "jdbcmysql"
)
end

extend ThinkingSphinx::SearchMethods::ClassMethods
end

ThinkingSphinx::AutoVersion.detect

0 comments on commit 5e08986

Please sign in to comment.