Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products. If you have feedback or questions as you navigate the site, click Send Feedback.

Python 2 is no longer supported by the community. We recommend that you migrate Python 2 apps to Python 3.

The FieldExpression Class

Stay organized with collections Save and categorize content based on your preferences.

Class FieldExpression allows you to compute customized content snippets for each result returned by a search.

Caution: **This solution is no longer recommended:** Apps that use this API can only run in the Python 2 runtime and will need to upgrade to a [recommended solution](/appengine/docs/legacy/standard/python/migrate-to-python3/migrating-services#migration_paths_for_bundled_services) before migrating to the Python 3 runtime.

FieldExpression is defined in the module google.appengine.api.search.

Constructor

The constructor for class FieldExpression is defined as follows:

class FieldExpression(name, expression)

Construct an instance of class FieldExpression.

For example,

FieldExpression(name='content_snippet',
                expression='snippet("very important", content)')

constructs a field expression that returns a computed field named content-snippet with each search result, containing HTML snippets of the content field that match the query "very important".

Arguments

name

Name of computed field.

expression

Expression to evaluate and return.

Result value

A new instance of class FieldExpression.

Exceptions

TypeError

A parameter has an invalid type, or an unknown attribute was passed.

ValueError

A parameter has an invalid value.

Properties

An instance of class FieldExpression has the following properties:

name

Name of computed field.

expression

String containing expression to evaluate and return.