You are here

public function Query::__toString in Search API 8

Implements the magic __toString() method to simplify debugging.

File

src/Query/Query.php, line 832

Class

Query
Provides a standard implementation for a Search API query.

Namespace

Drupal\search_api\Query

Code

public function __toString() {
  $ret = 'Index: ' . $this->index
    ->id() . "\n";
  $ret .= 'Keys: ' . str_replace("\n", "\n  ", var_export($this->origKeys, TRUE)) . "\n";
  if (isset($this->keys)) {
    $ret .= 'Parsed keys: ' . str_replace("\n", "\n  ", var_export($this->keys, TRUE)) . "\n";
    $ret .= 'Searched fields: ' . (isset($this->fields) ? implode(', ', $this->fields) : '[ALL]') . "\n";
  }
  if (isset($this->languages)) {
    $ret .= 'Searched languages: ' . implode(', ', $this->languages) . "\n";
  }
  if ($conditions = (string) $this->conditionGroup) {
    $conditions = str_replace("\n", "\n  ", $conditions);
    $ret .= "Conditions:\n  {$conditions}\n";
  }
  if ($this->sorts) {
    $sorts = [];
    foreach ($this->sorts as $field => $order) {
      $sorts[] = "{$field} {$order}";
    }
    $ret .= 'Sorting: ' . implode(', ', $sorts) . "\n";
  }
  $options = $this
    ->sanitizeOptions($this->options);
  $options = str_replace("\n", "\n  ", var_export($options, TRUE));
  $ret .= 'Options: ' . $options . "\n";
  return $ret;
}