You are here

class Apache_Solr_Document in Apache Solr Search 5

Holds Key / Value pairs that represent a Solr Document. Field values can be accessed by direct dereferencing such as: <code> ... $document->title = 'Something'; echo $document->title; ... </code>

Additionally, the field values can be iterated with foreach

<code> foreach ($document as $key => $value) { ... } </code>

Hierarchy

Expanded class hierarchy of Apache_Solr_Document

File

SolrPhpClient/Apache/Solr/Document.php, line 42

View source
class Apache_Solr_Document implements Iterator {
  protected $_fields = array();

  /**
   * Magic get for field values
   *
   * @param string $key
   * @return mixed
   */
  public function __get($key) {
    return $this->_fields[$key];
  }

  /**
   * Magic set for field values. Multi-valued fields should be set as arrays
   * or instead use the setMultiValue(...) function which will automatically
   * make sure the field is an array.
   *
   * @param string $key
   * @param mixed $value
   */
  public function __set($key, $value) {
    $this->_fields[$key] = $value;
  }

  /**
   * Magic isset for fields values.  Do no call directly. Allows usage:
   *
   * <code>
   * isset($document->some_field);
   * </code>
   *
   * @param string $key
   * @return boolean
   */
  public function __isset($key) {
    return isset($this->_fields[$key]);
  }

  /**
   * Magic unset for field values. Do no call directly. Allows usage:
   *
   * <code>
   * unset($document->some_field);
   * </code>
   *
   * @param string $key
   */
  public function __unset($key) {
    unset($this->_fields[$key]);
  }

  /**
   * Handle the array manipulation for a multi-valued field
   *
   * @param string $key
   * @param string $value
   */
  public function setMultiValue($key, $value) {
    if (!isset($this->_fields[$key])) {
      $this->_fields[$key] = array();
    }
    if (!is_array($this->_fields[$key])) {
      $this->_fields[$key] = array(
        $this->_fields[$key],
      );
    }
    $this->_fields[$key][] = $value;
  }

  /**
   * Get the names of all fields in this document
   *
   * @return array
   */
  public function getFieldNames() {
    return array_keys($this->_fields);
  }

  /**
   * Iterator implementation function, proxies to _fields. Allows usage:
   *
   * <code>
   * foreach ($document as $key => $value)
   * {
   *  ...
   * }
   * </code>
   */
  public function rewind() {
    reset($this->_fields);
  }

  /**
   * Iterator implementation function, proxies to _fields. Allows usage:
   *
   * <code>
   * foreach ($document as $key => $value)
   * {
   *  ...
   * }
   * </code>
   */
  public function current() {
    return current($this->_fields);
  }

  /**
   * Iterator implementation function, proxies to _fields. Allows usage:
   *
   * <code>
   * foreach ($document as $key => $value)
   * {
   *  ...
   * }
   * </code>
   */
  public function key() {
    return key($this->_fields);
  }

  /**
   * Iterator implementation function, proxies to _fields. Allows usage:
   *
   * <code>
   * foreach ($document as $key => $value)
   * {
   *  ...
   * }
   * </code>
   */
  public function next() {
    return next($this->_fields);
  }

  /**
   * Iterator implementation function, proxies to _fields. Allows usage:
   *
   * <code>
   * foreach ($document as $key => $value)
   * {
   *  ...
   * }
   * </code>
   */
  public function valid() {
    return current($this->_fields) !== false;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Apache_Solr_Document::$_fields protected property
Apache_Solr_Document::current public function Iterator implementation function, proxies to _fields. Allows usage:
Apache_Solr_Document::getFieldNames public function Get the names of all fields in this document
Apache_Solr_Document::key public function Iterator implementation function, proxies to _fields. Allows usage:
Apache_Solr_Document::next public function Iterator implementation function, proxies to _fields. Allows usage:
Apache_Solr_Document::rewind public function Iterator implementation function, proxies to _fields. Allows usage:
Apache_Solr_Document::setMultiValue public function Handle the array manipulation for a multi-valued field
Apache_Solr_Document::valid public function Iterator implementation function, proxies to _fields. Allows usage:
Apache_Solr_Document::__get public function Magic get for field values
Apache_Solr_Document::__isset public function Magic isset for fields values. Do no call directly. Allows usage:
Apache_Solr_Document::__set public function Magic set for field values. Multi-valued fields should be set as arrays or instead use the setMultiValue(...) function which will automatically make sure the field is an array.
Apache_Solr_Document::__unset public function Magic unset for field values. Do no call directly. Allows usage: