define_rank_expression ( $domain_name, $rank_expression, $opt )

Configures a RankExpression for the search domain. Used to create new rank expressions and modify existing ones. If the expression exists, the new configuration replaces the old one. You can configure a maximum of 50 rank expressions.

Access

public

Parameters

Parameter

Type

Required

Description

$domain_name

string

Required

A string that represents the name of a domain. Domain names must be unique across the domains owned by an account within an AWS region. Domain names must start with a letter or number and can contain the following characters: a-z (lowercase), 0-9, and - (hyphen). Uppercase letters and underscores are not allowed. [Constraints: The value must be between 3 and 28 characters, and must match the following regular expression pattern: [a-z][a-z0-9-]+]

$rank_expression

array

Required

A named expression that can be evaluated at search time and used for ranking or thresholding in a search query.

  • x - array - Optional - This represents a simple array index.
    • RankName - string - Required - The name of a rank expression. Rank expression names must begin with a letter and can contain the following characters: a-z (lowercase), 0-9, and _ (underscore). Uppercase letters and hyphens are not allowed. The names “body”, “docid”, and “text_relevance” are reserved and cannot be specified as field or rank expression names. [Constraints: The value must be between 1 and 64 characters, and must match the following regular expression pattern: [a-z][a-z0-9_]*]
    • RankExpression - string - Required - The expression to evaluate for ranking or thresholding while processing a search request. The RankExpression syntax is based on JavaScript expressions and supports:
      • Integer, floating point, hex and octal literals
      • Shortcut evaluation of logical operators such that an expression a || b evaluates to the value a if a is true without evaluting b at all
      • JavaScript order of precendence for operators
      • Arithmetic operators: + - / %
      • Boolean operators (including the ternary operator)
      • Bitwise operators
      • Comparison operators
      • Common mathematic functions: abs ceil erf exp floor lgamma ln log2 log10 max min sqrt pow
      • Trigonometric library functions: acosh acos asinh asin atanh atan cosh cos sinh sin tanh tan
      • Random generation of a number between 0 and 1: rand
      • Current time in epoch: time
      • The min max functions that operate on a variable argument list
      Intermediate results are calculated as double precision floating point values. The final return value of a RankExpression is automatically converted from floating point to a 32-bit unsigned integer by rounding to the nearest integer, with a natural floor of 0 and a ceiling of max(uint32_t), 4294967295. Mathematical errors such as dividing by 0 will fail during evaluation and return a value of 0. The source data for a RankExpression can be the name of an IndexField of type uint, another RankExpression or the reserved name text_relevance. The text_relevance source is defined to return an integer from 0 to 1000 (inclusive) to indicate how relevant a document is to the search request, taking into account repetition of search terms in the document and proximity of search terms to each other in each matching IndexField in the document. For more information about using rank expressions to customize ranking, see the Amazon CloudSearch Developer Guide.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

Create and delete a rank expression.

// Instantiate the class
$search = new AmazonCloudSearch();

$domain_name = 'my-domain';
$rank_expression = 'test_expression';

/*%**************************************************************%*/
// Create a new CloudSearch domain

echo '# Creating a new CloudSearch domain' . PHP_EOL;
$response = $search->create_domain($domain_name);

// Check for success...
if ($response->isOK())
{
	echo 'Kicked off the creation of the CloudSearch domain...' . PHP_EOL;
}
else
{
	print_r($response);
}

echo PHP_EOL;

/*%**************************************************************%*/
// Define rank expressions

echo '# Defining a new CloudSearch rank expression' . PHP_EOL;
$response = $search->define_rank_expression($domain_name, array(
	'RankName' => $rank_expression,
	'RankExpression' => '(0.7*text_relevance)',
));

// Check for success...
if ($response->isOK())
{
	echo 'Defined a rank expression...' . PHP_EOL;
}
else
{
	print_r($response);
}

echo PHP_EOL;

/*%**************************************************************%*/
// Describe rank expressions

echo "# Describing the CloudSearch rank expressions, \"${domain_name}\"" . PHP_EOL;
$response = $search->describe_rank_expressions($domain_name);

print_r($response->body->RankName()->map_string());

echo PHP_EOL;

/*%**************************************************************%*/
// Delete rank expressions

echo '# Deleting the CloudSearch rank expression...' . PHP_EOL;
$response = $search->delete_rank_expression($domain_name, $rank_expression);

// Check for success...
if ($response->isOK())
{
	echo 'CloudSearch rank expression was deleted successfully.' . PHP_EOL;
}
else
{
	print_r($response);
}

echo PHP_EOL;

/*%**************************************************************%*/
// Delete the CloudSearch domain

echo '# Deleting the CloudSearch domain...' . PHP_EOL;
$response = $search->delete_domain($domain_name);

// Check for success...
if ($response->isOK())
{
	echo 'CloudSearch domain was deleted successfully.' . PHP_EOL;
}
else
{
	print_r($response);
}

Source

Method defined in services/cloudsearch.class.php | Toggle source view (12 lines) | View on GitHub

public function define_rank_expression($domain_name, $rank_expression, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['DomainName'] = $domain_name;
    
    // Required map (non-list)
    $opt = array_merge($opt, CFComplexType::map(array(
        'RankExpression' => (is_array($rank_expression) ? $rank_expression : array($rank_expression))
    ), 'member'));

    return $this->authenticate('DefineRankExpression', $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback