Module: Slingshot::Model::Search::InstanceMethods

Defined in:
lib/slingshot/model/search.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



66
67
68
# File 'lib/slingshot/model/search.rb', line 66

def index
  self.class.index
end

#scoreObject



62
63
64
# File 'lib/slingshot/model/search.rb', line 62

def score
  attributes['_score']
end

#to_indexed_jsonObject



80
81
82
83
84
85
86
87
88
89
# File 'lib/slingshot/model/search.rb', line 80

def to_indexed_json
  if self.class.mapping.empty?
    self.serializable_hash.
      to_json
  else
    self.serializable_hash.
      reject { |key, value| ! self.class.mapping.keys.map(&:to_s).include?(key.to_s) }.
      to_json
  end
end

#update_elastic_search_indexObject



70
71
72
73
74
75
76
77
78
# File 'lib/slingshot/model/search.rb', line 70

def update_elastic_search_index
  if destroyed?
    self.class.index.remove document_type, self
  else
    response  = self.class.index.store  document_type, self
    self.id ||= response['_id'] if self.respond_to?(:id=)
    self
  end
end