Beispiel #1
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;
    }
Beispiel #2
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;
    }