Class: Gcloud::Search::Document
- Inherits:
-
Object
- Object
- Gcloud::Search::Document
- Defined in:
- lib/gcloud/search/document.rb,
lib/gcloud/search/document/list.rb
Overview
Defined Under Namespace
Classes: List
Class Method Summary collapse
Instance Method Summary collapse
-
#[](name) ⇒ FieldValues
Retrieve the field values associated to a field name.
-
#add(name, value, type: nil, lang: nil) ⇒ Object
Add a new value.
-
#delete(name, &block) ⇒ Object
Deletes a field and all values.
-
#doc_id ⇒ Object
The unique identifier for the document.
-
#doc_id=(new_doc_id) ⇒ Object
Sets the unique identifier for the document.
-
#each(&block) ⇒ Object
Calls block once for each field, passing the field name and values pair as parameters.
-
#fields ⇒ Object
The fields in the document.
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #inspect ⇒ Object
-
#names ⇒ Object
Returns a new array populated with all the field names.
-
#rank ⇒ Object
A positive integer which determines the default ordering of documents returned from a search.
-
#rank=(new_rank) ⇒ Object
Sets the rank of the document.
- #to_hash ⇒ Object
Constructor Details
Class Method Details
Instance Method Details
#[](name) ⇒ FieldValues
Retrieve the field values associated to a field name.
121 122 123 |
# File 'lib/gcloud/search/document.rb', line 121 def [] name @fields[name] end |
#add(name, value, type: nil, lang: nil) ⇒ Object
Add a new value. If the field name does not exist it will be added. If the field value is a DateTime or Numeric, or the type is set to ‘:datetime` or `:number`, then the added value will replace any existing values of the same type (since there can be only one).
182 183 184 |
# File 'lib/gcloud/search/document.rb', line 182 def add name, value, type: nil, lang: nil @fields[name].add value, type: type, lang: lang end |
#delete(name, &block) ⇒ Object
Deletes a field and all values. (See Fields#delete)
201 202 203 |
# File 'lib/gcloud/search/document.rb', line 201 def delete name, &block @fields.delete name, &block end |
#doc_id ⇒ Object
The unique identifier for the document. Can be set explicitly when the document is saved. (See Index#document and #doc_id=.) If missing, it is automatically assigned to the document when saved.
62 63 64 |
# File 'lib/gcloud/search/document.rb', line 62 def doc_id @raw["docId"] end |
#doc_id=(new_doc_id) ⇒ Object
Sets the unique identifier for the document.
Must contain only visible, printable ASCII characters (ASCII codes 33 through 126 inclusive) and be no longer than 500 characters. It cannot begin with an exclamation point (!), and it cannot begin and end with double underscores (__).
73 74 75 |
# File 'lib/gcloud/search/document.rb', line 73 def doc_id= new_doc_id @raw["docId"] = new_doc_id end |
#each(&block) ⇒ Object
Calls block once for each field, passing the field name and values pair as parameters. If no block is given an enumerator is returned instead. (See Fields#each)
226 227 228 |
# File 'lib/gcloud/search/document.rb', line 226 def each &block @fields.each(&block) end |
#fields ⇒ Object
The fields in the document. Each field has a name (String) and a list of values (FieldValues). (See Fields)
130 131 132 |
# File 'lib/gcloud/search/document.rb', line 130 def fields @fields end |
#inspect ⇒ Object
253 254 255 256 257 258 |
# File 'lib/gcloud/search/document.rb', line 253 def inspect insp_rank = "" insp_rank = ", rank: #{rank}" if rank insp_fields = ", fields: (#{fields.names.map(&:inspect).join ', '})" "#{self.class}(doc_id: #{doc_id.inspect}#{insp_rank}#{insp_fields})" end |
#names ⇒ Object
Returns a new array populated with all the field names. (See Fields#names)
247 248 249 |
# File 'lib/gcloud/search/document.rb', line 247 def names @fields.names end |
#rank ⇒ Object
A positive integer which determines the default ordering of documents returned from a search. The rank can be set explicitly when the document is saved. (See Index#document and #rank=.) If missing, it is automatically assigned to the document when saved.
83 84 85 |
# File 'lib/gcloud/search/document.rb', line 83 def rank @raw["rank"] end |
#rank=(new_rank) ⇒ Object
Sets the rank of the document.
The same rank should not be assigned to many documents, and should never be assigned to more than 10,000 documents. By default (when it is not specified or set to 0), it is set at the time the document is created to the number of seconds since January 1, 2011. The rank can be used in Index#search options ‘expressions`, `order`, and `fields`, where it is referenced as `rank`.
96 97 98 |
# File 'lib/gcloud/search/document.rb', line 96 def rank= new_rank @raw["rank"] = new_rank end |
#to_hash ⇒ Object
271 272 273 274 275 |
# File 'lib/gcloud/search/document.rb', line 271 def to_hash hash = @raw.dup hash["fields"] = @fields.to_raw hash end |