Stay organized with collections Save and categorize content based on your preferences.
Class Index
represents an index allowing documents to be indexed, deleted, and searched.
Index
is defined in the google.appengine.api.search
module.
put_async
, delete_async
, get_async
, search_async
, and get_range_async
. These are identical to the synchronous methods, except they all return a future. To get the actual result, call get_result()
on the returned value; that call will block. 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 failureConstructor
The constructor for class Index
is defined as follows:
Index(name, namespace=None)
Construct an instance of class Index
.
Arguments
Index name (see name property, below, for details).
For multitenant applications, the namespace in which index name is defined.
Result value
A new instance of class Index
.
An instance of class Index
has the following properties:
Schema mapping field names to the list of types supported. Valid only for indexes returned by the search.get_indexes
method.
Index name, a human-readable ASCII string identifying the index. Must contain no whitespace characters and not start with an exclamation point (!
).
Namespace in which index name is defined.
The approximate number of bytes used by this index. The number may not reflect the results of recent changes. Valid only for indexes returned by the search.get_indexes
method.
The maximum allowable storage for this index, in bytes. Valid only for indexes returned by the search.get_indexes
method.
Instances of class Index
have the following methods:
If the specified documents have already been put into the index, and if they have the same doc_ids
, they are reindexed with updated contents.
Arguments
Document (or iterable collection of documents) to index.
Deadline for RPC call in seconds.
Result value
List of results (PutResult
), one for each document requested to be indexed.
Exceptions
One or more documents failed to index, or number indexed did not match number requested.
Unknown attribute passed.
Argument not a document or iterable collection of documents, or number of documents larger than MAXIMUM_DOCUMENTS_PER_PUT_REQUEST
.
Delete documents from index.
If no document exists for an identifier in the list, that identifier is ignored.
Arguments
Identifier (or list of identifiers) of documents to delete.
Deadline for RPC call in seconds.
Exceptions
One or more documents failed to delete, or number deleted did not match number requested.
Argument not a string or iterable collection of valid document identifiers, or number of document identifiers larger than MAXIMUM_DOCUMENTS_PER_PUT_REQUEST
.
Retrieves a Document from the index using the document's identifier. If the document is not found, returns None
.
Arguments
The identifier of the document to retrieve.
Deadline for RPC call in seconds.
Result value
A Document object whose identifier matches the one supplied by doc_id.
Search the index for documents matching the query. The query may be either a string or a Query object.
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( # Define the query by using a Query object. query=Query('subject:first good', options=QueryOptions(limit=20, cursor=Cursor(), sort_options=SortOptions( expressions=[SortExpression(expression='subject', default_value='')], 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 results: # 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)) )
Arguments
The query to match against documents in the index, described in a Query object. For more information, please see the Query Language Overview.
Deadline for RPC call in seconds.
Result value
A SearchResults object containing a list of documents matched, number returned and number matched by the query.
Exceptions
A parameter has an invalid type, or an unknown attribute was passed.
A parameter has an invalid value.
Get a range of documents from an index, in doc_id
order.
Arguments
String containing the document identifier from which to list documents. By default, starts at the first document identifier.
If true
, include document specified by start_id
.
Maximum number of documents to return.
If true
, return only document identifiers instead of full documents.
Deadline for RPC call in seconds.
Result value
A GetResponse
object containing a list of the retrieved documents, ordered by document identifier.
Exceptions
Unknown attribute passed.
Some subclass of Error
occurred while processing request.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["The `Index` class allows for the management of documents within an index, including indexing, deleting, and searching."],["Asynchronous methods like `put_async`, `delete_async`, `get_async`, `search_async`, and `get_range_async` are available, returning a future object that can be used to retrieve the result via `get_result()`."],["The `Index` constructor takes the index's `name` and an optional `namespace` to create an instance, which can be used to perform methods like `put`, `delete`, `get`, `search`, and `get_range`."],["The `search` method allows querying the index using a string or a `Query` object, which can be further customized with a `QueryOptions` to control parameters like limits, cursors, and sort options."],["The properties of an `Index` object include the name, namespace, schema, storage_usage, and storage_limit, while instance methods allow to manage documents, like put a document to the index, deleting an existing one, retrieving a document by it's ID, searching for documents matching a query and retrieving a range of documents by ID."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4