Permalink
Browse files

Refactoring client interface clean up concrete classes

  • Loading branch information...
1 parent cf59371 commit cf274a974073970a252de14d691bd140c049db0c @MrHash MrHash committed Apr 28, 2013
View
63 lib/Doctrine/Search/ElasticSearch/Client.php
@@ -56,8 +56,7 @@ public function __construct(Elastica_Client $client)
*/
public function addDocuments($index, $type, array $documents)
{
- $index = $this->client->getIndex($index);
- $type = $index->getType($type);
+ $type = $this->getIndex($index)->getType($type);
$batch = array();
foreach($documents as $id => $document)
@@ -73,53 +72,59 @@ public function addDocuments($index, $type, array $documents)
*/
public function removeDocuments($index, $type, array $documents)
{
- $index = $this->client->getIndex($index);
- $type = $index->getType($type);
+ $type = $this->getIndex($index)->getType($type);
$type->deleteIds(array_keys($documents));
}
/**
- * Remove all documents of a given type from the specified index
- * without deleting the index itself
- *
- * @param string $index
- * @param string $type
+ * {@inheritDoc}
*/
public function removeAll($index, $type)
{
- $index = $this->client->getIndex($index);
- $type = $index->getType($type);
- $type->deleteByQuery(new MatchAll());
+ $type = $this->getIndex($index)->getType($type);
+ $type->deleteByQuery(new MatchAll());
}
/**
* {@inheritDoc}
*/
public function find($index, $type, $query)
{
- $index = $this->client->getIndex($index);
- return iterator_to_array($index->search($query));
+
}
/**
* {@inheritDoc}
*/
public function createIndex($name, array $config = array())
{
- $index = $this->client->getIndex($name);
+ $index = $this->getIndex($name);
$index->create($config, true);
return $index;
}
+ /**
+ * {@inheritDoc}
+ */
+ public function getIndex($name)
+ {
+ return $this->client->getIndex($name);
+ }
+
/**
- * Create a document type mapping in the specified index
- *
- * @param Elastica\Index $index
- * @param Doctrine\Search\Mapping\ClassMetadata $metadata
+ * {@inheritDoc}
+ */
+ public function deleteIndex($index)
+ {
+ $this->getIndex($index)->delete();
+ }
+
+ /**
+ * {@inheritDoc}
*/
- public function createType(Index $index, ClassMetadata $metadata)
+ public function createType(ClassMetadata $metadata)
{
- $type = $index->getType($metadata->type);
+ $type = $this->getIndex($metadata->index)->getType($metadata->type);
$properties = $this->getMapping($metadata->fieldMappings);
$mapping = new Mapping($type, $properties);
@@ -160,20 +165,4 @@ protected function getMapping($fieldMapping)
return $properties;
}
-
- /**
- * {@inheritDoc}
- */
- public function deleteIndex($index)
- {
- $index = $this->client->getIndex($index);
- $index->delete();
- }
-
- /**
- * {@inheritDoc}
- */
- public function bulkSearch(array $data)
- {
- }
}
View
34 lib/Doctrine/Search/SearchClientInterface.php
@@ -47,17 +47,28 @@ function find($index, $type, $query);
* @param string $config The configuration of the index.
*/
function createIndex($name, array $config = array());
-
+
/**
+ * Gets a document index reference
*
- * @param array $data
+ * @param string $name The name of the index.
*/
- function deleteIndex($index);
+ function getIndex($name);
/**
- * @param array $query
+ * Deletes an index and its types and documents
+ *
+ * @param string $index
*/
- function bulkSearch(array $query);
+ function deleteIndex($index);
+
+ /**
+ * Create a document type mapping as defined in the
+ * class annotations
+ *
+ * @param ClassMetadata $metadata
+ */
+ function createType(ClassMetadata $metadata);
/**
* Adds documents of a given type to the specified index
@@ -66,7 +77,7 @@ function bulkSearch(array $query);
* @param string $type
* @param array $documents Indexed by document id
*/
- public function addDocuments($index, $type, array $documents);
+ function addDocuments($index, $type, array $documents);
/**
* Remove documents of a given type from the specified index
@@ -75,5 +86,14 @@ public function addDocuments($index, $type, array $documents);
* @param string $type
* @param array $documents Indexed by document id
*/
- public function removeDocuments($index, $type, array $documents);
+ function removeDocuments($index, $type, array $documents);
+
+ /**
+ * Remove all documents of a given type from the specified index
+ * without deleting the index itself
+ *
+ * @param string $index
+ * @param string $type
+ */
+ function removeAll($index, $type);
}
View
23 lib/Doctrine/Search/SearchManager.php
@@ -21,7 +21,6 @@
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Search\SearchClientInterface;
-use Doctrine\Common\EventManager;
use Doctrine\Search\ElasticSearch\Client;
use Doctrine\Search\Configuration;
use Doctrine\Common\Annotations\AnnotationReader;
@@ -115,6 +114,14 @@ public function getClient()
return $this->searchClient;
}
+ /**
+ * @return mixed
+ */
+ public function getIndex($name)
+ {
+ return $this->getClient()->getIndex($name);
+ }
+
/**
* @return ClassMetadataFactory
*/
@@ -167,20 +174,6 @@ public function remove($object)
}
/**
- * Bulk action
- *
- * @param object $object
- *
- * @throws UnexpectedTypeException
- */
- public function bulk($object)
- {
- if (!is_object($object)) {
- throw new UnexpectedTypeException($object, 'object');
- }
- }
-
- /**
* Commit all changes
*/
public function commit()
View
34 lib/Doctrine/Search/Solr/Client.php
@@ -20,6 +20,7 @@
namespace Doctrine\Search\Solr;
use Doctrine\Search\SearchClientInterface;
+use Doctrine\Search\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
/**
@@ -54,27 +55,34 @@ public function createIndex($index, array $data)
{
}
-
- public function updateIndex(array $data)
+
+ public function createType(ClassMetadata $metadata)
+ {
+
+ }
+
+ public function getIndex($index)
{
}
- /**
- *
- * @param array $data
- */
public function deleteIndex($index)
{
- // TODO: Implement deleteIndex() method.
+
}
- /**
- * @param array $data
- */
- public function bulkAction(array $data)
+ public function addDocuments($index, $type, array $documents)
{
- // TODO: Implement bulkAction() method.
+
+ }
+
+ public function removeDocuments($index, $type, array $documents)
+ {
+
+ }
+
+ public function removeAll($index, $type)
+ {
+
}
-
}
View
37 lib/Doctrine/Search/ZendLucene/Client.php
@@ -19,7 +19,9 @@
namespace Doctrine\Search\ZendLucene;
+
use Doctrine\Search\SearchClientInterface;
+use Doctrine\Search\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
/**
@@ -54,27 +56,34 @@ public function createIndex($index, array $data)
{
}
+
+ public function createType(ClassMetadata $metadata)
+ {
- public function updateIndex(array $data)
+ }
+
+ public function getIndex($index)
{
}
- /**
- *
- * @param array $data
- */
public function deleteIndex($index)
{
- // TODO: Implement deleteIndex() method.
+
}
-
- /**
- * @param array $data
- */
- public function bulkAction(array $data)
- {
- // TODO: Implement bulkAction() method.
+
+ public function addDocuments($index, $type, array $documents)
+ {
+
+ }
+
+ public function removeDocuments($index, $type, array $documents)
+ {
+
+ }
+
+ public function removeAll($index, $type)
+ {
+
}
-
}

0 comments on commit cf274a9

Please sign in to comment.