You are here

protected function SearchApiAbstractProcessor::processField in Search API 7

Method for preprocessing field data.

Calls process() either for the whole text, or each token, depending on the type. Also takes care of extracting list values and of fusing returned tokens back into a one-dimensional array.

1 call to SearchApiAbstractProcessor::processField()
SearchApiAbstractProcessor::preprocessIndexItems in includes/processor.inc
Calls processField() for all appropriate fields.

File

includes/processor.inc, line 243
Contains SearchApiProcessorInterface and SearchApiAbstractProcessor.

Class

SearchApiAbstractProcessor
Abstract processor implementation that provides an easy framework for only processing specific fields.

Code

protected function processField(&$value, &$type) {
  if (!isset($value) || $value === '') {
    return;
  }
  if (substr($type, 0, 5) == 'list<') {
    $inner_type = $t = $t1 = substr($type, 5, -1);
    foreach ($value as &$v) {
      $t1 = $inner_type;
      $this
        ->processField($v, $t1);

      // If one value got tokenized, all others have to follow.
      if ($t1 != $inner_type) {
        $t = $t1;
      }
    }
    if ($t == 'tokens') {
      foreach ($value as $i => &$v) {
        if (!$v) {
          unset($value[$i]);
          continue;
        }
        if (!is_array($v)) {
          $v = array(
            array(
              'value' => $v,
              'score' => 1,
            ),
          );
        }
      }
    }
    $type = "list<{$t}>";
    return;
  }
  if ($type == 'tokens') {
    foreach ($value as &$token) {
      $this
        ->processFieldValue($token['value']);
    }
  }
  else {
    $this
      ->processFieldValue($value);
  }
  if (is_array($value)) {

    // Don't tokenize non-fulltext content!
    if (in_array($type, array(
      'text',
      'tokens',
    ))) {
      $type = 'tokens';
      $value = $this
        ->normalizeTokens($value);
    }
    else {
      $value = $this
        ->implodeTokens($value);
    }
  }
}