<commit_before><?php

/*
 * This file is part of the Stinger Entity Search package.
 *
 * (c) <NAME> <<EMAIL>>
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace StingerSoft\DoctrineEntitySearchBundle\Model;

use StingerSoft\EntitySearchBundle\Model\Document as BaseDocument;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Backend independent document implementation
 */
abstract class Document implements BaseDocument {

	protected $id;

	/**
	 *
	 * @var string
	 */
	protected $entityClass = null;

	/**
	 *
	 * @var string
	 */
	protected $entityType = null;

	/**
	 *
	 * @var mixed
	 */
	protected $entityId = null;

	/**
	 *
	 * @var Field[]
	 */
	protected $internalFields;

	public function __construct() {
		$this->internalFields = new ArrayCollection();
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::addField()
	 */
	public function addField($fieldname, $value) {
		foreach($this->internalFields as $field) {
			if($field->getFieldName() == $fieldname) {
				$field->setFieldValue($value);
				return;
			}
		}
		$field = $this->newFieldInstance();
		$field->setFieldValue($value);
		$field->setFieldName($fieldname);
		$this->internalFields[] = $field;
		$field->setDocument($this);
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getFields()
	 */
	public function getFields() {
		$result = array();
		foreach($this->internalFields as $field) {
			if(isset($result[$field->getFieldName()])) {
				$oldValue = $result[$field->getFieldName()];
				if(is_array($oldValue)) {
					$result[$field->getFieldName()][] = $field->getFieldValue();
				} else if(is_scalar($oldValue)) {
					$result[$field->getFieldName()] = array(
						$oldValue,
						$field->getFieldValue() 
					);
				}
			} else {
				$result[$field->getFieldName()] = $field->getFieldValue();
			}
		}
		return $result;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getFieldValue()
	 */
	public function getFieldValue($fieldName) {
		$result = array();
		foreach($this->internalFields as $field) {
			if($field->getFieldName() == $fieldName) {
				$result[] = $field->getFieldValue();
			}
		}
		switch(count($result)) {
			case 0:
				return null;
			case 1:
				return $result[0];
			default:
				return $result;
		}
		return null;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::addMultiValueField()
	 */
	public function addMultiValueField($fieldName, $value) {
		$field = $this->newFieldInstance();
		$field->setFieldValue($value);
		$field->setFieldName($fieldName);
		$this->internalFields[] = $field;
		$field->setDocument($this);
	}

	/**
	 * Returns the internal field representation
	 *
	 * @return Field[]
	 */
	public function getInternalFields() {
		return $this->internalFields;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setFile()
	 */
	public function setFile($path) {
		// Not supported
	}

	/**
	 */
	public function getId() {
		return $this->id;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getEntityClass()
	 */
	public function getEntityClass() {
		return $this->entityClass;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setEntityClass()
	 */
	public function setEntityClass($entityClass) {
		$this->entityClass = $entityClass;
		if(!$this->entityType) {
			$this->entityType = $entityClass;
		}
		return $this;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setEntityType()
	 */
	public function setEntityType($type) {
		$this->entityType = $type;
	}
	
	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getEntityType()
	 */
	public function getEntityType() {
		return $this->entityType ? $this->entityType : $this->getEntityClass();
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getEntityId()
	 */
	public function getEntityId() {
		return json_decode($this->entityId);
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setEntityId()
	 */
	public function setEntityId($entityId) {
		$this->entityId = json_encode($entityId);
		return $this;
	}

	public function getInternalEntityId() {
		return $this->entityId;
	}

	public function __get($name) {
		return $this->getFieldValue($name);
	}

	public function __isset($name) {
		return $this->getFieldValue($name) !== null;
	}

	/**
	 * Creates a new field instance
	 *
	 * @return Field
	 */
	protected abstract function newFieldInstance();
}<commit_msg>Added missing method<commit_after><?php

/*
 * This file is part of the Stinger Entity Search package.
 *
 * (c) <NAME> <<EMAIL>.<EMAIL>>
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace StingerSoft\DoctrineEntitySearchBundle\Model;

use StingerSoft\EntitySearchBundle\Model\Document as BaseDocument;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Backend independent document implementation
 */
abstract class Document implements BaseDocument {

	protected $id;

	/**
	 *
	 * @var string
	 */
	protected $entityClass = null;

	/**
	 *
	 * @var string
	 */
	protected $entityType = null;

	/**
	 *
	 * @var mixed
	 */
	protected $entityId = null;

	/**
	 *
	 * @var Field[]
	 */
	protected $internalFields;

	public function __construct() {
		$this->internalFields = new ArrayCollection();
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::addField()
	 */
	public function addField($fieldname, $value) {
		foreach($this->internalFields as $field) {
			if($field->getFieldName() == $fieldname) {
				$field->setFieldValue($value);
				return;
			}
		}
		$field = $this->newFieldInstance();
		$field->setFieldValue($value);
		$field->setFieldName($fieldname);
		$this->internalFields[] = $field;
		$field->setDocument($this);
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getFields()
	 */
	public function getFields() {
		$result = array();
		foreach($this->internalFields as $field) {
			if(isset($result[$field->getFieldName()])) {
				$oldValue = $result[$field->getFieldName()];
				if(is_array($oldValue)) {
					$result[$field->getFieldName()][] = $field->getFieldValue();
				} else if(is_scalar($oldValue)) {
					$result[$field->getFieldName()] = array(
						$oldValue,
						$field->getFieldValue() 
					);
				}
			} else {
				$result[$field->getFieldName()] = $field->getFieldValue();
			}
		}
		return $result;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getFieldValue()
	 */
	public function getFieldValue($fieldName) {
		$result = array();
		foreach($this->internalFields as $field) {
			if($field->getFieldName() == $fieldName) {
				$result[] = $field->getFieldValue();
			}
		}
		switch(count($result)) {
			case 0:
				return null;
			case 1:
				return $result[0];
			default:
				return $result;
		}
		return null;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::addMultiValueField()
	 */
	public function addMultiValueField($fieldName, $value) {
		$field = $this->newFieldInstance();
		$field->setFieldValue($value);
		$field->setFieldName($fieldName);
		$this->internalFields[] = $field;
		$field->setDocument($this);
	}

	/**
	 * Returns the internal field representation
	 *
	 * @return Field[]
	 */
	public function getInternalFields() {
		return $this->internalFields;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setFile()
	 */
	public function setFile($path) {
		// Not supported
	}
	
	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getFile()
	 */
	public function getFile() {
		// Not supported
		return null;
	}

	/**
	 */
	public function getId() {
		return $this->id;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getEntityClass()
	 */
	public function getEntityClass() {
		return $this->entityClass;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setEntityClass()
	 */
	public function setEntityClass($entityClass) {
		$this->entityClass = $entityClass;
		if(!$this->entityType) {
			$this->entityType = $entityClass;
		}
		return $this;
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setEntityType()
	 */
	public function setEntityType($type) {
		$this->entityType = $type;
	}
	
	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getEntityType()
	 */
	public function getEntityType() {
		return $this->entityType ? $this->entityType : $this->getEntityClass();
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::getEntityId()
	 */
	public function getEntityId() {
		return json_decode($this->entityId);
	}

	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \StingerSoft\EntitySearchBundle\Model\Document::setEntityId()
	 */
	public function setEntityId($entityId) {
		$this->entityId = json_encode($entityId);
		return $this;
	}

	public function getInternalEntityId() {
		return $this->entityId;
	}

	public function __get($name) {
		return $this->getFieldValue($name);
	}

	public function __isset($name) {
		return $this->getFieldValue($name) !== null;
	}

	/**
	 * Creates a new field instance
	 *
	 * @return Field
	 */
	protected abstract function newFieldInstance();
}
{'fraction_non_alphanumeric': 0.16646329062436446, 'fraction_numerical': 0.0006101281269066504, 'mean_word_length': 3.6304143126177024, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 98, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2311347', 'n_tokens_mistral': 3586, 'n_tokens_neox': 3147, 'n_words': 574}