Documents#

Define API Document.

class gcloud.search.document.Document(name, index, rank=None)[source]#

Bases: object

Documents hold values for search within indexes.

See: https://cloud.google.com/search/reference/rest/v1/projects/indexes/documents

Parameters:
  • name (string) – the name of the document
  • index (gcloud.search.index.Index) – the index to which the document belongs.
  • rank (positive integer) – override the server-generated rank for ordering the document within in queries. If not passed, the server generates a timestamp-based value. See the rank entry on the page above for details.
create(client=None)[source]#

API call: create the document via a PUT request

See: https://cloud.google.com/search/reference/rest/v1/projects/indexes/documents/create

Parameters:client (gcloud.search.client.Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current document’s index.
delete(client=None)[source]#

API call: delete the document via a DELETE request.

See: https://cloud.google.com/search/reference/rest/v1/projects/indexes/documents/delete

Parameters:client (gcloud.search.client.Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current document’s index.
exists(client=None)[source]#

API call: test existence of the document via a GET request

See https://cloud.google.com/search/reference/rest/v1/projects/indexes/documents/get

Parameters:client (gcloud.search.client.Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current document’s index.
field(name)[source]#

Construct a Field instance.

Parameters:name (string) – field’s name
classmethod from_api_repr(resource, index)[source]#

Factory: construct a document given its API representation

Parameters:
Return type:

gcloud.search.document.Document

Returns:

Document parsed from resource.

path#

URL path for the document’s APIs

reload(client=None)[source]#

API call: sync local document configuration via a GET request

See https://cloud.google.com/search/reference/rest/v1/projects/indexes/documents/get

Parameters:client (gcloud.search.client.Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current document’s index.
class gcloud.search.document.Field(name)[source]#

Bases: object

Fields hold values for a given document

See: https://cloud.google.com/search/reference/rest/google/cloudsearch/v1/FieldValueList

Parameters:name (string) – field name
add_value(value, **kw)[source]#

Add a value to the field.

Selects type of value instance based on type of value.

Parameters:
  • value (string, integer, float, datetime, or tuple (float, float)) – the field value to add.
  • kw – extra keyword arguments to be passed to the value instance constructor. Currently, only StringValue expects / honors additional parameters.
Raises:

ValueError if unable to match the type of value.

class gcloud.search.document.GeoValue(geo_value)[source]#

Bases: object

GeoValues hold individual latitude/longitude values for a given field See: https://cloud.google.com/search/reference/rest/google/cloudsearch/v1/FieldValue

Parameters:geo_value (tuple, (float, float)) – latitude, longitude
value_type = 'geo'#
class gcloud.search.document.NumberValue(number_value)[source]#

Bases: object

NumberValues hold individual numeric values for a given field

See: https://cloud.google.com/search/reference/rest/google/cloudsearch/v1/FieldValue

Parameters:number_value (integer, float (long on Python2)) – the actual value.
value_type = 'number'#
class gcloud.search.document.StringValue(string_value, string_format=None, language=None)[source]#

Bases: object

StringValues hold individual text values for a given field

See: https://cloud.google.com/search/reference/rest/google/cloudsearch/v1/FieldValue

Parameters:
  • string_value (string) – the actual value.
  • string_format (string) – how the value should be indexed: one of ‘ATOM’, ‘TEXT’, ‘HTML’ (leave as None to use the server-supplied default).
  • language (string) – Human language of the text. Should be an ISO 639-1 language code.
value_type = 'string'#
class gcloud.search.document.TimestampValue(timestamp_value)[source]#

Bases: object

TimestampValues hold individual datetime values for a given field See: https://cloud.google.com/search/reference/rest/google/cloudsearch/v1/FieldValue

Parameters:timestamp_value (class:datetime.datetime) – the actual value.
value_type = 'timestamp'#