class SearchApiDenormalizedEntityField in Search API Grouping 7.2
Processor to configure and handle the denormalization per index.
Hierarchy
- class \SearchApiAbstractProcessor implements SearchApiProcessorInterface
Expanded class hierarchy of SearchApiDenormalizedEntityField
1 string reference to 'SearchApiDenormalizedEntityField'
File
- includes/
processor_denormalize_field.inc, line 11 - Processor for configuring the denormalization per index.
View source
class SearchApiDenormalizedEntityField extends SearchApiAbstractProcessor {
/**
* Check if this index is supported.
*/
public function supportsIndex(SearchApiIndex $index) {
return $index
->datasource() instanceof SearchApiDenormalizedEntityDataSourceController;
}
/**
* Return the settings form for this processor.
*/
public function configurationForm() {
$form = parent::configurationForm();
$form['permutation_limit'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#title' => t('Permutation limits'),
'#description' => t('Defines how man permutations should be processed. Can become handy if you just want to have one item of a muti-value field. Leave empty for no limit.'),
'#weight' => 1,
);
$entity_type = $this->index
->datasource()
->getEntityType();
$entity_info = entity_get_info($this->index
->datasource()
->getEntityType());
$bundle_infos = field_info_instances($this->index
->datasource()
->getEntityType());
$options = array();
foreach ($form['fields']['#options'] as $field_name => $label) {
if (stristr($field_name, ':')) {
list($field_name, $property) = explode(':', $field_name, 2);
}
if ($field_info = field_info_field($field_name)) {
$instance = field_read_instance($entity_type, $field_name, reset($field_info['bundles'][$entity_type]));
if (!empty($field_info['cardinality']) && ($field_info['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $field_info['cardinality'] > 1)) {
$options[$field_name] = $instance['label'] . ' (' . $field_name . ')';
$form['permutation_limit'][$field_name] = array(
'#type' => 'textfield',
'#title' => $instance['label'] . ' (' . $field_name . ')',
'#size' => 4,
'#maxlength' => 10,
'#states' => array(
'visible' => array(
':input[name$="[denormalization_field][' . $field_name . ']"]' => array(
'checked' => TRUE,
),
),
),
'#default_value' => !empty($this->options['permutation_limit'][$field_name]) ? $this->options['permutation_limit'][$field_name] : NULL,
);
}
}
}
$form['fields']['#options'] = $options;
// Re-use but modify the default form element.
$form['fields']['#type'] = 'checkboxes';
unset($form['fields']['#attributes']);
$form['denormalization_field'] = $form['fields'];
$form['fields']['#access'] = FALSE;
$form['denormalization_field'] = array(
'#title' => t('The field to use to denormalize the items to index.'),
'#description' => t('The field hast to be selected for indexing to use it for denormalization.'),
'#default_value' => isset($this->options['denormalization_field']) ? $this->options['denormalization_field'] : NULL,
) + $form['denormalization_field'];
return $form;
}
/**
* Returns the fields to denormalize on.
*
* @return array
* Associative list of fields to use for denormalization. The value in the
* array defines the permutation limit. 0 means no limit.
*/
public function getDenormalizationFields() {
$fields =& drupal_static(__FUNCTION__, array());
if (empty($fields)) {
$fields = array_filter($this->options['denormalization_field']);
foreach ($fields as $field_name => $field) {
$fields[$field_name] = 0;
if (!empty($this->options['permutation_limit'][$field]) && is_numeric($this->options['permutation_limit'][$field])) {
$fields[$field_name] = (int) $this->options['permutation_limit'][$field];
}
}
}
return $fields;
}
/**
* Returns the permutation limit of a field.
*
* @param string $field
* The field to get the limit for.
*
* @return int
* The number of permutations to generate from this field. 0 means no limit.
*/
public function getDenormalizationFieldLimit($field) {
if (!empty($this->options['permutation_limit'][$field]) && is_numeric($this->options['permutation_limit'][$field])) {
return (int) $this->options['permutation_limit'][$field];
}
return 0;
}
/**
* Denormalizes items on behalf of multivalue fields.
*/
public function preprocessIndexItems(array &$items) {
// Run default pre-processing first.
parent::preprocessIndexItems($items);
// Reduce item data to its denormalized data set.
foreach ($items as $item_id => $item) {
$items[$item_id] = $this
->createDocument($item, $item_id);
}
// Ensure obsolete permutations are removed from index.
$this->index
->datasource()
->removeObsoletePermutationsFromIndex($items, $this->index);
}
/**
* Create a denormalized item for indexing.
*
* @param array $item
* The item to index.
* @param string $item_id
* The item id of the item to index.
*
* @return array
* Denormalized item to index.
*/
protected function createDocument($item, $item_id) {
$fields = $this
->getDenormalizationFields();
$parts = explode(SEARCH_API_GROUPING_ENTITY_FIELD_SEPERATOR, $item_id);
// Unshift non delta values to ensure the $fields_index matches.
$entity_type = array_shift($parts);
$entity_id = array_shift($parts);
$fields_index = array_flip(array_keys($fields));
foreach ($item as $index => $data) {
list($key) = explode(':', $index, 2);
if (isset($fields[$key]) && !empty($data['value'])) {
$item[$index]['value'] = array_intersect_key($data['value'], array(
$parts[$fields_index[$key]] => $parts[$fields_index[$key]],
));
}
}
return $item;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SearchApiAbstractProcessor:: |
protected | property | ||
SearchApiAbstractProcessor:: |
protected | property | ||
SearchApiAbstractProcessor:: |
public | function |
Submit callback for the form returned by configurationForm(). Overrides SearchApiProcessorInterface:: |
|
SearchApiAbstractProcessor:: |
public | function |
Validation callback for the form returned by configurationForm(). Overrides SearchApiProcessorInterface:: |
4 |
SearchApiAbstractProcessor:: |
protected | function | Internal helper function for imploding tokens into a single string. | |
SearchApiAbstractProcessor:: |
protected | function | Internal helper function for normalizing tokens. | |
SearchApiAbstractProcessor:: |
public | function |
Does nothing. Overrides SearchApiProcessorInterface:: |
2 |
SearchApiAbstractProcessor:: |
public | function |
Calls processKeys() for the keys and processFilters() for the filters. Overrides SearchApiProcessorInterface:: |
1 |
SearchApiAbstractProcessor:: |
protected | function | Function that is ultimately called for all text by the standard implementation, and does nothing by default. | 5 |
SearchApiAbstractProcessor:: |
protected | function | Method for preprocessing field data. | |
SearchApiAbstractProcessor:: |
protected | function | Called for processing a single text element in a field. The default implementation just calls process(). | 2 |
SearchApiAbstractProcessor:: |
protected | function | Method for preprocessing query filters. | |
SearchApiAbstractProcessor:: |
protected | function | Called for processing a single filter value. The default implementation just calls process(). | |
SearchApiAbstractProcessor:: |
protected | function | Called for processing a single search keyword. The default implementation just calls process(). | |
SearchApiAbstractProcessor:: |
protected | function | Method for preprocessing search keys. | |
SearchApiAbstractProcessor:: |
protected | function | Determines whether to process data from the given field. | |
SearchApiAbstractProcessor:: |
protected | function | Determines whether fields of the given type should normally be processed. | |
SearchApiAbstractProcessor:: |
public | function |
Constructor, saving its arguments into properties. Overrides SearchApiProcessorInterface:: |
2 |
SearchApiDenormalizedEntityField:: |
public | function |
Return the settings form for this processor. Overrides SearchApiAbstractProcessor:: |
|
SearchApiDenormalizedEntityField:: |
protected | function | Create a denormalized item for indexing. | |
SearchApiDenormalizedEntityField:: |
public | function | Returns the permutation limit of a field. | |
SearchApiDenormalizedEntityField:: |
public | function | Returns the fields to denormalize on. | |
SearchApiDenormalizedEntityField:: |
public | function |
Denormalizes items on behalf of multivalue fields. Overrides SearchApiAbstractProcessor:: |
|
SearchApiDenormalizedEntityField:: |
public | function |
Check if this index is supported. Overrides SearchApiAbstractProcessor:: |