![]() |
App Engine Python SDK
v1.6.9 rev.445
The Python runtime is available as an experimental Preview feature.
|
Public Member Functions | |
def | __init__ |
def | schema |
def | storage_usage |
def | storage_limit |
def | name |
def | namespace |
def | source |
def | __eq__ |
def | __ne__ |
def | __hash__ |
def | __repr__ |
def | put |
def | delete |
def | delete_schema |
def | get |
def | search |
def | get_range |
Represents an index allowing indexing, deleting and searching documents. The following code fragment shows how to add documents, then search the index for documents matching a query. # Get the index. index = Index(name='index-name') # Create a document. doc = Document(doc_id='document-id', fields=[TextField(name='subject', value='my first email'), HtmlField(name='body', value='<html>some content here</html>')]) # Index the document. try: index.put(doc) except search.Error, e: # possibly retry indexing or log error # Query the index. try: results = index.search('subject:first body:here') # Iterate through the search results. for scored_document in results: print scored_document except search.Error, e: # possibly log the failure Once an index is created with a given specification, that specification is immutable. Search results may contain some out of date documents. However, any two changes to any document stored in an index are applied in the correct order.
def google.appengine.api.search.search.Index.__init__ | ( | self, | |
name, | |||
namespace = None , |
|||
source = SEARCH |
|||
) |
Initializer. Args: name: The name of the index. An index name must be a visible printable ASCII string not starting with '!'. Whitespace characters are excluded. namespace: The namespace of the index name. If not set, then the current namespace is used. source: Deprecated as of 1.7.6. The source of the index: SEARCH - The Index was created by adding documents throught this search API. DATASTORE - The Index was created as a side-effect of putting entities into Datastore. CLOUD_STORAGE - The Index was created as a side-effect of adding objects into a Cloud Storage bucket. Raises: TypeError: If an unknown attribute is passed. ValueError: If invalid namespace is given.
def google.appengine.api.search.search.Index.delete | ( | self, | |
document_ids, | |||
deadline = None |
|||
) |
Delete the documents with the corresponding document ids from the index. If no document exists for the identifier in the list, then that document identifier is ignored. If any document delete fails, then no documents will be deleted. Args: document_ids: A single identifier or list of identifiers of documents to delete. Kwargs: deadline: Deadline for RPC call in seconds; if None use the default. Raises: DeleteError: If one or more documents failed to remove or number removed did not match requested. ValueError: If document_ids is not a string or iterable of valid document identifiers or number of document ids is larger than MAXIMUM_DOCUMENTS_PER_PUT_REQUEST or deadline is a negative number.
def google.appengine.api.search.search.Index.delete_schema | ( | self | ) |
Deprecated in 1.7.4. Delete the schema from the index. We are deprecating this method and replacing with more general schema and index managment. A possible use may be remove typed fields which are no longer used. After you delete the schema, you need to index one or more documents to rebuild the schema. Until you re-index some documents, searches may fail, especially searches using field restricts. Raises: DeleteError: If the schema failed to be deleted.
def google.appengine.api.search.search.Index.get | ( | self, | |
doc_id, | |||
deadline = None |
|||
) |
Retrieve a document by document ID. Args: doc_id: The ID of the document to retreive. Kwargs: deadline: Deadline for RPC call in seconds; if None use the default. Returns: If the document ID exists, returns the associated document. Otherwise, returns None. Raises: TypeError: If any of the parameters have invalid types, or an unknown attribute is passed. ValueError: If any of the parameters have invalid values (e.g., a negative deadline).
def google.appengine.api.search.search.Index.get_range | ( | self, | |
start_id = None , |
|||
include_start_object = True , |
|||
limit = 100 , |
|||
ids_only = False , |
|||
deadline = None , |
|||
kwargs | |||
) |
Get a range of Documents in the index, in id order. Args: start_id: String containing the Id from which to list Documents from. By default, starts at the first Id. include_start_object: If true, include the Document with the Id specified by the start_id parameter. limit: The maximum number of Documents to return. ids_only: If true, the Documents returned only contain their keys. Kwargs: deadline: Deadline for RPC call in seconds; if None use the default. Returns: A GetResponse containing a list of Documents, ordered by Id. Raises: Error: Some subclass of Error is raised if an error occurred processing the request. TypeError: If any of the parameters have invalid types, or an unknown attribute is passed. ValueError: If any of the parameters have invalid values (e.g., a negative deadline).
def google.appengine.api.search.search.Index.name | ( | self | ) |
Returns the name of the index.
def google.appengine.api.search.search.Index.namespace | ( | self | ) |
Returns the namespace of the name of the index.
def google.appengine.api.search.search.Index.put | ( | self, | |
documents, | |||
deadline = None |
|||
) |
Index the collection of documents. If any of the documents are already in the index, then reindex them with their corresponding fresh document. If any of the documents fail to be indexed, then none of the documents will be indexed. Args: documents: A Document or iterable of Documents to index. Kwargs: deadline: Deadline for RPC call in seconds; if None use the default. Returns: A list of PutResult, one per Document requested to be indexed. Raises: PutError: If one or more documents failed to index or number indexed did not match requested. TypeError: If an unknown attribute is passed. ValueError: If documents is not a Document or iterable of Document or number of the documents is larger than MAXIMUM_DOCUMENTS_PER_PUT_REQUEST or deadline is a negative number.
def google.appengine.api.search.search.Index.schema | ( | self | ) |
Returns the schema mapping field names to list of types supported. Only valid for Indexes returned by search.get_indexes method.
def google.appengine.api.search.search.Index.search | ( | self, | |
query, | |||
deadline = None , |
|||
kwargs | |||
) |
Search the index for documents matching the query. For example, the following code fragment requests a search for documents where 'first' occurs in subject and 'good' occurs anywhere, returning at most 20 documents, starting the search from 'cursor token', returning another single cursor for the response, sorting by subject in descending order, returning the author, subject, and summary fields as well as a snippeted field content. results = index.search( query=Query('subject:first good', options=QueryOptions(limit=20, cursor=Cursor(), sort_options=SortOptions( expressions=[SortExpression(expression='subject')], limit=1000), returned_fields=['author', 'subject', 'summary'], snippeted_fields=['content']))) The following code fragment shows how to use a results cursor cursor = results.cursor for result in response: # process result results = index.search( Query('subject:first good', options=QueryOptions(cursor=cursor))) The following code fragment shows how to use a per_result cursor results = index.search( query=Query('subject:first good', options=QueryOptions(limit=20, cursor=Cursor(per_result=True), ...))) cursor = None for result in results: cursor = result.cursor results = index.search( Query('subject:first good', options=QueryOptions(cursor=cursor))) Args: query: The Query to match against documents in the index. Kwargs: deadline: Deadline for RPC call in seconds; if None use the default. Returns: A SearchResults containing a list of documents matched, number returned and number matched by the query. Raises: TypeError: If any of the parameters have invalid types, or an unknown attribute is passed. ValueError: If any of the parameters have invalid values (e.g., a negative deadline).
def google.appengine.api.search.search.Index.source | ( | self | ) |
Returns the source of the index. Deprecated: from 1.7.6, source is no longer available.
def google.appengine.api.search.search.Index.storage_limit | ( | self | ) |
The maximum allowable storage for this index, in bytes. Returns None for indexes not obtained from search.get_indexes.
def google.appengine.api.search.search.Index.storage_usage | ( | self | ) |
The approximate number of bytes used by this index. The number may be slightly stale, as it may not reflect the results of recent changes. Returns None for indexes not obtained from search.get_indexes.