Skip to content

Commit

Permalink
Renamed IndicesAndTypesMetadataCollection to TypesToDocumentClasses
Browse files Browse the repository at this point in the history
Made all properties in AbstractDocument public
Replaced Converter with DocumentConverter
Removed dependency on PropertyAccess component
Refactored DocumentIterator and ObjectIterator
  • Loading branch information
pmishev committed Nov 19, 2015
1 parent f895740 commit ed9c8c6
Show file tree
Hide file tree
Showing 17 changed files with 538 additions and 821 deletions.
53 changes: 0 additions & 53 deletions DTO/IndicesAndTypesMetadataCollection.php

This file was deleted.

52 changes: 52 additions & 0 deletions DTO/TypesToDocumentClasses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Sineflow\ElasticsearchBundle\DTO;

/**
* Class to be used as a data transport structure of mappings between physical indices + types,
* to document names in short notation (e.g. AppBundle:Product)
*/
class TypesToDocumentClasses
{
/**
* <physical_index_name|*> => [
* <es_type> => <document_class>
* ...
* ]
* ...
*
* @var array
*/
private $documentClasses = [];

/**
* Set the document class for a combination of a physical index name and a type
* When all the needed types are unique across indices, `null` can be passed for $index
*
* @param string $index The name of the physical index in Elasticsearch
* @param string $type The name of the type in Elasticsearch
* @param string $documentClass The document class in short notation
*/
public function set($index, $type, $documentClass)
{
$this->documentClasses[$index ?: '*'][$type] = $documentClass;
}

/**
* Get the document class for a combination of a physical index name and a type
*
* @param string $index The name of the physical index in Elasticsearch
* @param string $type The name of the type in Elasticsearch
* @return string
*/
public function get($index, $type)
{
if (isset($this->documentClasses[$index][$type])) {
return $this->documentClasses[$index][$type];
} elseif (isset($this->documentClasses['*'][$type])) {
return $this->documentClasses['*'][$type];
} else {
throw new \InvalidArgumentException(sprintf('Document class for type "%s" in index "%s" is not set', $type, $index));
}
}
}
123 changes: 13 additions & 110 deletions Document/AbstractDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,135 +11,38 @@ abstract class AbstractDocument implements DocumentInterface
{
/**
* @var string
*
* @ES\Property(type="string", name="_id")
*/
private $id;
public $id;

/**
* @var string
*
* @ES\Property(type="float", name="_score")
*/
private $score;
public $score;

/**
* @var string
*
* @ES\Property(type="string", name="_parent")
*/
private $parent;
public $parent;

/**
* @var string
*
* @ES\Property(type="string", name="_ttl")
*/
private $ttl;
public $ttl;

/**
* When document is cloned id is set to null.
*/
public function __clone()
{
$this->setId(null);
$this->id = null;
}

/**
* Sets document unique id.
*
* @param string $documentId
*
* @return $this
*/
public function setId($documentId)
{
$this->id = $documentId;

return $this;
}

/**
* Returns document id.
*
* @return string
*/
public function getId()
{
return $this->id;
}

/**
* Sets document score.
*
* @param string $documentScore
*
* @return $this
*/
public function setScore($documentScore)
{
$this->score = $documentScore;

return $this;
}

/**
* Gets document score.
*
* @return string
*/
public function getScore()
{
return $this->score;
}

/**
* Sets parent document id.
*
* @param string $parent
*
* @return $this
*/
public function setParent($parent)
{
$this->parent = $parent;

return $this;
}

/**
* Returns parent document id.
*
* @return null|string
*/
public function getParent()
{
return $this->parent;
}

/**
* Checks if document has a parent.
*
* @return bool
*/
public function hasParent()
{
return $this->parent !== null;
}

/**
* Sets time to live timestamp.
*
* @param string $ttl
*
* @return $this
*/
public function setTtl($ttl)
{
$this->ttl = $ttl;

return $this;
}

/**
* Returns time to live value.
*
* @return int
*/
public function getTtl()
{
return $this->ttl;
}
}
70 changes: 0 additions & 70 deletions Document/DocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,4 @@
*/
interface DocumentInterface
{
/**
* Sets document unique id.
*
* @param string $documentId
*
* @return $this
*/
public function setId($documentId);

/**
* Returns document id.
*
* @return string
*/
public function getId();

/**
* Sets document score.
*
* @param string $documentScore
*
* @return $this
*/
public function setScore($documentScore);

/**
* Gets document score.
*
* @return string
*/
public function getScore();

/**
* Sets parent document id.
*
* @param string $parent
*
* @return $this
*/
public function setParent($parent);

/**
* Returns parent document id.
*
* @return null|string
*/
public function getParent();

/**
* Checks if document has a parent.
*
* @return bool
*/
public function hasParent();

/**
* Sets time to live timestamp.
*
* @param int $ttl
*
* @return $this
*/
public function setTtl($ttl);

/**
* Returns time to live value.
*
* @return int
*/
public function getTtl();
}
2 changes: 0 additions & 2 deletions Document/Repository/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace Sineflow\ElasticsearchBundle\Document\Repository;

use Elasticsearch\Common\Exceptions\Missing404Exception;
use Sineflow\ElasticsearchBundle\Document\DocumentInterface;
use Sineflow\ElasticsearchBundle\Finder\Finder;
use Sineflow\ElasticsearchBundle\Result\Converter;
use Sineflow\ElasticsearchBundle\Manager\IndexManager;
use Sineflow\ElasticsearchBundle\Mapping\DocumentMetadata;

Expand Down
Loading

0 comments on commit ed9c8c6

Please sign in to comment.