Indexes#

Define API Indexes.

class gcloud.search.index.Index(name, client)[source]#

Bases: object

Indexes are containers for documents.

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

Parameters:
  • name (string) – the name of the index
  • client (gcloud.dns.client.Client) – A client which holds credentials and project configuration for the index (which requires a project).
atom_fields#

Names of atom fields in the index.

Return type:list of string, or None
Returns:names of atom fields in the index, or None if no resource information is available.
date_fields#

Names of date fields in the index.

Return type:list of string, or None
Returns:names of date fields in the index, or None if no resource information is available.
document(name, rank=None)[source]#

Construct a document bound to this index.

Parameters:
  • name (string) – Name of the document.
  • rank (integer) – Rank of the document (defaults to a server-assigned value based on timestamp).
Return type:

gcloud.search.document.Document

Returns:

a new Document instance

classmethod from_api_repr(resource, client)[source]#

Factory: construct an index given its API representation

Parameters:
  • resource (dict) – index resource representation returned from the API
  • client (gcloud.dns.client.Client) – Client which holds credentials and project configuration for the index.
Return type:

gcloud.dns.index.Index

Returns:

Index parsed from resource.

geo_fields#

Names of geo fields in the index.

Return type:list of string, or None
Returns:names of geo fields in the index, or None if no resource information is available.
html_fields#

Names of html fields in the index.

Return type:list of string, or None
Returns:names of html fields in the index, or None if no resource information is available.
list_documents(max_results=None, page_token=None, view=None)[source]#

List documents created within this index.

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

Parameters:
  • max_results (int) – maximum number of indexes to return, If not passed, defaults to a value set by the API.
  • page_token (string) – opaque marker for the next “page” of indexes. If not passed, the API will return the first page of indexes.
  • view (string) – One of ‘ID_ONLY’ (return only the document ID; the default) or ‘FULL’ (return the full resource representation for the document, including field values)
Return type:

tuple, (list, str)

Returns:

list of gcloud.dns.document.Document, plus a “next page token” string: if the token is not None, indicates that more indexes can be retrieved with another call (pass that value as page_token).

number_fields#

Names of number fields in the index.

Return type:list of string, or None
Returns:names of number fields in the index, or None if no resource information is available.
path#

URL path for the index’s APIs.

Return type:string
Returns:the path based on project and dataste name.
project#

Project bound to the index.

Return type:string
Returns:the project (derived from the client).
search(query, max_results=None, page_token=None, field_expressions=None, order_by=None, matched_count_accuracy=None, scorer=None, scorer_size=None, return_fields=None)[source]#

Search documents created within this index.

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

Parameters:
  • query (string) – query string (see https://cloud.google.com/search/query).
  • max_results (int) – maximum number of indexes to return, If not passed, defaults to a value set by the API.
  • page_token (string) – opaque marker for the next “page” of indexes. If not passed, the API will return the first page of indexes.
  • field_expressions (dict, or NoneType) – mapping of field name -> expression for use in ‘order_by’ or ‘return_fields’
  • order_by (sequence of string, or NoneType) – list of field names (plus optional ‘ desc’ suffix) specifying ordering of results.
  • matched_count_accuracy (integer or NoneType) – minimum accuracy for matched count returned
  • return_fields (sequence of string, or NoneType) – list of field names to be returned.
  • scorer (string or NoneType) – name of scorer function (e.g., “generic”).
  • scorer_size (integer or NoneType) – max number of top results pass to scorer function.
Return type:

tuple, (list, str, int)

Returns:

list of gcloud.dns.document.Document, plus a “next page token” string, and a “matched count”. If the token is not None, indicates that more indexes can be retrieved with another call (pass that value as page_token). The “matched count” indicates the total number of documents matching the query string.

text_fields#

Names of text fields in the index.

Return type:list of string, or None
Returns:names of text fields in the index, or None if no resource information is available.