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, #internal_class_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, #type_values, #types_to_crcs

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

- (Source) initialize(index, options = {})

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
36
# File 'lib/thinking_sphinx/source.rb', line 13

def initialize(index, options = {})
  @index        = index
  @model        = index.model
  @fields       = []
  @attributes   = []
  @joins        = []
  @conditions   = []
  @groupings    = []
  @options      = options
  @associations = {}
  @database_configuration = @model.connection.
    instance_variable_get(:@config).clone

  @base = join_dependency_class.new(
    @model, [], initial_joins
  )

  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

- (Object) attributes

Returns the value of attribute attributes



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

def attributes
  @attributes
end

- (Object) base (readonly)

Returns the value of attribute base



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

def base
  @base
end

- (Object) conditions

Returns the value of attribute conditions



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

def conditions
  @conditions
end

- (Object) database_configuration (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

- (Object) fields

Returns the value of attribute fields



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

def fields
  @fields
end

- (Object) groupings

Returns the value of attribute groupings



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

def groupings
  @groupings
end

- (Object) index (readonly)

Returns the value of attribute index



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

def index
  @index
end

- (Object) joins

Returns the value of attribute joins



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

def joins
  @joins
end

- (Object) model

Returns the value of attribute model



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

def model
  @model
end

- (Object) options

Returns the value of attribute options



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

def options
  @options
end

Instance Method Details

- (Object) association(key)

Gets the association stack for a specific key.



77
78
79
# File 'lib/thinking_sphinx/source.rb', line 77

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

- (Boolean) delta?

Returns:

  • (Boolean)


71
72
73
# File 'lib/thinking_sphinx/source.rb', line 71

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

- (Object) name



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

def name
  index.name
end

- (Object) to_riddle_for_core(offset, position)



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

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_fields             source
  set_source_attributes         source, offset
  set_source_settings           source
  set_source_sql                source, offset

  source
end

- (Object) to_riddle_for_delta(offset, position)



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

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_fields             source
  set_source_attributes         source, offset, true
  set_source_settings           source
  set_source_sql                source, offset, true

  source
end