Configuring Expressions in Amazon CloudSearch (original) (raw)

You can define numeric expressions and use them to sort search results. Expressions can also be returned in search results. You can add expressions to the domain configuration or define expressions within search requests.

Topics

Writing Expressions for Amazon CloudSearch

Amazon CloudSearch expressions can contain:

JavaScript order of precedence rules apply for operators. You can override operator precedence by using parentheses.

Shortcut evaluation is used when evaluating logical expressions—if the value of the expression can be determined after evaluating the first argument, the second argument is not evaluated. For example, in the expression a || b, b is only evaluated if a is not true.

Expressions always return an integer value from 0 to the maximum 64-bit signed integer value (2^63 - 1). Intermediate results are calculated as double-precision floating point values and the return value is rounded to the nearest integer. If the expression is invalid or evaluates to a negative value, it returns 0. If the expression evaluates to a value greater than the maximum, it returns the maximum value.

Expression names must begin with a letter and be at least 3 and no more than 64 characters long. The following characters are allowed: a-z (lower-case letters), 0-9, and _ (underscore). The name score is reserved and cannot be used as an expression name.

For example, if you define an int field named popularity for your domain, you could use that field in conjunction with the default relevance _score to construct a custom expression.

(0.3*popularity)+(0.7*_score)

Note that this simple example assumes that the popularity ranking and the relevance _score values are in about the same range. To tune your expressions for ranking results, you need to do some testing to determine how to weight the components of your expressions to get the results you want.

Using Date Fields in Amazon CloudSearch Expressions

The value from a date field is stored as an epoch time with millisecond resolution. This means you can use the mathematical and comparison operators to construct expressions using dates stored in your documents and the current epoch time (_time). For example, using the following expression to sort search results from the movies domain pushes movies with recent release dates toward the top of the list.

_score/(_time - release_date)