Sha256: 17e04e9d47369a2f00387dfac427f7ef62c03d9cf5156139fc5cca14b764002e

Contents?: true

Size: 949 Bytes

Versions: 9

Compression:

Stored size: 949 Bytes

Contents

module ThinkingSphinx::ActiveRecord::AssociationProxy
  extend ActiveSupport::Concern

  def search(query = nil, options = {})
    perform_search super(*normalise_search_arguments(query, options))
  end

  def search_for_ids(query = nil, options = {})
    perform_search super(*normalise_search_arguments(query, options))
  end

  private
  def normalise_search_arguments(query, options)
    query, options = nil, query if query.is_a?(Hash)
    options[:ignore_scopes] = true

    [query, options]
  end

  def perform_search(searcher)
    ThinkingSphinx::Search::Merger.new(searcher).merge! nil,
      :with => association_filter
  end

  def association_filter
    attribute = AttributeFinder.new(proxy_association).attribute

    {attribute.name.to_sym => proxy_association.owner.id}
  end
end

require 'thinking_sphinx/active_record/association_proxy/attribute_finder'
require 'thinking_sphinx/active_record/association_proxy/attribute_matcher'

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
thinking-sphinx-3.4.2 lib/thinking_sphinx/active_record/association_proxy.rb
thinking-sphinx-3.4.1 lib/thinking_sphinx/active_record/association_proxy.rb
thinking-sphinx-3.4.0 lib/thinking_sphinx/active_record/association_proxy.rb
thinking-sphinx-3.3.0 lib/thinking_sphinx/active_record/association_proxy.rb
thinking-sphinx-3.2.0 lib/thinking_sphinx/active_record/association_proxy.rb
thinking-sphinx-3.1.4 lib/thinking_sphinx/active_record/association_proxy.rb
thinking-sphinx-3.1.3 lib/thinking_sphinx/active_record/association_proxy.rb
thinking-sphinx-3.1.2 lib/thinking_sphinx/active_record/association_proxy.rb
thinking-sphinx-3.1.1 lib/thinking_sphinx/active_record/association_proxy.rb