Skip to content

Commit

Permalink
Merge branch 'master' into rails3
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Nov 3, 2011
2 parents 05bdeae + f037d4c commit 42a120d
Show file tree
Hide file tree
Showing 24 changed files with 486 additions and 363 deletions.
2 changes: 2 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Edge:
* Updating Riddle references for impending 1.5.0 release.
* Handle out-of-date indexed_models references.
* Fixing STI model handling during context index loading (Kenn Ejima).

2.0.9 - October 10th 2011
Expand Down
6 changes: 3 additions & 3 deletions lib/thinking_sphinx/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ def environment
end

def generate
@configuration.indexes.clear
@configuration.indices.clear

ThinkingSphinx.context.indexed_models.each do |model|
model = model.constantize
model.define_indexes
@configuration.indexes.concat model.to_riddle
@configuration.indices.concat model.to_riddle

enforce_common_attribute_types
end
Expand Down Expand Up @@ -316,7 +316,7 @@ def set_sphinx_setting(object, key, value, allowed = {})
end

def enforce_common_attribute_types
sql_indexes = configuration.indexes.reject { |index|
sql_indexes = configuration.indices.reject { |index|
index.is_a? Riddle::Configuration::DistributedIndex
}

Expand Down
70 changes: 35 additions & 35 deletions lib/thinking_sphinx/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module ThinkingSphinx
class Index
attr_accessor :name, :model, :sources, :delta_object

# Create a new index instance by passing in the model it is tied to, and
# a block to build it with (optional but recommended). For documentation
# on the syntax for inside the block, the Builder class is what you want.
Expand All @@ -13,9 +13,9 @@ class Index
#
# Index.new(User) do
# indexes login, email
#
#
# has created_at
#
#
# set_property :delta => true
# end
#
Expand All @@ -26,46 +26,46 @@ def initialize(model, &block)
@options = {}
@delta_object = nil
end

def fields
@sources.collect { |source| source.fields }.flatten
end

def attributes
@sources.collect { |source| source.attributes }.flatten
end

def core_name
"#{name}_core"
end

def delta_name
"#{name}_delta"
end

def all_names
names = [core_name]
names << delta_name if delta?

names
end

def self.name_for(model)
model.name.underscore.tr(':/\\', '_')
end

def prefix_fields
fields.select { |field| field.prefixes }
end

def infix_fields
fields.select { |field| field.infixes }
end

def local_options
@options
end

def options
all_index_options = config.index_options.clone
@options.keys.select { |key|
Expand All @@ -74,82 +74,82 @@ def options
}.each { |key| all_index_options[key.to_sym] = @options[key] }
all_index_options
end

def delta?
!@delta_object.nil?
end

def to_riddle(offset)
indexes = [to_riddle_for_core(offset)]
indexes << to_riddle_for_delta(offset) if delta?
indexes << to_riddle_for_distributed
end

private

def adapter
@adapter ||= @model.sphinx_database_adapter
end

def utf8?
options[:charset_type] == "utf-8"
end

def sql_query_pre_for_delta
[""]
end

def config
@config ||= ThinkingSphinx::Configuration.instance
end

def to_riddle_for_core(offset)
index = Riddle::Configuration::Index.new core_name
index.path = File.join config.searchd_file_path, index.name

set_configuration_options_for_indexes index
set_field_settings_for_indexes index

sources.each_with_index do |source, i|
index.sources << source.to_riddle_for_core(offset, i)
end

index
end

def to_riddle_for_delta(offset)
index = Riddle::Configuration::Index.new delta_name
index.parent = core_name
index.path = File.join config.searchd_file_path, index.name

sources.each_with_index do |source, i|
index.sources << source.to_riddle_for_delta(offset, i)
end

index
end

def to_riddle_for_distributed
index = Riddle::Configuration::DistributedIndex.new name
index.local_indexes << core_name
index.local_indexes.unshift delta_name if delta?
index.local_indices << core_name
index.local_indices.unshift delta_name if delta?
index
end

def set_configuration_options_for_indexes(index)
config.index_options.each do |key, value|
method = "#{key}=".to_sym
index.send(method, value) if index.respond_to?(method)
end

options.each do |key, value|
index.send("#{key}=".to_sym, value) if ThinkingSphinx::Configuration::IndexOptions.include?(key.to_s) && !value.nil?
end
end

def set_field_settings_for_indexes(index)
field_names = lambda { |field| field.unique_name.to_s }

index.prefix_field_names += prefix_fields.collect(&field_names)
index.infix_field_names += infix_fields.collect(&field_names)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/thinking_sphinx/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
config.reset
config.generate

config.configuration.indexes.each do |index|
config.configuration.indices.each do |index|
next if index.is_a? Riddle::Configuration::DistributedIndex

index.sources.each do |source|
Expand Down
Loading

0 comments on commit 42a120d

Please sign in to comment.