Class: ThinkingSphinx::Processor

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

Instance Method Summary collapse

Constructor Details

#initialize(instance: nil, model: nil, id: nil) ⇒ Processor

Returns a new instance of Processor.

Parameters:

  • instance (ActiveRecord::Base) (defaults to: nil)

    an ActiveRecord object

  • model (Class) (defaults to: nil)

    the ActiveRecord model of the instance

  • id (Integer) (defaults to: nil)

    the instance indices primary key (might be different from model primary key)

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
# File 'lib/thinking_sphinx/processor.rb', line 7

def initialize(instance: nil, model: nil, id: nil)
  raise ArgumentError if instance.nil? && (model.nil? || id.nil?)

  @instance = instance
  @model = model || instance.class
  @id = id
end

Instance Method Details

#deleteObject



15
16
17
18
19
# File 'lib/thinking_sphinx/processor.rb', line 15

def delete
  return if instance&.new_record?

  indices.each { |index| perform_deletion(index) }
end

#syncObject

Will upsert or delete instance into all matching indices based on index scope



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/thinking_sphinx/processor.rb', line 30

def sync
  real_time_indices.each do |index|
    found = find_in(index)

    if found
      ThinkingSphinx::RealTime::Transcriber.new(index).copy found
    else
      ThinkingSphinx::Deletion.perform(index, index_id(index))
    end
  end
end

#upsertObject

Will insert instance into all matching indices



22
23
24
25
26
27
# File 'lib/thinking_sphinx/processor.rb', line 22

def upsert
  real_time_indices.each do |index|
    found = loaded_instance(index)
    ThinkingSphinx::RealTime::Transcriber.new(index).copy found if found
  end
end