<?php
declare(strict_types=1);
/*
*
* This file is part of the PEC Platform SearchBundle.
*
* (c) PEC project engineers & consultants
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Pec\Bundle\SearchBundle\Entity;
@trigger_error('Please use \StingerSoft\EntitySearchBundle\Model\Document', E_USER_DEPRECATED);
/**
* POPO to encapsulated properties and fields to be indexed
* @deprecated
*/
class SolrDocument {
/**
* Key of the solr field <em>title</em>
* @var string
*/
const FIELD_TITLE = 'title';
/**
* Key of the solr field <em>content</em>
* @var string
*/
const FIELD_CONTENT = 'content';
/**
* Key of the solr field <em>last_modified</em>
* @var string
*/
const FIELD_LAST_MODIFIED = 'last_modified';
/**
* Key of the solr field <em>author</em>
* @var string
*/
const FIELD_AUTHOR = 'author';
/**
* Key of the solr field <em>keywords</em>
* @var string
*/
const FIELD_KEYWORDS = 'keywords';
/**
* Key of the solr field <em>roles</em>
* @var string
*/
const FIELD_ROLES = 'roles';
/**
* Key of the solr field <em>editors</em>
* @var string
*/
const FIELD_EDITORS = 'editors';
/**
* Key of the solr field <em>deleted_at</em>
* @var string
*/
const FIELD_DELETED_AT = 'deleted_at';
/**
* Stores are fields with their values which should be stored in the solr index
* @var array
*/
protected $fields = array();
/**
* Adds a field and its value to the index
* @param string $fieldname
* @param mixed $value
*/
public function addField($fieldname, $value) {
$this->fields[$fieldname] = $this->failSafeValue($value);
}
/**
* Returns all fields and values which should be stored in the solr index
*/
public function getFields() {
return $this->fields;
}
/**
* Adds an editor to the field set
* @param string $editor
*/
public function addEditor($editor) {
$this->addMultiValueField(self::FIELD_EDITORS, $editor);
}
/**
* Adds a role to the field set
* @param string $role
*/
public function addRole($role) {
$this->addMultiValueField(self::FIELD_ROLES, $role);
}
/**
* Adds a value to a field without deleting the already existing values
* @param string $field
* @param string $value
*/
public function addMultiValueField($field, $value) {
if(!array_key_exists($field, $this->fields)) {
$this->fields[$field] = array(
$this->failSafeValue($value)
);
} else if(!in_array($value, $this->fields[$field])) {
$this->fields[$field][] = $this->failSafeValue($value);
}
}
protected function failSafeValue($value) {
if(is_string($value)) {
return preg_replace('@[\x00-\x08\x0B\x0C\x0E-\x1F]@', ' ', $value);
}
return $value;
}
}