You are here

protected function SearchApiQuery::parseKeys in Search API 7

1 call to SearchApiQuery::parseKeys()
SearchApiQuery::keys in includes/query.inc
Sets the keys to search for.

File

includes/query.inc, line 493
Contains SearchApiQueryInterface and SearchApiQuery.

Class

SearchApiQuery
Provides a standard implementation of the SearchApiQueryInterface.

Code

protected function parseKeys($keys, $mode) {
  if ($keys === NULL || is_array($keys)) {
    return $keys;
  }
  $keys = '' . $keys;
  switch ($mode) {
    case 'direct':
      return $keys;
    case 'single':
      return array(
        '#conjunction' => $this->options['conjunction'],
        $keys,
      );
    case 'terms':
      $ret = preg_split('/\\s+/u', $keys);
      $quoted = FALSE;
      $str = '';
      foreach ($ret as $k => $v) {
        if (!$v) {
          continue;
        }
        if ($quoted) {
          if (substr($v, -1) == '"') {
            $v = substr($v, 0, -1);
            $str .= ' ' . $v;
            $ret[$k] = $str;
            $quoted = FALSE;
          }
          else {
            $str .= ' ' . $v;
            unset($ret[$k]);
          }
        }
        elseif ($v[0] == '"') {
          $len = strlen($v);
          if ($len > 1 && $v[$len - 1] == '"') {
            $ret[$k] = substr($v, 1, -1);
          }
          else {
            $str = substr($v, 1);
            $quoted = TRUE;
            unset($ret[$k]);
          }
        }
      }
      if ($quoted) {
        $ret[] = $str;
      }
      $ret['#conjunction'] = $this->options['conjunction'];
      return array_filter($ret);
  }
}