class SearchApiGroupingMultivalueField in Search API Grouping 7
Processor for splitting up items on behalf of a multivalue field.
Hierarchy
- class \SearchApiAbstractProcessor implements SearchApiProcessorInterface
Expanded class hierarchy of SearchApiGroupingMultivalueField
1 string reference to 'SearchApiGroupingMultivalueField'
File
- includes/processor_multivalue_field.inc, line 11 
- Processor for splitting indexing items on behalf of a multivalue field.
View source
class SearchApiGroupingMultivalueField extends SearchApiAbstractProcessor {
  /**
   * Return the settings form for this processor.
   */
  public function configurationForm() {
    $form = parent::configurationForm();
    // Re-use but modify the default form element.
    $form['fields']['#type'] = 'select';
    unset($form['fields']['#attributes']);
    $form['fields']['#options'] = array(
      NULL => t('<none>'),
    ) + $form['fields']['#options'];
    $form['split_field'] = $form['fields'];
    $form['fields']['#access'] = FALSE;
    $form['split_field'] = array(
      '#title' => 'The field to use to split the items to index.',
      '#default_value' => isset($this->options['split_field']) ? $this->options['split_field'] : NULL,
    ) + $form['split_field'];
    return $form;
  }
  /**
   * Splits up the items on behalf of a multivalue field.
   */
  public function preprocessIndexItems(array &$items) {
    // Preprocess first.
    parent::preprocessIndexItems($items);
    $source_items = $items;
    $all_items = array();
    if (!empty($this->options['split_field'])) {
      foreach ($items as $id => $item) {
        // Find the properties of the split field.
        $field_properties = array();
        list($key, $property) = explode(':', $this->options['split_field']);
        foreach ($item as $related_name => $related_field) {
          if (substr($related_name, 0, mb_strlen($key) + 1) == $key . ':') {
            $field_properties[] = $related_name;
          }
        }
        // Split field and properties found.
        if (!empty($field_properties)) {
          foreach ($item[$this->options['split_field']]['value'] as $delta => $value) {
            $split_item = $item;
            foreach ($field_properties as $field_property) {
              if (search_api_is_list_type($item[$field_property]['type'])) {
                $split_item[$field_property]['value'] = array(
                  $item[$field_property]['value'][$delta],
                );
              }
              else {
                // Very unlikely case but it's better to cover it.
                $split_item[$field_property]['value'] = $item[$field_property]['value'];
              }
            }
            $all_items[$id . ':delta' . $delta] = $split_item;
          }
        }
        else {
          $all_items[$id] = $item;
        }
      }
    }
    $items = $all_items;
  }
  /**
   * Fix potentially split id's.
   *
   * This is necessary since the id is reused to fetch the related entity.
   */
  public function postprocessSearchResults(array &$response, SearchApiQuery $query) {
    if (!empty($response['results'])) {
      foreach ($response['results'] as $id => &$result) {
        if (mb_strstr($id, ':delta') !== FALSE) {
          $result['id'] = preg_replace('/:delta\\d+/', '', $result['id']);
        }
      }
    }
    return;
  }
}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 | 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:: | public | function | Check whether this processor is applicable for a certain index. Overrides SearchApiProcessorInterface:: | |
| 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 | 
| SearchApiGroupingMultivalueField:: | public | function | Return the settings form for this processor. Overrides SearchApiAbstractProcessor:: | |
| SearchApiGroupingMultivalueField:: | public | function | Fix potentially split id's. Overrides SearchApiAbstractProcessor:: | |
| SearchApiGroupingMultivalueField:: | public | function | Splits up the items on behalf of a multivalue field. Overrides SearchApiAbstractProcessor:: | 
