Class: ThinkingSphinx::Source

Inherits:
Object
  • Object
show all
Includes:
InternalProperties, SQL
Defined in:
lib/thinking_sphinx/source.rb,
lib/thinking_sphinx/source/sql.rb,
lib/thinking_sphinx/source/internal_properties.rb

Defined Under Namespace

Modules: InternalProperties, SQL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SQL

#crc_column, #quote_column, #sql_group_clause, #sql_query_pre_for_core, #sql_query_pre_for_delta, #sql_select_clause, #sql_where_clause, #to_sql, #to_sql_query_info, #to_sql_query_range

Methods included from InternalProperties

#add_internal_attribute, #add_internal_attributes_and_facets, #add_internal_facet, #attribute_by_alias, #facet_by_alias, #subclasses_to_s

Constructor Details

#initialize(index, options = {}) ⇒ Source

Returns a new instance of Source.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/thinking_sphinx/source.rb', line 13

def initialize(index, options = {})
  @index        = index
  @model        = index.model
  @fields       = []
  @attributes   = []
  @conditions   = []
  @groupings    = []
  @options      = options
  @associations = {}
  @database_configuration = @model.connection.
    instance_variable_get(:@config).clone
  
  @base = ::ActiveRecord::Associations::ClassMethods::JoinDependency.new(
    @model, [], nil
  )
  
  unless @model.descends_from_active_record?
    stored_class = @model.store_full_sti_class ? @model.name : @model.name.demodulize
    @conditions << "#{@model.quoted_table_name}.#{quote_column(@model.inheritance_column)} = '#{stored_class}'"
  end
  
  add_internal_attributes_and_facets
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



9
10
11
# File 'lib/thinking_sphinx/source.rb', line 9

def attributes
  @attributes
end

#baseObject (readonly)

Returns the value of attribute base.



11
12
13
# File 'lib/thinking_sphinx/source.rb', line 11

def base
  @base
end

#conditionsObject

Returns the value of attribute conditions.



9
10
11
# File 'lib/thinking_sphinx/source.rb', line 9

def conditions
  @conditions
end

#database_configurationObject (readonly)

Returns the value of attribute database_configuration.



11
12
13
# File 'lib/thinking_sphinx/source.rb', line 11

def database_configuration
  @database_configuration
end

#fieldsObject

Returns the value of attribute fields.



9
10
11
# File 'lib/thinking_sphinx/source.rb', line 9

def fields
  @fields
end

#groupingsObject

Returns the value of attribute groupings.



9
10
11
# File 'lib/thinking_sphinx/source.rb', line 9

def groupings
  @groupings
end

#indexObject (readonly)

Returns the value of attribute index.



11
12
13
# File 'lib/thinking_sphinx/source.rb', line 11

def index
  @index
end

#modelObject

Returns the value of attribute model.



9
10
11
# File 'lib/thinking_sphinx/source.rb', line 9

def model
  @model
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/thinking_sphinx/source.rb', line 9

def options
  @options
end

Instance Method Details

#association(key) ⇒ Object

Gets the association stack for a specific key.



74
75
76
# File 'lib/thinking_sphinx/source.rb', line 74

def association(key)
  @associations[key] ||= Association.children(@model, key)
end

#delta?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/thinking_sphinx/source.rb', line 68

def delta?
  !@index.delta_object.nil?
end

#nameObject



37
38
39
# File 'lib/thinking_sphinx/source.rb', line 37

def name
  index.name
end

#to_riddle_for_core(offset, position) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/thinking_sphinx/source.rb', line 41

def to_riddle_for_core(offset, position)
  source = Riddle::Configuration::SQLSource.new(
    "#{index.core_name}_#{position}", adapter.sphinx_identifier
  )
  
  set_source_database_settings  source
  set_source_attributes         source, offset
  set_source_settings           source
  set_source_sql                source, offset
  
  source
end

#to_riddle_for_delta(offset, position) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/thinking_sphinx/source.rb', line 54

def to_riddle_for_delta(offset, position)
  source = Riddle::Configuration::SQLSource.new(
    "#{index.delta_name}_#{position}", adapter.sphinx_identifier
  )
  source.parent = "#{index.core_name}_#{position}"
  
  set_source_database_settings  source
  set_source_attributes         source, offset, true
  set_source_settings           source
  set_source_sql                source, offset, true
  
  source
end