You are here

protected function FuzzySearchService::prepareKeys in Fuzzy Search 7

Helper method for removing unnecessary nested expressions from keys.

2 calls to FuzzySearchService::prepareKeys()
FuzzySearchService::createFilterCondition in includes/service.inc
Helper method for creating a condition for filtering search results.
FuzzySearchService::search in includes/service.inc
Executes a search on the server represented by this object.

File

includes/service.inc, line 849

Class

FuzzySearchService
Search service class using the database for storing index information.

Code

protected function prepareKeys($keys) {
  if (is_scalar($keys)) {
    $keys = $this
      ->splitKeys($keys);
    return is_array($keys) ? $this
      ->eliminateDuplicates($keys) : $keys;
  }
  elseif (!$keys) {
    return NULL;
  }
  $keys = $this
    ->eliminateDuplicates($this
    ->splitKeys($keys));
  $conj = $keys['#conjunction'];
  $neg = !empty($keys['#negation']);
  foreach ($keys as $i => &$nested) {
    if (is_array($nested)) {
      $nested = $this
        ->prepareKeys($nested);
      if ($neg == !empty($nested['#negation'])) {
        if (isset($nested['#conjunction']) && $nested['#conjunction'] == $conj) {
          unset($nested['#conjunction'], $nested['#negation']);
          foreach ($nested as $renested) {
            $keys[] = $renested;
          }
          unset($keys[$i]);
        }
      }
    }
  }
  $keys = array_filter($keys);
  if (($count = count($keys)) <= 2) {
    if ($count < 2 || isset($keys['#negation'])) {
      $keys = NULL;
    }
    else {
      unset($keys['#conjunction']);
      $keys = array_shift($keys);
    }
  }
  return $keys;
}