made the bundle compatible with Elastica 0.20.x
This commit is contained in:
parent
d8f836d179
commit
aafb6e53fb
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace FOS\ElasticaBundle;
|
||||
|
||||
use Elastica_Client;
|
||||
use Elastica\Client as ElasticaClient;
|
||||
use FOS\ElasticaBundle\Logger\ElasticaLogger;
|
||||
|
||||
/**
|
||||
* @author Gordon Franke <info@nevalon.de>
|
||||
*/
|
||||
class Client extends Elastica_Client
|
||||
class Client extends ElasticaClient
|
||||
{
|
||||
/**
|
||||
* @var ElasticaLogger
|
||||
|
@ -20,7 +20,7 @@ class Client extends Elastica_Client
|
|||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function request($path, $method, $data = array(), array $query = array())
|
||||
public function request($path, $method = Request::GET, $data = array(), array $query = array())
|
||||
{
|
||||
$start = microtime(true);
|
||||
$response = parent::request($path, $method, $data, $query);
|
||||
|
|
|
@ -8,8 +8,8 @@ use Symfony\Component\Console\Input\InputOption;
|
|||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Elastica_Query;
|
||||
use Elastica_Result;
|
||||
use Elastica\Query;
|
||||
use Elastica\Result;
|
||||
|
||||
/**
|
||||
* Searches a type
|
||||
|
@ -41,11 +41,11 @@ class SearchCommand extends ContainerAwareCommand
|
|||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$indexName = $input->getOption('index');
|
||||
/** @var $index \Elastica_Index */
|
||||
/** @var $index \Elastica\Index */
|
||||
$index = $this->getContainer()->get('fos_elastica.index_manager')->getIndex($indexName ? $indexName : null);
|
||||
$type = $index->getType($input->getArgument('type'));
|
||||
$query = Elastica_Query::create($input->getArgument('query'));
|
||||
$query->setLimit($input->getOption('limit'));
|
||||
$query = Query::create($input->getArgument('query'));
|
||||
$query->setSize($input->getOption('limit'));
|
||||
if ($input->getOption('explain')) {
|
||||
$query->setExplain(true);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class SearchCommand extends ContainerAwareCommand
|
|||
}
|
||||
}
|
||||
|
||||
protected function formatResult(Elastica_Result $result, $showField, $showSource, $showId, $explain)
|
||||
protected function formatResult(Result $result, $showField, $showSource, $showId, $explain)
|
||||
{
|
||||
$source = $result->getSource();
|
||||
if ($showField) {
|
||||
|
|
|
@ -37,7 +37,7 @@ class Configuration implements ConfigurationInterface
|
|||
->arrayNode('serializer')
|
||||
->treatNullLike(array())
|
||||
->children()
|
||||
->scalarNode('callback')->defaultValue('foq_elastica.serializer.callback.class')->end()
|
||||
->scalarNode('callback')->defaultValue('fos_elastica.serializer.callback.class')->end()
|
||||
->scalarNode('serializer')->defaultValue('serializer')->end()
|
||||
->end()
|
||||
->end()
|
||||
|
@ -219,6 +219,7 @@ class Configuration implements ConfigurationInterface
|
|||
->treatNullLike(array())
|
||||
->prototype('scalar')->end()
|
||||
->end()
|
||||
->scalarNode('version')->end()
|
||||
->end()
|
||||
->end()
|
||||
->scalarNode('index_analyzer')->end()
|
||||
|
|
|
@ -189,6 +189,9 @@ class FOSElasticaExtension extends Extension
|
|||
if (isset($type['serializer']['groups'])) {
|
||||
$serializerDef->addMethodCall('setGroups', array($type['serializer']['groups']));
|
||||
}
|
||||
if (isset($type['serializer']['version'])) {
|
||||
$serializerDef->addMethodCall('version', array($type['serializer']['version']));
|
||||
}
|
||||
|
||||
$container->setDefinition($serializerId, $serializerDef);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ interface FinderInterface
|
|||
/**
|
||||
* Searches for query results within a given limit
|
||||
*
|
||||
* @param mixed $query Can be a string, an array or an Elastica_Query object
|
||||
* @param mixed $query Can be a string, an array or an \Elastica\Query object
|
||||
* @param int $limit How many results to get
|
||||
* @return array results
|
||||
*/
|
||||
|
|
|
@ -4,14 +4,14 @@ namespace FOS\ElasticaBundle\Finder;
|
|||
|
||||
use FOS\ElasticaBundle\Paginator\PaginatorAdapterInterface;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Elastica_Query;
|
||||
use Elastica\Query;
|
||||
|
||||
interface PaginatedFinderInterface extends FinderInterface
|
||||
{
|
||||
/**
|
||||
* Searches for query results and returns them wrapped in a paginator
|
||||
*
|
||||
* @param mixed $query Can be a string, an array or an Elastica_Query object
|
||||
* @param mixed $query Can be a string, an array or an \Elastica\Query object
|
||||
* @return Pagerfanta paginated results
|
||||
*/
|
||||
function findPaginated($query);
|
||||
|
|
|
@ -7,8 +7,8 @@ use FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface;
|
|||
use FOS\ElasticaBundle\Paginator\TransformedPaginatorAdapter;
|
||||
use FOS\ElasticaBundle\Paginator\FantaPaginatorAdapter;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Elastica_Searchable;
|
||||
use Elastica_Query;
|
||||
use Elastica\SearchableInterface;
|
||||
use Elastica\Query;
|
||||
|
||||
/**
|
||||
* Finds elastica documents and map them to persisted objects
|
||||
|
@ -18,7 +18,7 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
protected $searchable;
|
||||
protected $transformer;
|
||||
|
||||
public function __construct(Elastica_Searchable $searchable, ElasticaToModelTransformerInterface $transformer)
|
||||
public function __construct(SearchableInterface $searchable, ElasticaToModelTransformerInterface $transformer)
|
||||
{
|
||||
$this->searchable = $searchable;
|
||||
$this->transformer = $transformer;
|
||||
|
@ -52,9 +52,9 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
*/
|
||||
protected function search($query, $limit = null)
|
||||
{
|
||||
$queryObject = Elastica_Query::create($query);
|
||||
$queryObject = Query::create($query);
|
||||
if (null !== $limit) {
|
||||
$queryObject->setLimit($limit);
|
||||
$queryObject->setSize($limit);
|
||||
}
|
||||
$results = $this->searchable->search($queryObject)->getResults();
|
||||
|
||||
|
@ -70,7 +70,7 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
*/
|
||||
public function findPaginated($query)
|
||||
{
|
||||
$queryObject = Elastica_Query::create($query);
|
||||
$queryObject = Query::create($query);
|
||||
$paginatorAdapter = $this->createPaginatorAdapter($queryObject);
|
||||
|
||||
return new Pagerfanta(new FantaPaginatorAdapter($paginatorAdapter));
|
||||
|
@ -81,7 +81,7 @@ class TransformedFinder implements PaginatedFinderInterface
|
|||
*/
|
||||
public function createPaginatorAdapter($query)
|
||||
{
|
||||
$query = Elastica_Query::create($query);
|
||||
$query = Query::create($query);
|
||||
return new TransformedPaginatorAdapter($this->searchable, $query, $this->transformer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace FOS\ElasticaBundle;
|
||||
|
||||
use Elastica_Result;
|
||||
use Elastica\Result;
|
||||
|
||||
class HybridResult
|
||||
{
|
||||
protected $result;
|
||||
protected $transformed;
|
||||
|
||||
public function __construct(Elastica_Result $result, $transformed = null)
|
||||
public function __construct(Result $result, $transformed = null)
|
||||
{
|
||||
$this->result = $result;
|
||||
$this->transformed = $transformed;
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace FOS\ElasticaBundle;
|
||||
|
||||
use Elastica\Index;
|
||||
|
||||
class IndexManager
|
||||
{
|
||||
protected $indexesByName;
|
||||
|
@ -11,9 +13,9 @@ class IndexManager
|
|||
* Constructor.
|
||||
*
|
||||
* @param array $indexesByName
|
||||
* @param \Elastica_Index $defaultIndex
|
||||
* @param Index $defaultIndex
|
||||
*/
|
||||
public function __construct(array $indexesByName, \Elastica_Index $defaultIndex)
|
||||
public function __construct(array $indexesByName, Index $defaultIndex)
|
||||
{
|
||||
$this->indexesByName = $indexesByName;
|
||||
$this->defaultIndexName = $defaultIndex->getName();
|
||||
|
@ -33,7 +35,7 @@ class IndexManager
|
|||
* Gets an index by its name
|
||||
*
|
||||
* @param string $name Index to return, or the default index if null
|
||||
* @return \Elastica_Index
|
||||
* @return Index
|
||||
* @throws \InvalidArgumentException if no index exists for the given name
|
||||
*/
|
||||
public function getIndex($name = null)
|
||||
|
@ -52,7 +54,7 @@ class IndexManager
|
|||
/**
|
||||
* Gets the default index
|
||||
*
|
||||
* @return \Elastica_Index
|
||||
* @return Index
|
||||
*/
|
||||
public function getDefaultIndex()
|
||||
{
|
||||
|
|
|
@ -2,35 +2,35 @@
|
|||
|
||||
namespace FOS\ElasticaBundle\Paginator;
|
||||
|
||||
use Elastica_Searchable;
|
||||
use Elastica_Query;
|
||||
use Elastica_ResultSet;
|
||||
use Elastica\SearchableInterface;
|
||||
use Elastica\Query;
|
||||
use Elastica\ResultSet;
|
||||
use FOS\ElasticaBundle\Paginator\PaginatorAdapterInterface;
|
||||
use FOS\ElasticaBundle\Paginator\RawPartialResults;
|
||||
use FOS\ElasticaBundle\Paginator\PartialResultsInterface;
|
||||
|
||||
/**
|
||||
* Allows pagination of Elastica_Query. Does not map results
|
||||
* Allows pagination of Elastica\Query. Does not map results
|
||||
*/
|
||||
class RawPaginatorAdapter implements PaginatorAdapterInterface
|
||||
{
|
||||
/**
|
||||
* @var Elastica_Searchable the object to search in
|
||||
* @var SearchableInterface the object to search in
|
||||
*/
|
||||
private $searchable = null;
|
||||
|
||||
/**
|
||||
* @var Elastica_Query the query to search
|
||||
* @var Query the query to search
|
||||
*/
|
||||
private $query = null;
|
||||
|
||||
/**
|
||||
* @see PaginatorAdapterInterface::__construct
|
||||
*
|
||||
* @param Elastica_Searchable $searchable the object to search in
|
||||
* @param Elastica_Query $query the query to search
|
||||
* @param SearchableInterface $searchable the object to search in
|
||||
* @param Query $query the query to search
|
||||
*/
|
||||
public function __construct(Elastica_Searchable $searchable, Elastica_Query $query)
|
||||
public function __construct(SearchableInterface $searchable, Query $query)
|
||||
{
|
||||
$this->searchable = $searchable;
|
||||
$this->query = $query;
|
||||
|
@ -41,7 +41,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
|
|||
*
|
||||
* @param $offset
|
||||
* @param $itemCountPerPage
|
||||
* @return Elastica_ResultSet
|
||||
* @return ResultSet
|
||||
*/
|
||||
protected function getElasticaResults($offset, $itemCountPerPage)
|
||||
{
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
namespace FOS\ElasticaBundle\Paginator;
|
||||
|
||||
use FOS\ElasticaBundle\Paginator\PartialResultsInterface;
|
||||
use Elastica_ResultSet;
|
||||
use Elastica_Result;
|
||||
use Elastica\ResultSet;
|
||||
use Elastica\Result;
|
||||
|
||||
/**
|
||||
* Raw partial results transforms to a simple array
|
||||
|
@ -14,9 +14,9 @@ class RawPartialResults implements PartialResultsInterface
|
|||
protected $resultSet;
|
||||
|
||||
/**
|
||||
* @param \Elastica_ResultSet $resultSet
|
||||
* @param ResultSet $resultSet
|
||||
*/
|
||||
public function __construct(Elastica_ResultSet $resultSet)
|
||||
public function __construct(ResultSet $resultSet)
|
||||
{
|
||||
$this->resultSet = $resultSet;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class RawPartialResults implements PartialResultsInterface
|
|||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return array_map(function(Elastica_Result $result) {
|
||||
return array_map(function(Result $result) {
|
||||
return $result->getSource();
|
||||
}, $this->resultSet->getResults());
|
||||
}
|
||||
|
|
|
@ -4,22 +4,22 @@ namespace FOS\ElasticaBundle\Paginator;
|
|||
|
||||
use FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface;
|
||||
use FOS\ElasticaBundle\Paginator\TransformedPartialResults;
|
||||
use Elastica_Searchable;
|
||||
use Elastica_Query;
|
||||
use Elastica\SearchableInterface;
|
||||
use Elastica\Query;
|
||||
|
||||
/**
|
||||
* Allows pagination of Elastica_Query
|
||||
* Allows pagination of \Elastica\Query
|
||||
*/
|
||||
class TransformedPaginatorAdapter extends RawPaginatorAdapter
|
||||
{
|
||||
private $transformer;
|
||||
|
||||
/**
|
||||
* @param Elastica_Searchable $searchable the object to search in
|
||||
* @param Elastica_Query $query the query to search
|
||||
* @param SearchableInterface $searchable the object to search in
|
||||
* @param Query $query the query to search
|
||||
* @param ElasticaToModelTransformerInterface $transformer the transformer for fetching the results
|
||||
*/
|
||||
public function __construct(Elastica_Searchable $searchable, Elastica_Query $query, ElasticaToModelTransformerInterface $transformer)
|
||||
public function __construct(SearchableInterface $searchable, Query $query, ElasticaToModelTransformerInterface $transformer)
|
||||
{
|
||||
parent::__construct($searchable, $query);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace FOS\ElasticaBundle\Paginator;
|
|||
|
||||
use FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface;
|
||||
use FOS\ElasticaBundle\Paginator\RawPartialResults;
|
||||
use Elastica_ResultSet;
|
||||
use Elastica\ResultSet;
|
||||
|
||||
/**
|
||||
* Partial transformed result set
|
||||
|
@ -14,10 +14,10 @@ class TransformedPartialResults extends RawPartialResults
|
|||
protected $transformer;
|
||||
|
||||
/**
|
||||
* @param \Elastica_ResultSet $resultSet
|
||||
* @param ResultSet $resultSet
|
||||
* @param \FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface $transformer
|
||||
*/
|
||||
public function __construct(Elastica_ResultSet $resultSet, ElasticaToModelTransformerInterface $transformer)
|
||||
public function __construct(ResultSet $resultSet, ElasticaToModelTransformerInterface $transformer)
|
||||
{
|
||||
parent::__construct($resultSet);
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
namespace FOS\ElasticaBundle\Persister;
|
||||
|
||||
use FOS\ElasticaBundle\Transformer\ModelToElasticaTransformerInterface;
|
||||
use Elastica_Type;
|
||||
use Elastica_Document;
|
||||
use Elastica\Type;
|
||||
use Elastica\Document;
|
||||
|
||||
/**
|
||||
* Inserts, replaces and deletes single documents in an elastica type
|
||||
|
@ -19,7 +19,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
protected $objectClass;
|
||||
protected $fields;
|
||||
|
||||
public function __construct(Elastica_Type $type, ModelToElasticaTransformerInterface $transformer, $objectClass, array $fields)
|
||||
public function __construct(Type $type, ModelToElasticaTransformerInterface $transformer, $objectClass, array $fields)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->transformer = $transformer;
|
||||
|
@ -95,7 +95,7 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
* Transforms an object to an elastica document
|
||||
*
|
||||
* @param object $object
|
||||
* @return Elastica_Document the elastica document
|
||||
* @return Document the elastica document
|
||||
*/
|
||||
public function transformToElasticaDocument($object)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace FOS\ElasticaBundle\Propel;
|
||||
|
||||
use Elastica\Document;
|
||||
use FOS\ElasticaBundle\HybridResult;
|
||||
use FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||
|
@ -65,12 +66,12 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
|
|||
* Transforms an array of elastica objects into an array of
|
||||
* model objects fetched from the propel repository
|
||||
*
|
||||
* @param \Elastica_Document[] $elasticaObjects array of elastica objects
|
||||
* @param Document[] $elasticaObjects array of elastica objects
|
||||
* @return array
|
||||
*/
|
||||
public function transform(array $elasticaObjects)
|
||||
{
|
||||
$ids = array_map(function(\Elastica_Document $elasticaObject) {
|
||||
$ids = array_map(function(Document $elasticaObject) {
|
||||
return $elasticaObject->getId();
|
||||
}, $elasticaObjects);
|
||||
|
||||
|
|
44
README.md
44
README.md
|
@ -64,7 +64,7 @@ Most of the time, you will need only one.
|
|||
Elastica can handle objects instead of data arrays if a serializer callable is configured
|
||||
|
||||
#app/config/config.yml
|
||||
foq_elastica:
|
||||
fos_elastica:
|
||||
clients:
|
||||
default: { host: localhost, port: 9200 }
|
||||
serializer:
|
||||
|
@ -73,12 +73,12 @@ Elastica can handle objects instead of data arrays if a serializer callable is c
|
|||
|
||||
"callback" is the name of a parameter defining a class having a public method serialize($object). "serializer" is the service id for the
|
||||
actual serializer, e.g. 'serializer' if you're using the JMSSerializerBundle. If this is configured you can use
|
||||
Elastica_Type::addObject instead of Elastica_Type::addDocument to add data to the index.
|
||||
\Elastica\Type::addObject instead of \Elastica\Type::addDocument to add data to the index.
|
||||
The bundle provides a default implementation with a serializer service id 'serializer' that can be turned on by adding
|
||||
the following line to your config.
|
||||
|
||||
#app/config/config.yml
|
||||
foq_elastica:
|
||||
fos_elastica:
|
||||
serializer: ~
|
||||
|
||||
#### Declare an index
|
||||
|
@ -98,7 +98,7 @@ Most of the time, you will need only one.
|
|||
|
||||
Here we created a "website" index, that uses our "default" client.
|
||||
|
||||
Our index is now available as a service: `fos_elastica.index.website`. It is an instance of `Elastica_Index`.
|
||||
Our index is now available as a service: `fos_elastica.index.website`. It is an instance of `\Elastica\Index`.
|
||||
|
||||
If you need to have different index name from the service name, for example,
|
||||
in order to have different indexes for different environments then you can
|
||||
|
@ -136,14 +136,14 @@ Elasticsearch type is comparable to Doctrine entity repository.
|
|||
lastName: { boost: 3 }
|
||||
aboutMe: ~
|
||||
|
||||
Our type is now available as a service: `fos_elastica.index.website.user`. It is an instance of `Elastica_Type`.
|
||||
Our type is now available as a service: `fos_elastica.index.website.user`. It is an instance of `\Elastica\Type`.
|
||||
|
||||
### Declaring serializer groups
|
||||
|
||||
If you are using the JMSSerializerBundle for serializing objects passed to elastica you can define serializer groups
|
||||
per type.
|
||||
|
||||
foq_elastica:
|
||||
fos_elastica:
|
||||
clients:
|
||||
default: { host: localhost, port: 9200 }
|
||||
serializer:
|
||||
|
@ -294,13 +294,14 @@ Its class must implement `FOS\ElasticaBundle\Provider\ProviderInterface`.
|
|||
namespace Acme\UserBundle\Provider;
|
||||
|
||||
use FOS\ElasticaBundle\Provider\ProviderInterface;
|
||||
use Elastica_Type;
|
||||
use Elastica\Type;
|
||||
use Elastica\Document;
|
||||
|
||||
class UserProvider implements ProviderInterface
|
||||
{
|
||||
protected $userType;
|
||||
|
||||
public function __construct(Elastica_Type $userType)
|
||||
public function __construct(Type $userType)
|
||||
{
|
||||
$this->userType = $userType;
|
||||
}
|
||||
|
@ -316,7 +317,7 @@ Its class must implement `FOS\ElasticaBundle\Provider\ProviderInterface`.
|
|||
$loggerClosure('Indexing users');
|
||||
}
|
||||
|
||||
$document = new \Elastica_Document();
|
||||
$document = new Document();
|
||||
$document->setData(array('username' => 'Bob'));
|
||||
$this->userType->addDocuments(array($document));
|
||||
}
|
||||
|
@ -328,10 +329,10 @@ You will find a more complete implementation example in `src/FOS/ElasticaBundle/
|
|||
|
||||
You can just use the index and type Elastica objects, provided as services, to perform searches.
|
||||
|
||||
/** var Elastica_Type */
|
||||
/** var Elastica\Type */
|
||||
$userType = $this->container->get('fos_elastica.index.website.user');
|
||||
|
||||
/** var Elastica_ResultSet */
|
||||
/** var Elastica\ResultSet */
|
||||
$resultSet = $userType->search('bob');
|
||||
|
||||
#### Doctrine/Propel finder
|
||||
|
@ -383,7 +384,7 @@ Knp paginator:
|
|||
$userPaginator = $paginator->paginate($finder->createPaginatorAdapter('bob'));
|
||||
|
||||
You can also get both the Elastica results and the entities together from the finder.
|
||||
You can then access the score, highlights etc. from the Elastica_Result whilst
|
||||
You can then access the score, highlights etc. from the Elastica\Result whilst
|
||||
still also getting the entity.
|
||||
|
||||
/** var array of FOS\ElasticaBundle\HybridResult */
|
||||
|
@ -393,7 +394,7 @@ still also getting the entity.
|
|||
/** var Acme\UserBundle\Entity\User */
|
||||
$user = $hybridResult->getTransformed();
|
||||
|
||||
/** var Elastica_Result */
|
||||
/** var Elastica\Result */
|
||||
$result = $hybridResult->getResult();
|
||||
}
|
||||
|
||||
|
@ -628,7 +629,7 @@ Any setting can be specified when declaring a type. For example, to enable a cus
|
|||
|
||||
By default, exceptions from the Elastica client library will propagate through
|
||||
the bundle's Client class. For instance, if the elasticsearch server is offline,
|
||||
issuing a request will result in an `Elastica_Exception_Client` being thrown.
|
||||
issuing a request will result in an `Elastica\Exception\Connection` being thrown.
|
||||
Depending on your needs, it may be desirable to suppress these exceptions and
|
||||
allow searches to fail silently.
|
||||
|
||||
|
@ -644,14 +645,17 @@ namespace Acme\ElasticaBundle;
|
|||
|
||||
use FOS\ElasticaBundle\Client as BaseClient;
|
||||
|
||||
use Elastica\Exception\AbstractException;
|
||||
use Elastica\Response;
|
||||
|
||||
class Client extends BaseClient
|
||||
{
|
||||
public function request($path, $method, $data = array())
|
||||
{
|
||||
try {
|
||||
return parent::request($path, $method, $data);
|
||||
} catch (\Elastica_Exception_Abstract $e) {
|
||||
return new \Elastica_Response('{"took":0,"timed_out":false,"hits":{"total":0,"max_score":0,"hits":[]}}');
|
||||
} catch (AbstractException $e) {
|
||||
return new Response('{"took":0,"timed_out":false,"hits":{"total":0,"max_score":0,"hits":[]}}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -669,18 +673,18 @@ apply to queries against the `title` field.
|
|||
|
||||
```php
|
||||
$finder = $this->container->get('fos_elastica.finder.website.article');
|
||||
$boolQuery = new \Elastica_Query_Bool();
|
||||
$boolQuery = new \Elastica\Query\Bool();
|
||||
|
||||
$fieldQuery = new \Elastica_Query_Text();
|
||||
$fieldQuery = new \Elastica\Query\Text();
|
||||
$fieldQuery->setFieldQuery('title', 'I am a title string');
|
||||
$fieldQuery->setFieldParam('title', 'analyzer', 'my_analyzer');
|
||||
$boolQuery->addShould($fieldQuery);
|
||||
|
||||
$tagsQuery = new \Elastica_Query_Terms();
|
||||
$tagsQuery = new \Elastica\Query\Terms();
|
||||
$tagsQuery->setTerms('tags', array('tag1', 'tag2'));
|
||||
$boolQuery->addShould($tagsQuery);
|
||||
|
||||
$categoryQuery = new \Elastica_Query_Terms();
|
||||
$categoryQuery = new \Elastica\Query\Terms();
|
||||
$categoryQuery->setTerms('categoryIds', array('1', '2', '3'));
|
||||
$boolQuery->addMust($categoryQuery);
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace FOS\ElasticaBundle;
|
||||
|
||||
use Elastica\Type\Mapping;
|
||||
|
||||
/**
|
||||
* Deletes and recreates indexes
|
||||
*/
|
||||
|
@ -66,11 +68,11 @@ class Resetter
|
|||
* create type mapping object
|
||||
*
|
||||
* @param array $indexConfig
|
||||
* @return \Elastica_Type_Mapping
|
||||
* @return Mapping
|
||||
*/
|
||||
protected function createMapping($indexConfig)
|
||||
{
|
||||
$mapping = \Elastica_Type_Mapping::create($indexConfig['properties']);
|
||||
$mapping = Mapping::create($indexConfig['properties']);
|
||||
|
||||
foreach($indexConfig['properties'] as $type) {
|
||||
if (!empty($type['_parent']) && $type['_parent'] !== '~') {
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
|
||||
<parameters>
|
||||
<parameter key="fos_elastica.client.class">FOS\ElasticaBundle\Client</parameter>
|
||||
<parameter key="fos_elastica.index.class">Elastica_Index</parameter>
|
||||
<parameter key="fos_elastica.type.class">Elastica_Type</parameter>
|
||||
<parameter key="fos_elastica.index.class">Elastica\Index</parameter>
|
||||
<parameter key="fos_elastica.type.class">Elastica\Type</parameter>
|
||||
<parameter key="fos_elastica.logger.class">FOS\ElasticaBundle\Logger\ElasticaLogger</parameter>
|
||||
<parameter key="fos_elastica.data_collector.class">FOS\ElasticaBundle\DataCollector\ElasticaDataCollector</parameter>
|
||||
<parameter key="fos_elastica.manager.class">FOS\ElasticaBundle\Manager\RepositoryManager</parameter>
|
||||
<parameter key="fos_elastica.elastica_to_model_transformer.collection.class">FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerCollection</parameter>
|
||||
<parameter key="fos_elastica.provider_registry.class">FOS\ElasticaBundle\Provider\ProviderRegistry</parameter>
|
||||
<parameter key="fos_elastica.property_accessor.class">Symfony\Component\PropertyAccess\PropertyAccessor</parameter>
|
||||
<parameter key="foq_elastica.serializer.callback.class">FOQ\ElasticaBundle\Serializer\Callback</parameter>
|
||||
<parameter key="fos_elastica.serializer.callback.class">FOS\ElasticaBundle\Serializer\Callback</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace FOQ\ElasticaBundle\Serializer;
|
||||
namespace FOS\ElasticaBundle\Serializer;
|
||||
|
||||
use JMS\Serializer\SerializationContext;
|
||||
use JMS\Serializer\Serializer;
|
||||
|
||||
class Callback
|
||||
|
@ -10,6 +11,8 @@ class Callback
|
|||
|
||||
protected $groups;
|
||||
|
||||
protected $version;
|
||||
|
||||
public function setSerializer($serializer)
|
||||
{
|
||||
$this->serializer = $serializer;
|
||||
|
@ -20,14 +23,31 @@ class Callback
|
|||
$this->groups = $groups;
|
||||
}
|
||||
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
public function serialize($object)
|
||||
{
|
||||
if ($this->serializer instanceof Serializer) {
|
||||
$this->serializer->setGroups($this->groups);
|
||||
} elseif ($this->groups) {
|
||||
throw new \RuntimeException('Setting serialization groups requires using "JMS\Serializer\Serializer"');
|
||||
$context = $this->serializer instanceof Serializer ? new SerializationContext() : null;
|
||||
|
||||
if ($this->groups) {
|
||||
if (!$context) {
|
||||
throw new \RuntimeException('Setting serialization groups requires using "JMS\Serializer\Serializer"');
|
||||
}
|
||||
|
||||
$context->setGroups($this->groups);
|
||||
}
|
||||
|
||||
return $this->serializer->serialize($object, 'json');
|
||||
if ($this->version) {
|
||||
if (!$context) {
|
||||
throw new \RuntimeException('Setting serialization version requires using "JMS\Serializer\Serializer"');
|
||||
}
|
||||
|
||||
$context->setVersion($this->version);
|
||||
}
|
||||
|
||||
return $this->serializer->serialize($object, 'json', $context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ class IndexManagerTest extends \PHPUnit_Framework_TestCase
|
|||
'index2' => 'test2',
|
||||
);
|
||||
|
||||
/** @var $defaultIndex \PHPUnit_Framework_MockObject_MockObject|\Elastica_Index */
|
||||
$defaultIndex = $this->getMockBuilder('Elastica_Index')
|
||||
/** @var $defaultIndex \PHPUnit_Framework_MockObject_MockObject|\Elastica\Index */
|
||||
$defaultIndex = $this->getMockBuilder('Elastica\Index')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!class_exists('Elastica_Type')) {
|
||||
if (!class_exists('Elastica\Type')) {
|
||||
$this->markTestSkipped('The Elastica library classes are not available');
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica_Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica_Type')
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica\Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica\Type')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$typeMock->expects($this->once())
|
||||
|
@ -65,8 +65,8 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica_Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica_Type')
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica\Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica\Type')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$typeMock->expects($this->never())
|
||||
|
@ -84,8 +84,8 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica_Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica_Type')
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica\Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica\Type')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$typeMock->expects($this->never())
|
||||
|
@ -106,8 +106,8 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica_Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica_Type')
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica\Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica\Type')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$typeMock->expects($this->never())
|
||||
|
@ -125,8 +125,8 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica_Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica_Type')
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica\Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica\Type')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$typeMock->expects($this->once())
|
||||
|
@ -147,8 +147,8 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica_Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica_Type')
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica\Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica\Type')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$typeMock->expects($this->never())
|
||||
|
@ -166,8 +166,8 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica_Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica_Type')
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica\Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica\Type')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$typeMock->expects($this->never())
|
||||
|
@ -190,8 +190,8 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$transformer = $this->getTransformer();
|
||||
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica_Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica_Type')
|
||||
/** @var $typeMock \PHPUnit_Framework_MockObject_MockObject|\Elastica\Type */
|
||||
$typeMock = $this->getMockBuilder('Elastica\Type')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$typeMock->expects($this->never())
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace FOS\ElasticaBundle\Tests\Resetter;
|
||||
|
||||
use FOS\ElasticaBundle\Resetter;
|
||||
use Elastica\Type\Mapping;
|
||||
|
||||
class ResetterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -91,7 +92,7 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
|||
$type->expects($this->once())
|
||||
->method('delete');
|
||||
|
||||
$mapping = \Elastica_Type_Mapping::create($this->indexConfigsByName['foo']['config']['mappings']['a']['properties']);
|
||||
$mapping = Mapping::create($this->indexConfigsByName['foo']['config']['mappings']['a']['properties']);
|
||||
$type->expects($this->once())
|
||||
->method('setMapping')
|
||||
->with($mapping);
|
||||
|
@ -130,7 +131,7 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
|||
$type->expects($this->once())
|
||||
->method('delete');
|
||||
|
||||
$mapping = \Elastica_Type_Mapping::create($this->indexConfigsByName['parent']['config']['mappings']['a']['properties']);
|
||||
$mapping = Mapping::create($this->indexConfigsByName['parent']['config']['mappings']['a']['properties']);
|
||||
$mapping->setParam('_parent', array('type' => 'b'));
|
||||
$type->expects($this->once())
|
||||
->method('setMapping')
|
||||
|
@ -141,21 +142,21 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @return \Elastica_Index
|
||||
* @return \Elastica\Index
|
||||
*/
|
||||
private function getMockElasticaIndex()
|
||||
{
|
||||
return $this->getMockBuilder('Elastica_Index')
|
||||
return $this->getMockBuilder('Elastica\Index')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Elastica_Type
|
||||
* @return \Elastica\Type
|
||||
*/
|
||||
private function getMockElasticaType()
|
||||
{
|
||||
return $this->getMockBuilder('Elastica_Type')
|
||||
return $this->getMockBuilder('Elastica\Type')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace FOS\ElasticaBundle\Tests\Transformer;
|
||||
|
||||
use Elastica\Document;
|
||||
use FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerCollection;
|
||||
|
||||
class ElasticaToModelTransformerCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
|
@ -53,8 +54,8 @@ class ElasticaToModelTransformerCollectionTest extends \PHPUnit_Framework_TestCa
|
|||
{
|
||||
$this->collectionSetup();
|
||||
|
||||
$document1 = new \Elastica_Document(123, array('data' => 'lots of data'), 'type1');
|
||||
$document2 = new \Elastica_Document(124, array('data' => 'not so much data'), 'type2');
|
||||
$document1 = new Document(123, array('data' => 'lots of data'), 'type1');
|
||||
$document2 = new Document(124, array('data' => 'not so much data'), 'type2');
|
||||
$result1 = new POPO(123, 'lots of data');
|
||||
$result2 = new POPO2(124, 'not so much data');
|
||||
|
||||
|
@ -80,8 +81,8 @@ class ElasticaToModelTransformerCollectionTest extends \PHPUnit_Framework_TestCa
|
|||
{
|
||||
$this->collectionSetup();
|
||||
|
||||
$document1 = new \Elastica_Document(123, array('data' => 'lots of data'), 'type1');
|
||||
$document2 = new \Elastica_Document(124, array('data' => 'not so much data'), 'type1');
|
||||
$document1 = new Document(123, array('data' => 'lots of data'), 'type1');
|
||||
$document2 = new Document(124, array('data' => 'not so much data'), 'type1');
|
||||
$result1 = new POPO(123, 'lots of data');
|
||||
$result2 = new POPO2(124, 'not so much data');
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!class_exists('Elastica_Document')) {
|
||||
if (!class_exists('Elastica\Document')) {
|
||||
;
|
||||
$this->markTestSkipped('The Elastica library classes are not available');
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
$document = $transformer->transform(new POPO(), array('name' => array()));
|
||||
$data = $document->getData();
|
||||
|
||||
$this->assertInstanceOf('Elastica_Document', $document);
|
||||
$this->assertInstanceOf('Elastica\Document', $document);
|
||||
$this->assertEquals(123, $document->getId());
|
||||
$this->assertEquals('someName', $data['name']);
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
|
|||
);
|
||||
$data = $document->getData();
|
||||
|
||||
$this->assertInstanceOf('Elastica_Document', $document);
|
||||
$this->assertInstanceOf('Elastica\Document', $document);
|
||||
$this->assertEquals(123, $document->getId());
|
||||
$this->assertEquals('someName', $data['name']);
|
||||
$this->assertEquals(7.2, $data['float']);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace FOS\ElasticaBundle\Transformer;
|
||||
|
||||
use FOS\ElasticaBundle\HybridResult;
|
||||
use Elastica_Document;
|
||||
use Elastica\Document;
|
||||
|
||||
/**
|
||||
* Holds a collection of transformers for an index wide transformation.
|
||||
|
@ -40,7 +40,7 @@ class ElasticaToModelTransformerCollection implements ElasticaToModelTransformer
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Elastica_Document[] $elasticaObjects
|
||||
* @param Document[] $elasticaObjects
|
||||
* @return array
|
||||
*/
|
||||
public function transform(array $elasticaObjects)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace FOS\ElasticaBundle\Transformer;
|
||||
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||
use Elastica\Document;
|
||||
|
||||
/**
|
||||
* Maps Elastica documents with Doctrine objects
|
||||
|
@ -53,12 +54,12 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
* @param object $object the object to convert
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
*
|
||||
* @return \Elastica_Document
|
||||
* @return Document
|
||||
**/
|
||||
public function transform($object, array $fields)
|
||||
{
|
||||
$identifier = $this->propertyAccessor->getValue($object, $this->options['identifier']);
|
||||
$document = new \Elastica_Document($identifier);
|
||||
$document = new Document($identifier);
|
||||
|
||||
foreach ($fields as $key => $mapping) {
|
||||
$value = $this->propertyAccessor->getValue($object, $key);
|
||||
|
|
|
@ -12,7 +12,7 @@ interface ModelToElasticaTransformerInterface
|
|||
*
|
||||
* @param object $object the object to convert
|
||||
* @param array $fields the keys we want to have in the returned array
|
||||
* @return \Elastica_Document
|
||||
* @return \Elastica\Document
|
||||
**/
|
||||
function transform($object, array $fields);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
"symfony/console": ">=2.1.0,<2.3.0-dev",
|
||||
"symfony/form": ">=2.1.0,<2.3.0-dev",
|
||||
"symfony/property-access": "2.2.*",
|
||||
"ruflin/elastica": "0.19.8"
|
||||
"ruflin/elastica": "dev-master"
|
||||
},
|
||||
"require-dev":{
|
||||
"doctrine/orm": ">=2.2,<2.5-dev",
|
||||
|
|
Loading…
Reference in a new issue