You are here

class TextValue in Search API 8

Represents a single value of a fulltext field.

Hierarchy

Expanded class hierarchy of TextValue

6 files declare their use of TextValue
AddHierarchy.php in src/Plugin/search_api/processor/AddHierarchy.php
BackendTest.php in modules/search_api_db/tests/src/Kernel/BackendTest.php
FieldsProcessorPluginBaseTest.php in tests/src/Unit/Processor/FieldsProcessorPluginBaseTest.php
StemmerTest.php in tests/src/Unit/Processor/StemmerTest.php
TestFieldsProcessorPlugin.php in tests/src/Unit/Processor/TestFieldsProcessorPlugin.php

... See full list

File

src/Plugin/search_api/data_type/value/TextValue.php, line 8

Namespace

Drupal\search_api\Plugin\search_api\data_type\value
View source
class TextValue implements TextValueInterface {

  /**
   * The current text value.
   *
   * @var string
   */
  protected $text;

  /**
   * The original text value.
   *
   * @var string
   */
  protected $originalText;

  /**
   * The tokens created for this text value (if any).
   *
   * @var \Drupal\search_api\Plugin\search_api\data_type\value\TextTokenInterface[]|null
   */
  protected $tokens;

  /**
   * An array of properties for this text value.
   *
   * @var array
   */
  protected $properties = [];

  /**
   * Constructs a TextValue object.
   *
   * @param string $text
   *   The original text value.
   */
  public function __construct($text) {
    $this->text = $this->originalText = $text;
  }

  /**
   * {@inheritdoc}
   */
  public function getText() {
    return $this->text;
  }

  /**
   * {@inheritdoc}
   */
  public function toText() {
    $tokens = $this
      ->getTokens();
    if ($tokens !== NULL) {
      $to_string = function (TextTokenInterface $token) {
        return $token
          ->getText();
      };
      return implode(' ', array_map($to_string, $tokens));
    }
    return $this
      ->getText();
  }

  /**
   * {@inheritdoc}
   */
  public function setText($text) {
    $this->text = $text;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getOriginalText() {
    return $this->originalText;
  }

  /**
   * {@inheritdoc}
   */
  public function setOriginalText($originalText) {
    $this->originalText = $originalText;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getTokens() {
    return $this->tokens;
  }

  /**
   * {@inheritdoc}
   */
  public function setTokens(array $tokens = NULL) {
    $this->tokens = $tokens;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getProperties() {
    return $this->properties;
  }

  /**
   * {@inheritdoc}
   */
  public function getProperty($name, $default = NULL) {
    if (array_key_exists($name, $this->properties)) {
      return $this->properties[$name];
    }
    return $default;
  }

  /**
   * {@inheritdoc}
   */
  public function setProperties(array $properties) {
    $this->properties = $properties;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setProperty($name, $value = TRUE) {
    $this->properties[$name] = $value;
    return $this;
  }

  /**
   * Implements the magic __toString() method.
   */
  public function __toString() {
    return $this
      ->toText();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TextValue::$originalText protected property The original text value.
TextValue::$properties protected property An array of properties for this text value.
TextValue::$text protected property The current text value.
TextValue::$tokens protected property The tokens created for this text value (if any).
TextValue::getOriginalText public function Retrieves the original text value. Overrides TextValueInterface::getOriginalText
TextValue::getProperties public function Retrieves the properties set for this text value. Overrides TextValueInterface::getProperties
TextValue::getProperty public function Retrieves a specific property of this text value. Overrides TextValueInterface::getProperty
TextValue::getText public function Retrieves the currently stored text value. Overrides TextValueInterface::getText
TextValue::getTokens public function Retrieves the text tokens this text value was split into, if any. Overrides TextValueInterface::getTokens
TextValue::setOriginalText public function Sets the original text value. Overrides TextValueInterface::setOriginalText
TextValue::setProperties public function Sets the properties of this text value. Overrides TextValueInterface::setProperties
TextValue::setProperty public function Sets the properties of this text value. Overrides TextValueInterface::setProperty
TextValue::setText public function Sets the currently stored text value. Overrides TextValueInterface::setText
TextValue::setTokens public function Sets the text tokens for the text value. Overrides TextValueInterface::setTokens
TextValue::toText public function Retrieves the current effective text value. Overrides TextValueInterface::toText
TextValue::__construct public function Constructs a TextValue object.
TextValue::__toString public function Implements the magic __toString() method.