class ThinkingSphinx::Middlewares::SphinxQL::Inner
Attributes
context[R]
Public Class Methods
new(context)
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 22 def initialize(context) @context = context end
Public Instance Methods
call()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 26 def call context[:indices] = indices context[:sphinxql] = statement end
Private Instance Methods
class_condition()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 61 def class_condition "(#{classes_and_descendants_names.join('|')})" end
class_condition_required?()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 65 def class_condition_required? classes.any? && !indices_match_classes? end
classes()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 39 def classes options[:classes] || [] end
classes_and_descendants()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 43 def classes_and_descendants classes + descendants end
classes_and_descendants_names()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 47 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
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 55 def classes_with_inheritance_column classes.select { |klass| klass.column_names.include?(klass.inheritance_column) } end
constantize_inheritance_column(klass)
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 69 def constantize_inheritance_column(klass) values = klass.connection.select_values inheritance_column_select(klass) values.reject(&:blank?).each(&:constantize) end
descendants()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 74 def descendants @descendants ||= options[:skip_sti] ? [] : descendants_from_tables end
descendants_from_tables()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 78 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
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 85 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
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 91 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
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 102 def group_attribute options[:group_by].to_s if options[:group_by] end
group_order_clause()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 106 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
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 112 def inclusive_filters (options[:with] || {}).merge({:sphinx_deleted => false}) end
index_names()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 116 def index_names indices.collect(&:name) end
index_options()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 120 def index_options indices.first.options end
indices()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 124 def indices @indices ||= begin set = configuration.index_set_class.new( options.slice(:classes, :indices) ) raise ThinkingSphinx::NoIndicesError if set.empty? set end end
indices_match_classes?()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 134 def indices_match_classes? indices.collect(&:reference).uniq.sort == classes.collect { |klass| configuration.index_set_class.reference_name(klass) }.sort end
inheritance_column_select(klass)
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 140 def inheritance_column_select(klass) <<-SQL SELECT DISTINCT #{klass.inheritance_column} FROM #{klass.table_name} SQL end
order_clause()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 147 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
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 153 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
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 170 def statement Statement.new(self).to_riddle_query_select end
values()
click to toggle source
# File lib/thinking_sphinx/middlewares/sphinxql.rb, line 162 def values options[:select] ||= ['*', "groupby() AS sphinx_internal_group", "id AS sphinx_document_id, count(DISTINCT sphinx_document_id) AS sphinx_internal_count" ].join(', ') if group_attribute.present? options[:select] end