Class: Sunspot::IndexQueue::SessionProxy

Inherits:
SessionProxy::AbstractSessionProxy
  • Object
show all
Defined in:
lib/sunspot/index_queue/session_proxy.rb

Overview

This is a Sunspot::SessionProxy that works with the IndexQueue class. Most update requests will be added to the queue and be processed asynchronously. The exceptions are the remove method with a block and the remove_all method. These will send their commands directly to Solr since the queue cannot handle delete by query. You should avoid calling these methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue = nil, session = nil) ⇒ SessionProxy

Create a new session proxy for a particular queue (default to a queue for all classes bound to the default session configuration). You can specify the session argument if the session used for queries should be different than the one the queue is bound to.



17
18
19
20
# File 'lib/sunspot/index_queue/session_proxy.rb', line 17

def initialize(queue = nil, session = nil)
  @queue = queue || IndexQueue.new
  @session = session || @queue.session
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue.



10
11
12
# File 'lib/sunspot/index_queue/session_proxy.rb', line 10

def queue
  @queue
end

#sessionObject (readonly)

Returns the value of attribute session.



10
11
12
# File 'lib/sunspot/index_queue/session_proxy.rb', line 10

def session
  @session
end

Instance Method Details

#batchObject

Does nothing in this implementation.



23
24
25
# File 'lib/sunspot/index_queue/session_proxy.rb', line 23

def batch
  yield if block_given?
end

#commitObject

Does nothing in this implementation.



28
29
30
# File 'lib/sunspot/index_queue/session_proxy.rb', line 28

def commit
  # no op
end

#commit_if_delete_dirtyObject

Does nothing in this implementation.



33
34
35
# File 'lib/sunspot/index_queue/session_proxy.rb', line 33

def commit_if_delete_dirty
  # no op
end

#commit_if_dirtyObject

Does nothing in this implementation.



38
39
40
# File 'lib/sunspot/index_queue/session_proxy.rb', line 38

def commit_if_dirty
  # no op
end

#delete_dirty?Boolean

Always returns false in this implementation.

Returns:

  • (Boolean)


43
44
45
# File 'lib/sunspot/index_queue/session_proxy.rb', line 43

def delete_dirty?
  false
end

#dirty?Boolean

Always returns false in this implementation.

Returns:

  • (Boolean)


48
49
50
# File 'lib/sunspot/index_queue/session_proxy.rb', line 48

def dirty?
  false
end

#index(*objects) ⇒ Object

Queues up the index operation for later.



53
54
55
56
57
# File 'lib/sunspot/index_queue/session_proxy.rb', line 53

def index(*objects)
  objects.flatten.each do |object|
    queue.index(object)
  end
end

#index!(*objects) ⇒ Object

Queues up the index operation for later.



60
61
62
# File 'lib/sunspot/index_queue/session_proxy.rb', line 60

def index!(*objects)
  index(*objects)
end

#remove(*objects, &block) ⇒ Object

Queues up the remove operation for later unless a block is passed. In that case it will be performed immediately.



66
67
68
69
70
71
72
73
74
75
# File 'lib/sunspot/index_queue/session_proxy.rb', line 66

def remove(*objects, &block)
  if block
    # Delete by query not supported by queue, so send to server
    queue.session.remove(*objects, &block)
  else
    objects.flatten.each do |object|
      queue.remove(object)
    end
  end
end

#remove!(*objects, &block) ⇒ Object

Queues up the remove operation for later unless a block is passed. In that case it will be performed immediately.



79
80
81
82
83
84
85
86
# File 'lib/sunspot/index_queue/session_proxy.rb', line 79

def remove!(*objects, &block)
  if block
    # Delete by query not supported by queue, so send to server
    queue.session.remove!(*objects, &block)
  else
    remove(*objects)
  end
end

#remove_all(*classes) ⇒ Object

Proxies remove_all to the queue session.



89
90
91
92
# File 'lib/sunspot/index_queue/session_proxy.rb', line 89

def remove_all(*classes)
  # Delete by query not supported by queue, so send to server
  queue.session.remove_all(*classes)
end

#remove_all!(*classes) ⇒ Object

Proxies remove_all! to the queue session.



95
96
97
98
# File 'lib/sunspot/index_queue/session_proxy.rb', line 95

def remove_all!(*classes)
  # Delete by query not supported by queue, so send to server
  queue.session.remove_all!(*classes)
end

#remove_by_id(clazz, id) ⇒ Object

Queues up the index operation for later.



101
102
103
# File 'lib/sunspot/index_queue/session_proxy.rb', line 101

def remove_by_id(clazz, id)
  queue.remove(:class => clazz, :id => id)
end

#remove_by_id!(clazz, id) ⇒ Object

Queues up the index operation for later.



106
107
108
# File 'lib/sunspot/index_queue/session_proxy.rb', line 106

def remove_by_id!(clazz, id)
  remove_by_id(clazz, id)
end