Exemple #1
0
    /**
     * Transforms given objects into a bulk delete operation
     *
     * @param ClassMetadata $metadata
     * @param array $objects
     * @return array bulk commands
     */
    public function createBulk(ClassMetadata $metadata, array $objects)
    {
        $index = $metadata->getIndex();

        $idGetter = 'get' . self::camelize($index->getIdProperty());
        $map = array();
        foreach ($objects as $object) {
            $map[] = array('delete' => array('_index' => $index->getName(), '_type' => $metadata->getClassName(), '_id' => $object->$idGetter()));
        }

        return $map;
    }
Exemple #2
0
    /**
     * Transforms object metadata into a mapping definition
     *
     * @param ClassMetadata $metadata
     */
    public function createSchema(ClassMetadata $metadata)
    {
        $index = $metadata->getIndex();

        $settings = array('number_of_shards' => $index->getNumberOfShards(), 'number_of_replicas' => $index->getNumberOfReplicas());

        $type = $metadata->getClassName();
        $mappings = array($type => array('properties' => array()));
        $mappings[$type]['properties'] = $this->exportProperties($metadata);

        return array('settings' => $settings, 'mappings' => $mappings);
    }
Exemple #3
0
    /**
     * Transform the raw http response into a Generic Result object
     *
     * @param Response $response
     * @param ClassMetadata $metadata
     * @return Result
     */
    public function mapResult(Response $response, ClassMetadata $metadata)
    {
        $className = $metadata->getClassName();
        $result = new Result();
        $foreign = json_decode($response->getBody());

        $result->setTotal($foreign->hits->total);
        foreach ($foreign->hits->hits as $foreignHit) {
            $hit = new Hit();
            $hit->setScore($foreignHit->_score);
            $hit->setDocument($foreignHit->_source);
            $result->getHits()->add($hit);
        }

        return $result;
    }
Exemple #4
0
    /**
     * @test
     * @cover ClassMetadata::__construct
     */
    public function testConstructor()
    {
        $meta = new ClassMetadata('foo');

        $this->assertEquals('foo', $meta->getClassName(), 'constructor set the class name property');
    }
Exemple #5
0
    /**
     * Transform the raw http response into a Generic Result object
     *
     * @param Response $response
     * @param ClassMetadata $metadata
     * @return Result
     */
    public function mapResult(array $foreignResult, ClassMetadata $metadata, $query)
    {
        $className = $metadata->getClassName();

        $result = new Result();

        $result->setTotal(count($foreignResult));

        $foreignResult = array_slice($foreignResult, $query->getOffset(), $query->getLimit());

        foreach ($foreignResult as $foreignHit) {

            $hit = new Hit();
            $hit->setScore($foreignHit->score);
            $hit->setDocument(json_decode($foreignHit->_doc));
            $result->getHits()->add($hit);
        }

        return $result;
    }