Class: ThinkingSphinx::Search::Merger

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/search/merger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search) ⇒ Merger

Returns a new instance of Merger.



6
7
8
# File 'lib/thinking_sphinx/search/merger.rb', line 6

def initialize(search)
  @search = search
end

Instance Attribute Details

#searchObject (readonly)

Returns the value of attribute search.



4
5
6
# File 'lib/thinking_sphinx/search/merger.rb', line 4

def search
  @search
end

Instance Method Details

#merge!(query = nil, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/thinking_sphinx/search/merger.rb', line 10

def merge!(query = nil, options = {})
  if search.populated?
    raise ThinkingSphinx::PopulatedResultsError, 'This search request has already been made - you can no longer modify it.'
  end

  query, options = nil, query if query.is_a?(Hash)
  @search.query  = query unless query.nil?

  options.each do |key, value|
    case key
    when :conditions, :with, :without, :with_all, :without_all
      @search.options[key] ||= {}
      @search.options[key].merge! value
    when :without_ids, :classes
      @search.options[key] ||= []
      @search.options[key] += value
      @search.options[key].uniq!
    else
      @search.options[key] = value
    end
  end

  @search
end