yii\elasticsearch\Query::search PHP Method

    public function search($db = null, $options = [])
    {
        $result = $this->createCommand($db)->search($options);
        if (!empty($result['hits']['hits']) && $this->indexBy !== null) {
            $rows = [];
            foreach ($result['hits']['hits'] as $key => $row) {
                if (is_string($this->indexBy)) {
                    $key = isset($row['fields'][$this->indexBy]) ? $row['fields'][$this->indexBy] : $row['_source'][$this->indexBy];
                } else {
                    $key = call_user_func($this->indexBy, $row);
                }
                $rows[$key] = $row;
            }
            $result['hits']['hits'] = $rows;
        }
        return $result;
    }

Usage Example

Ejemplo n.º 1
1
 public function testFuzzySearch()
 {
     $this->prepareDbData();
     $queryParts = ["fuzzy_like_this" => ["fields" => ["title"], "like_text" => "Similar to YII", "max_query_terms" => 4]];
     $query = new Query();
     $query->from('yiitest', 'article');
     $query->query = $queryParts;
     $result = $query->search($this->getConnection());
     $this->assertEquals(3, $result['hits']['total']);
 }