class_condition()
click to toggle source
def class_condition
"(#{classes_and_descendants_names.join('|')})"
end
class_condition_required?()
click to toggle source
def class_condition_required?
classes.any? && !indices_match_classes?
end
classes()
click to toggle source
def classes
options[:classes] || []
end
classes_and_descendants()
click to toggle source
def classes_and_descendants
classes + descendants
end
classes_and_descendants_names()
click to toggle source
def classes_and_descendants_names
classes_and_descendants.collect do |klass|
name = klass.name
name = %Q{"#{name}"} if name[/:/]
name
end
end
classes_with_inheritance_column()
click to toggle source
def classes_with_inheritance_column
classes.select { |klass|
klass.column_names.include?(klass.inheritance_column)
}
end
constantize_inheritance_column(klass)
click to toggle source
def constantize_inheritance_column(klass)
klass.connection.select_values(inheritance_column_select(klass)).compact.each(&:constantize)
end
descendants()
click to toggle source
def descendants
@descendants ||= options[:skip_sti] ? [] : descendants_from_tables
end
descendants_from_tables()
click to toggle source
def descendants_from_tables
classes_with_inheritance_column.collect do |klass|
constantize_inheritance_column(klass)
klass.descendants
end.flatten
end
exclusive_filters()
click to toggle source
def exclusive_filters
@exclusive_filters ||= (options[:without] || {}).tap do |without|
without[:sphinx_internal_id] = options[:without_ids] if options[:without_ids].present?
end
end
extended_query()
click to toggle source
def extended_query
conditions = options[:conditions] || {}
if class_condition_required?
conditions[:sphinx_internal_class_name] = class_condition
end
@extended_query ||= ThinkingSphinx::Search::Query.new(
context.search.query, conditions, options[:star]
).to_s
end
group_attribute()
click to toggle source
def group_attribute
options[:group_by].to_s if options[:group_by]
end
group_order_clause()
click to toggle source
def group_order_clause
group_by = options[:order_group_by]
group_by = "#{group_by} ASC" if group_by.is_a? Symbol
group_by
end
inclusive_filters()
click to toggle source
def inclusive_filters
(options[:with] || {}).merge({:sphinx_deleted => false})
end
index_names()
click to toggle source
def index_names
indices.collect(&:name)
end
index_options()
click to toggle source
def index_options
indices.first.options
end
indices()
click to toggle source
def indices
@indices ||= begin
set = ThinkingSphinx::IndexSet.new classes, options[:indices]
raise ThinkingSphinx::NoIndicesError if set.empty?
set
end
end
indices_match_classes?()
click to toggle source
def indices_match_classes?
indices.collect(&:reference).uniq.sort == classes.collect { |klass|
klass.name.underscore.to_sym
}.sort
end
inheritance_column_select(klass)
click to toggle source
def inheritance_column_select(klass)
<<-SQL
SELECT DISTINCT #{klass.inheritance_column}
FROM #{klass.table_name}
SQL
end
order_clause()
click to toggle source
def order_clause
order_by = options[:order]
order_by = "#{order_by} ASC" if order_by.is_a? Symbol
order_by
end
select_options()
click to toggle source
def select_options
@select_options ||= SELECT_OPTIONS.inject({}) do |hash, key|
hash[key] = settings[key.to_s] if settings.key? key.to_s
hash[key] = index_options[key] if index_options.key? key
hash[key] = options[key] if options.key? key
hash
end
end
statement()
click to toggle source
def statement
Statement.new(self).to_riddle_query_select
end
values()
click to toggle source
def values
options[:select] ||= "*, #{ThinkingSphinx::SphinxQL.group_by}, #{ThinkingSphinx::SphinxQL.count}" if group_attribute.present?
options[:select]
end