yii\elasticsearch\Query::populate PHP Method

populate() public method

This method is internally used to convert the data fetched from database into the format as required by this query.
Since: 2.0.4
public populate ( array $rows ) : array
$rows array the raw query result from database
return array the converted query result
    public function populate($rows)
    {
        if ($this->indexBy === null) {
            return $rows;
        }
        $models = [];
        foreach ($rows as $key => $row) {
            if ($this->indexBy !== null) {
                if (is_string($this->indexBy)) {
                    $key = isset($row['fields'][$this->indexBy]) ? reset($row['fields'][$this->indexBy]) : $row['_source'][$this->indexBy];
                } else {
                    $key = call_user_func($this->indexBy, $row);
                }
            }
            $models[$key] = $row;
        }
        return $models;
    }