protected function SearchApiMultiQuery::parseKeys in Search API Multi-Index Searches 7
Parses the keys string according to a certain parse mode.
Parameters
string|array|null $keys: The keys as passed to keys().
string $mode: The parse mode to use. Must be one of the keys from parseModes().
Return value
string|array|null The parsed keys.
1 call to SearchApiMultiQuery::parseKeys()
- SearchApiMultiQuery::keys in ./
search_api_multi.query.inc - Sets the keys to search for.
File
- ./
search_api_multi.query.inc, line 467
Class
- SearchApiMultiQuery
- Standard implementation of SearchApiMultiQueryInterface.
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 = explode(' ', $keys);
$ret['#conjunction'] = $this->options['conjunction'];
$quoted = FALSE;
$str = '';
foreach ($ret as $k => $v) {
if (!$v) {
continue;
}
if ($quoted) {
if ($v[drupal_strlen($v) - 1] == '"') {
$v = substr($v, 0, -1);
$str .= ' ' . $v;
$ret[$k] = $str;
$quoted = FALSE;
}
else {
$str .= ' ' . $v;
unset($ret[$k]);
}
}
elseif ($v[0] == '"') {
$len = drupal_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;
}
return array_filter($ret);
default:
throw new SearchApiException(t('Unrecognized parse mode %mode.', array(
'%mode' => $mode,
)));
}
}