module Sunspot::SubmodelIndex::InstanceMethods

Public Instance Methods

call_parent_solr_index() click to toggle source
# File lib/sunspot_submodel_index/submodel_index.rb, line 54
def call_parent_solr_index
  if self.respond_to?(self._sunspot_submodel_options[:parent]) && !self.send(self._sunspot_submodel_options[:parent]).nil?
    self.send(self._sunspot_submodel_options[:parent],true) if self._sunspot_submodel_options[:force_association_reload]
    if self.send(self._sunspot_submodel_options[:parent]).is_a?(Enumerable)
      self.send(self._sunspot_submodel_options[:parent]).each {|item| item.solr_index }
    else
      self.send(self._sunspot_submodel_options[:parent]).solr_index 
    end
  end
end
check_parent_solr_if_statement() click to toggle source
# File lib/sunspot_submodel_index/submodel_index.rb, line 65
def check_parent_solr_if_statement
  if self._sunspot_submodel_options[:if] && self._sunspot_submodel_options[:if].instance_of?(Proc)
    self._sunspot_submodel_options[:if].call(self)
  else
    true
  end
end
mark_for_parent_solr_index() click to toggle source

to run before a save to see if this is a new record, or if fields I care about changed.

# File lib/sunspot_submodel_index/submodel_index.rb, line 74
def mark_for_parent_solr_index
  #only mark for index if the record is new, or if fields changed that I care about
  #check the if proc first
  return unless check_parent_solr_if_statement
  if self._sunspot_submodel_options[:included_attributes]
    fields_changed = !(self.changed.map {|k| k.to_sym} & self._sunspot_submodel_options[:included_attributes]).empty?
  elsif self._sunspot_submodel_options[:ignored_attributes]
    fields_changed = !(self.changed.map {|k| k.to_sym} - self._sunspot_submodel_options[:ignored_attributes]).empty?
  else
    fields_changed = true
  end
  if new_record? || fields_changed
    @marked_for_parent_solr_indexing = true
  end
end
parent_solr_index() click to toggle source

call reindex if I need too

# File lib/sunspot_submodel_index/submodel_index.rb, line 91
def parent_solr_index
  if @marked_for_parent_solr_indexing
    call_parent_solr_index
    remove_instance_variable(:@marked_for_parent_solr_indexing)
  end
end
parent_solr_index_on_destroy() click to toggle source

always call reindex on destroy

# File lib/sunspot_submodel_index/submodel_index.rb, line 99
def parent_solr_index_on_destroy
  return unless check_parent_solr_if_statement
  call_parent_solr_index
end