class Elastics::InstanceProxy::ModelIndexer
Attributes
index[W]
parent[W]
routing[W]
type[W]
Public Instance Methods
each_parent() { |pi| ... }
click to toggle source
helper that iterates through the parent record chain record.elastics.each_parent{|p| p.do_something }
# File lib/elastics/instance_proxy/model_indexer.rb, line 49 def each_parent pi = parent_instance while pi do yield pi pi = pi.elastics.parent_instance end end
full_get(*vars)
click to toggle source
like get, but it returns all the source fields after a refresh
# File lib/elastics/instance_proxy/model_indexer.rb, line 36 def full_get(*vars) return unless instance.elastics_indexable? Elastics.search_by_id(metainfo, {:refresh => true, :params => {:_source => '*'}}, *vars) end
get(*vars)
click to toggle source
gets the document from ES
# File lib/elastics/instance_proxy/model_indexer.rb, line 30 def get(*vars) return unless instance.elastics_indexable? Elastics.get(metainfo, *vars) end
id()
click to toggle source
# File lib/elastics/instance_proxy/model_indexer.rb, line 71 def id @id ||= instance.respond_to?(:elastics_id) ? instance.elastics_id : instance.id.to_s end
index()
click to toggle source
# File lib/elastics/instance_proxy/model_indexer.rb, line 57 def index @index ||= instance.respond_to?(:elastics_index) ? instance.elastics_index : class_elastics.index end
metainfo()
click to toggle source
# File lib/elastics/instance_proxy/model_indexer.rb, line 93 def metainfo meta = Vars.new( :index => index, :type => type, :id => id ) params = {} params[:routing] = routing if routing params[:parent] = parent if parent meta.merge!(:params => params) unless params.empty? meta end
parent()
click to toggle source
# File lib/elastics/instance_proxy/model_indexer.rb, line 84 def parent @parent ||= case when instance.respond_to?(:elastics_parent) then instance.elastics_parent when is_child? then parent_instance.id.to_s else nil end end
parent_instance()
click to toggle source
# File lib/elastics/instance_proxy/model_indexer.rb, line 41 def parent_instance return unless is_child? @parent_instance ||= instance.send(class_elastics.parent_association) || raise(MissingParentError, "missing parent instance for document #{instance.inspect}.") end
remove(*vars)
click to toggle source
removes the document from the index (called from after_destroy)
# File lib/elastics/instance_proxy/model_indexer.rb, line 24 def remove(*vars) return unless instance.elastics_indexable? Elastics.remove(metainfo, *vars) end
routing()
click to toggle source
# File lib/elastics/instance_proxy/model_indexer.rb, line 75 def routing @routing ||= case when instance.respond_to?(:elastics_routing) then instance.elastics_routing when is_child? then parent_instance.elastics.routing when is_parent? then id end end
store(*vars)
click to toggle source
indexes the document usually called from after_save, you can eventually call it explicitly for example from another callback or whenever the DB doesn't get updated by the model you can also pass the :data=>elastics_source explicitly (useful for example to override the elastics_source in the model)
# File lib/elastics/instance_proxy/model_indexer.rb, line 15 def store(*vars) if instance.elastics_indexable? Elastics.store(metainfo, {:data => instance.elastics_source}, *vars) else Elastics.remove(metainfo, *vars) if Elastics.get(metainfo, *vars, :raise => false) end end
sync_self()
click to toggle source
# File lib/elastics/instance_proxy/model_indexer.rb, line 102 def sync_self instance.destroyed? ? remove : store end
type()
click to toggle source
# File lib/elastics/instance_proxy/model_indexer.rb, line 62 def type @type ||= case when instance.respond_to?(:elastics_type) then instance.elastics_type when is_child? then class_elastics.parent_child_map[parent_instance.elastics.type] else class_elastics.type end end