You are here

public function Item::__toString in Search API 8

Implements the magic __toString() method to simplify debugging.

File

src/Item/Item.php, line 517

Class

Item
Provides a default implementation for a search item.

Namespace

Drupal\search_api\Item

Code

public function __toString() {
  $out = 'Item ' . $this
    ->getId();
  if ($this
    ->getScore() != 1) {
    $out .= "\nScore: " . $this
      ->getScore();
  }
  if ($this
    ->getBoost() != 1) {
    $out .= "\nBoost: " . $this
      ->getBoost();
  }
  if ($this
    ->getExcerpt()) {
    $excerpt = str_replace("\n", "\n  ", $this
      ->getExcerpt());
    $out .= "\nExcerpt: {$excerpt}";
  }
  if ($this
    ->getFields(FALSE)) {
    $out .= "\nFields:";
    foreach ($this
      ->getFields(FALSE) as $field) {
      $field = str_replace("\n", "\n  ", "{$field}");
      $out .= "\n- " . $field;
    }
  }
  if ($this
    ->getAllExtraData()) {
    $data = str_replace("\n", "\n  ", print_r($this
      ->getAllExtraData(), TRUE));
    $out .= "\nExtra data: " . $data;
  }
  return $out;
}