class SearchEnjoy::SearchIndex
Public Class Methods
new(*several_variants, index_schema: nil)
click to toggle source
Calls superclass method
# File lib/search_enjoy/search_index.rb, line 3 def initialize(*several_variants, index_schema: nil) super @index_schema = index_schema end
Public Instance Methods
load_json(json)
click to toggle source
# File lib/search_enjoy/search_index.rb, line 28 def load_json(json) hash = JSON.parse(json) hash.each_pair do |id, object| indexed_object = @index_schema.call(object) self[id] = indexed_object end rescue StandardError => e e.message end
to_json()
click to toggle source
# File lib/search_enjoy/search_index.rb, line 10 def to_json hash = {} each_pair do |id, object| object_hash = {} @index_schema.key_map.each do |key| object_hash[key.name.to_sym] = object[key.name.to_sym] end hash[id] = object_hash end JSON.generate(hash) rescue StandardError => e e.message end