class ThinkingSphinx::ActiveRecord::SQLBuilder::Statement

Attributes

report[R]
scope[R]

Public Class Methods

new(report) click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 6
def initialize(report)
  @report = report
  @scope  = relation
end

Public Instance Methods

to_query_info_relation() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 23
def to_query_info_relation
  filter_by_query_info

  scope
end
to_query_pre() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 29
def to_query_pre
  filter_by_query_pre

  scope
end
to_query_range_relation() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 17
def to_query_range_relation
  filter_by_query_range

  scope
end
to_relation() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 11
def to_relation
  filter_by_scopes

  scope
end

Private Instance Methods

attribute_presenters() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 65
def attribute_presenters
  @attribute_presenters ||= property_sql_presenters_for source.attributes
end
custom_joins() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 39
def custom_joins
  @custom_joins ||= source.associations.select(&:string?).collect(&:to_s)
end
field_presenters() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 69
def field_presenters
  @field_presenters ||= property_sql_presenters_for source.fields
end
filter_by_query_info() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 52
def filter_by_query_info
  @scope = scope.where("#{quoted_primary_key} = #{reversed_document_id}")
end
filter_by_query_range() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 43
def filter_by_query_range
  minimum = convert_nulls "MIN(#{quoted_primary_key})", 1
  maximum = convert_nulls "MAX(#{quoted_primary_key})", 1

  @scope = scope.select("#{minimum}, #{maximum}").where(
    where_clause(true)
  )
end
filter_by_scopes() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 56
def filter_by_scopes
  scope_by_select
  scope_by_where_clause
  scope_by_group_clause
  scope_by_joins
  scope_by_custom_joins
  scope_by_order
end
group_clause() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 137
def group_clause
  builder = SQLBuilder::ClauseBuilder.new(quoted_primary_key)

  builder.compose(
    presenters_to_group(field_presenters),
    presenters_to_group(attribute_presenters)
  ) unless source.options[:minimal_group_by?]

  builder.compose(groupings).separated
end
method_missing(*args, &block) click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 119
def method_missing(*args, &block)
  report.send *args, &block
end
presenters_to_group(presenters) click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 73
def presenters_to_group(presenters)
  presenters.collect(&:to_group)
end
presenters_to_select(presenters) click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 77
def presenters_to_select(presenters)
  presenters.collect(&:to_select)
end
property_sql_presenter_for(property) click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 85
def property_sql_presenter_for(property)
  ThinkingSphinx::ActiveRecord::PropertySQLPresenter.new(
    property, source.adapter, associations
  )
end
property_sql_presenters_for(properties) click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 81
def property_sql_presenters_for(properties)
  properties.collect { |property| property_sql_presenter_for(property) }
end
scope_by_custom_joins() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 107
def scope_by_custom_joins
  @scope = scope.joins(custom_joins) if custom_joins.any?
end
scope_by_group_clause() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 99
def scope_by_group_clause
  @scope = scope.group(group_clause)
end
scope_by_joins() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 103
def scope_by_joins
  @scope = scope.joins(associations.join_values)
end
scope_by_order() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 111
def scope_by_order
  @scope = scope.order('NULL') if source.type == 'mysql'
end
scope_by_select() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 91
def scope_by_select
  @scope = scope.select(pre_select + select_clause)
end
scope_by_where_clause() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 95
def scope_by_where_clause
  @scope = scope.where where_clause
end
select_clause() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 123
def select_clause
  SQLBuilder::ClauseBuilder.new(document_id).compose(
    presenters_to_select(field_presenters),
    presenters_to_select(attribute_presenters)
  ).separated
end
source() click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 115
def source
  report.source
end
where_clause(for_range = false) click to toggle source
# File lib/thinking_sphinx/active_record/sql_builder/statement.rb, line 130
def where_clause(for_range = false)
  builder = SQLBuilder::ClauseBuilder.new(nil)
  builder.add_clause delta_processor.clause(source.delta?) if delta_processor
  builder.add_clause range_condition unless for_range
  builder.separated(' AND ')
end