# File lib/thinking_sphinx/core/index.rb, line 62 def primary_key @primary_key ||= @options[:primary_key] || config.settings['primary_key'] || model.primary_key || :id end
module ThinkingSphinx::Core::Index
Public Class Methods
new(reference, options = {})
click to toggle source
Calls superclass method
# File lib/thinking_sphinx/core/index.rb, line 12 def initialize(reference, options = {}) @reference = reference.to_sym @options = options @offset = config.next_offset(options[:offset_as] || reference) @type = 'plain' super "#{options[:name] || reference.to_s.gsub('/', '_')}_#{name_suffix}" end
Public Instance Methods
delta?()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 21 def delta? false end
distributed?()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 25 def distributed? false end
document_id_for_instance(instance)
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 29 def document_id_for_instance(instance) document_id_for_key instance.public_send(primary_key) end
document_id_for_key(key)
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 33 def document_id_for_key(key) return nil if key.nil? key * config.indices.count + offset end
interpret_definition!()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 39 def interpret_definition! table_exists = model.table_exists? unless table_exists Rails.logger.info "No table exists for #{model}. Index can not be created" return end return if @interpreted_definition apply_defaults! @interpreted_definition = true interpreter.translate! self, @definition_block if @definition_block end
model()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 53 def model @model ||= reference.to_s.camelize.constantize end
options()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 57 def options interpret_definition! @options end
primary_key()
click to toggle source
render()
click to toggle source
Calls superclass method
# File lib/thinking_sphinx/core/index.rb, line 67 def render pre_render set_path assign_infix_fields assign_prefix_fields super end
Private Instance Methods
assign_infix_fields()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 79 def assign_infix_fields self.infix_fields = fields.select(&:infixing?).collect(&:name) end
assign_prefix_fields()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 83 def assign_prefix_fields self.prefix_fields = fields.select(&:prefixing?).collect(&:name) end
config()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 87 def config ThinkingSphinx::Configuration.instance end
name_suffix()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 91 def name_suffix 'core' end
path_prefix()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 95 def path_prefix options[:path] || config.indices_location end
pre_render()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 99 def pre_render interpret_definition! end
set_path()
click to toggle source
# File lib/thinking_sphinx/core/index.rb, line 103 def set_path unless config.settings['skip_directory_creation'] FileUtils.mkdir_p path_prefix end @path = File.join path_prefix, name end