define_index_field ( $domain_name, $index_field, $opt )

Configures an IndexField for the search domain. Used to create new fields and modify existing ones. If the field exists, the new configuration replaces the old one. You can configure a maximum of 200 index fields.

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-]+]

$index_field

array

Required

Defines a field in the index, including its name, type, and the source of its data. The IndexFieldType indicates which of the options will be present. It is invalid to specify options for a type other than the IndexFieldType.

  • x - array - Optional - This represents a simple array index.
    • IndexFieldName - string - Required - The name of a field in the search index. Field 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_]*]
    • IndexFieldType - string - Required - The type of field. Based on this type, exactly one of the UIntOptions, LiteralOptions or TextOptions must be present. [Allowed values: uint, literal, text]
    • UIntOptions - array - Optional - Options for an unsigned integer field. Present if IndexFieldType specifies the field is of type unsigned integer.
      • x - array - Optional - This represents a simple array index.
        • DefaultValue - integer - Optional - The default value for an unsigned integer field.
    • LiteralOptions - array - Optional - Options for literal field. Present if IndexFieldType specifies the field is of type literal.
      • x - array - Optional - This represents a simple array index.
        • DefaultValue - string - Optional - The default value for a literal field.
        • SearchEnabled - boolean - Optional - Specifies whether search is enabled for this field.
        • FacetEnabled - boolean - Optional - Specifies whether facets are enabled for this field.
        • ResultEnabled - boolean - Optional - Specifies whether values of this field can be returned in search results and used for ranking.
    • TextOptions - array - Optional - Options for text field. Present if IndexFieldType specifies the field is of type text.
      • x - array - Optional - This represents a simple array index.
        • DefaultValue - string - Optional - The default value for a text field.
        • FacetEnabled - boolean - Optional - Specifies whether facets are enabled for this field.
        • ResultEnabled - boolean - Optional - Specifies whether values of this field can be returned in search results and used for ranking.
    • SourceAttributes - array - Optional - An optional list of source attributes that provide data for this index field. If not specified, the data is pulled from a source attribute with the same name as this IndexField. When one or more source attributes are specified, an optional data transformation can be applied to the source data when populating the index field. You can configure a maximum of 20 sources for an IndexField.
      • x - array - Optional - This represents a simple array index.
        • SourceDataFunction - string - Required - Identifies the transformation to apply when copying data from a source attribute. [Allowed values: Copy, TrimTitle, Map]
        • SourceDataCopy - array - Optional - Copies data from a source document attribute to an IndexField.
          • x - array - Optional - This represents a simple array index.
            • SourceName - string - Required - The name of the document source field to add to this IndexField. [Constraints: The value must be between 1 and 64 characters, and must match the following regular expression pattern: [a-z][a-z0-9_]*]
            • DefaultValue - string - Optional - The value of a field or source document attribute.
        • SourceDataTrimTitle - array - Optional - Trims common title words from a source document attribute when populating an IndexField. This can be used to create an IndexField you can use for sorting.
          • x - array - Optional - This represents a simple array index.
            • SourceName - string - Required - The name of the document source field to add to this IndexField. [Constraints: The value must be between 1 and 64 characters, and must match the following regular expression pattern: [a-z][a-z0-9_]*]
            • DefaultValue - string - Optional - The value of a field or source document attribute.
            • Separator - string - Optional - The separator that follows the text to trim.
            • Language - string - Optional - An IETF RFC 4646 language code. Only the primary language is considered. English (en) is currently the only supported language. [Constraints: The value must match the following regular expression pattern: [a-zA-Z]{2,8}(?:-[a-zA-Z]{2,8})*]
        • SourceDataMap - array - Optional - Maps source document attribute values to new values when populating the IndexField.
          • x - array - Optional - This represents a simple array index.
            • SourceName - string - Required - The name of the document source field to add to this IndexField. [Constraints: The value must be between 1 and 64 characters, and must match the following regular expression pattern: [a-z][a-z0-9_]*]
            • DefaultValue - string - Optional - The value of a field or source document attribute.
            • Cases - array - Optional - A map that translates source field values to custom values.
              • x - array - Optional - This represents a simple array index.
                • [custom-key] - string - Optional - The value of a field or source document attribute.

$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 an index field.

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

$domain_name = 'my-domain';
$index_field = 'test_integer';

/*%**************************************************************%*/
// 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 index fields

echo '# Defining a new CloudSearch index field' . PHP_EOL;
$response = $search->define_index_field($domain_name, array(
	'IndexFieldName' => $index_field,
	'IndexFieldType' => 'uint',
));

// Check for success...
if ($response->isOK())
{
	echo 'Defined an index field...' . PHP_EOL;
}
else
{
	print_r($response);
}

echo PHP_EOL;

/*%**************************************************************%*/
// Describe index fields

echo "# Describing the CloudSearch index fields, \"${domain_name}\"" . PHP_EOL;
$response = $search->describe_index_fields($domain_name);

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

echo PHP_EOL;

/*%**************************************************************%*/
// Index documents

echo "# Indexing documents, \"${domain_name}\"" . PHP_EOL;
$response = $search->index_documents($domain_name);

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

echo PHP_EOL;

/*%**************************************************************%*/
// Delete index fields

echo '# Deleting the CloudSearch index field...' . PHP_EOL;
$response = $search->delete_index_field($domain_name, $index_field);

// Check for success...
if ($response->isOK())
{
	echo 'CloudSearch index field 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_index_field($domain_name, $index_field, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['DomainName'] = $domain_name;
    
    // Required map (non-list)
    $opt = array_merge($opt, CFComplexType::map(array(
        'IndexField' => (is_array($index_field) ? $index_field : array($index_field))
    ), 'member'));

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

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback