Elastica\Query\MoreLikeThis::toArray PHP Method

toArray() public method

public toArray ( )
    public function toArray()
    {
        $array = parent::toArray();
        // If _id is provided, perform MLT on an existing document from the index
        // If _source is provided, perform MLT on a document provided as an input
        if (!empty($array['more_like_this']['like']['_id'])) {
            $doc = $array['more_like_this']['like'];
            $doc = array_intersect_key($doc, ['_index' => 1, '_type' => 1, '_id' => 1]);
            $array['more_like_this']['like'] = $doc;
        } elseif (!empty($array['more_like_this']['like']['_source'])) {
            $doc = $array['more_like_this']['like'];
            $doc['doc'] = $array['more_like_this']['like']['_source'];
            unset($doc['_id']);
            unset($doc['_source']);
            $array['more_like_this']['like'] = $doc;
        }
        return $array;
    }

Usage Example

 /**
  * @group unit
  */
 public function testSetLikeText()
 {
     $query = new MoreLikeThis();
     $query->setLikeText(' hello world');
     $data = $query->toArray();
     $this->assertEquals('hello world', $data['more_like_this']['like_text']);
 }
All Usage Examples Of Elastica\Query\MoreLikeThis::toArray