FOSElasticaBundle/Elastica/TransformingIndex.php

59 lines
1.6 KiB
PHP
Raw Normal View History

2014-04-21 01:21:50 +02:00
<?php
2014-04-25 13:31:04 +02:00
namespace FOS\ElasticaBundle\Elastica;
2014-04-21 01:21:50 +02:00
2014-04-25 13:31:04 +02:00
use Elastica\Client;
use Elastica\Exception\InvalidException;
2014-04-21 01:21:50 +02:00
use Elastica\Index;
2014-04-25 13:31:04 +02:00
use FOS\ElasticaBundle\Transformer\CombinedResultTransformer;
2014-04-21 01:21:50 +02:00
/**
* Overridden Elastica Index class that provides dynamic index name changes
* and returns our own ResultSet instead of the Elastica ResultSet.
*
* @author Konstantin Tjuterev <kostik.lv@gmail.com>
* @author Tim Nagel <tim@nagel.com.au>
*/
class TransformingIndex extends Index
{
/**
2014-04-25 13:31:04 +02:00
* Creates a TransformingSearch instance instead of the default Elastica Search
*
* @param string $query
* @param int|array $options
* @return TransformingSearch
2014-04-21 01:21:50 +02:00
*/
public function createSearch($query = '', $options = null)
{
2014-04-25 13:31:04 +02:00
$search = new TransformingSearch($this->getClient());
2014-04-21 01:21:50 +02:00
$search->addIndex($this);
$search->setOptionsAndQuery($options, $query);
return $search;
}
2014-04-25 13:31:04 +02:00
/**
* Returns a type object for the current index with the given name
*
* @param string $type Type name
* @return TransformingType Type object
*/
public function getType($type)
{
return new TransformingType($this, $type);
}
2014-04-21 01:21:50 +02:00
/**
* Reassign index name
*
* While it's technically a regular setter for name property, it's specifically named overrideName, but not setName
* since it's used for a very specific case and normally should not be used
*
* @param string $name Index name
*/
public function overrideName($name)
{
$this->_name = $name;
}
}