Class: Zvec::Doc

Inherits:
Object
  • Object
show all
Defined in:
lib/zvec/doc.rb

Instance Method Summary collapse

Instance Method Details

#to_h(schema) ⇒ Object

Convert doc fields to a Ruby Hash. The schema parameter is required because the C++ layer stores fields as type-erased values — the FieldSchema's data_type selects the correct deserialization path (get_field dispatches on it).



8
9
10
11
12
13
14
15
16
17
# File 'lib/zvec/doc.rb', line 8

def to_h(schema)
  result = {"pk" => pk, "score" => score}
  field_names.each do |name|
    fs = schema.get_field(name)
    next unless fs

    result[name] = get_field(name, fs.data_type)
  end
  result
end