Class
Index
represents an index allowing documents to be indexed, deleted, and searched.
Index
is defined in the
google.appengine.api.search
module.
- Introduction
- Constructor
- Properties:
- Instance methods:
Introduction
The
Index
class provides arguments to construct an index as well as functions allowing you to add, list, search, and delete
documents
(or an iterable collection of documents) within the index. You construct an index using arguments to the
Index
class, including the name and namespace of the index.
The following code shows how to put documents into an index, then search it for documents matching a query:
# Get the index. index = search.Index(name='index-name') # Create a document. doc = search.Document( doc_id='document-id', fields=[search.TextField(name='subject', value='my first email'), search.HtmlField(name='body', value='<html>some content here</html>')]) # Index the document. try: index.put(doc) except search.PutError, e: result = e.results[0] if result.code == search.OperationResult.TRANSIENT_ERROR: # possibly retry indexing result.object_id except search.Error, e: # possibly log the failure # Query the index. try: results = index.search('subject:first body:here') # Iterate through the search results. for scored_document in results: # process the scored_document except search.Error, e: # possibly log the failure
Constructor
The constructor for class
Index
is defined as follows:
-
Index ( name , namespace = None )
-
Construct an instance of class
Index
. -
Arguments
- name
-
Index name (see name property , below, for details).
- namespace
-
For multitenant applications , the namespace in which index name is defined.
Result value
-
A new instance of class
Index
.