Class: Redis::Commands::Search::Document
- Inherits:
-
Object
- Object
- Redis::Commands::Search::Document
- Defined in:
- lib/redis/commands/modules/search/result.rb
Overview
A single document returned by FT.SEARCH.
Behaves like a read-only hash over the document's returned fields, while also
exposing the document id and, when requested, its score and payload.
Instance Attribute Summary collapse
- #attributes ⇒ String, ... readonly
- #id ⇒ String, ... readonly
- #payload ⇒ String, ... readonly
- #score ⇒ String, ... readonly
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Whether
otheris a Document with equal id, attributes, score and payload. -
#[](key) ⇒ Object?
Look up a returned field by name.
-
#hash ⇒ Integer
A hash derived from id, attributes, score and payload.
-
#initialize(id, attributes: {}, score: nil, payload: nil) ⇒ Document
constructor
A new instance of Document.
-
#key?(key) ⇒ Boolean
Whether the document has the given field.
-
#to_h ⇒ Hash{String => Object}
The document id plus its returned fields, as a flat hash.
Constructor Details
#initialize(id, attributes: {}, score: nil, payload: nil) ⇒ Document
Returns a new instance of Document.
24 25 26 27 28 29 |
# 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)
18 19 20 |
# File 'lib/redis/commands/modules/search/result.rb', line 18 def attributes @attributes end |
#id ⇒ String, ... (readonly)
18 19 20 |
# File 'lib/redis/commands/modules/search/result.rb', line 18 def id @id end |
#payload ⇒ String, ... (readonly)
18 19 20 |
# File 'lib/redis/commands/modules/search/result.rb', line 18 def payload @payload end |
#score ⇒ String, ... (readonly)
18 19 20 |
# File 'lib/redis/commands/modules/search/result.rb', line 18 def score @score end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns whether other is a Document with equal id, attributes, score and payload.
54 55 56 57 58 59 60 |
# 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.
35 36 37 |
# File 'lib/redis/commands/modules/search/result.rb', line 35 def [](key) @attributes[key.to_s] end |
#hash ⇒ Integer
Returns a hash derived from id, attributes, score and payload.
64 65 66 |
# File 'lib/redis/commands/modules/search/result.rb', line 64 def hash [id, attributes, score, payload].hash end |
#key?(key) ⇒ Boolean
Returns whether the document has the given field.
41 42 43 |
# 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.
48 49 50 |
# File 'lib/redis/commands/modules/search/result.rb', line 48 def to_h @attributes.merge("id" => @id) end |