Class: Redis::Commands::Search::Document
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/redis/commands/modules/search/result.rb |
Overview
Class Method Summary
Instance Attribute Summary
- #attributes ⇒ String, ... readonly
- #id ⇒ String, ... readonly
- #payload ⇒ String, ... readonly
- #score ⇒ String, ... readonly
Instance Method Summary
- #==(other) ⇒ Boolean (also: #eql?)
-
#[](key) ⇒ Object?
Look up a returned field by name.
-
#eql?(other)
Alias for #==.
- #hash ⇒ Integer
- #key?(key) ⇒ Boolean
-
#to_h ⇒ Hash{String => Object}
The document id plus its returned fields, as a flat hash.
Constructor Details
.new(id, attributes: {}, score: nil, payload: nil) ⇒ Document
# File 'lib/redis/commands/modules/search/result.rb', line 24
def initialize(id, attributes: {}, score: nil, payload: nil) @id = id @attributes = attributes @score = score @payload = payload end
Instance Attribute Details
#attributes ⇒ String, ... (readonly)
#id ⇒ String, ... (readonly)
# File 'lib/redis/commands/modules/search/result.rb', line 18
attr_reader :id, :score, :payload, :attributes
#payload ⇒ String, ... (readonly)
# File 'lib/redis/commands/modules/search/result.rb', line 18
attr_reader :id, :score, :payload, :attributes
#score ⇒ String, ... (readonly)
# File 'lib/redis/commands/modules/search/result.rb', line 18
attr_reader :id, :score, :payload, :attributes
Instance Method Details
#==(other) ⇒ Boolean
Also known as: #eql?
# File 'lib/redis/commands/modules/search/result.rb', line 54
def ==(other) other.is_a?(Document) && id == other.id && attributes == other.attributes && score == other.score && payload == other.payload end
#[](key) ⇒ Object?
Look up a returned field by name.
# File 'lib/redis/commands/modules/search/result.rb', line 35
def [](key) @attributes[key.to_s] end
#eql?(other)
Alias for #==.
# File 'lib/redis/commands/modules/search/result.rb', line 61
alias eql? ==
#hash ⇒ Integer
# File 'lib/redis/commands/modules/search/result.rb', line 64
def hash [id, attributes, score, payload].hash end
#key?(key) ⇒ Boolean
# File 'lib/redis/commands/modules/search/result.rb', line 41
def key?(key) @attributes.key?(key.to_s) end
#to_h ⇒ Hash{String => Object}
The document id plus its returned fields, as a flat hash.
# File 'lib/redis/commands/modules/search/result.rb', line 48
def to_h @attributes.merge("id" => @id) end