Skip to content
Snippets Groups Projects
Commit 54d51b6b authored by Aivaras Gotovskis's avatar Aivaras Gotovskis
Browse files

Fix FuzzyLikeThisQuery to return correct format.

parent 9582224e
Branches
No related tags found
No related merge requests found
......@@ -11,11 +11,38 @@
namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch fuzzy_like_this query class.
*/
class FuzzyLikeThisQuery extends FuzzyLikeThisFieldQuery
class FuzzyLikeThisQuery implements BuilderInterface
{
use ParametersTrait;
/**
* @var string[]
*/
private $fields;
/**
* @var string
*/
private $likeText;
/**
* @param string[] $fields
* @param string $likeText
* @param array $parameters
*/
public function __construct(array $fields, $likeText, array $parameters = [])
{
$this->fields = $fields;
$this->likeText = $likeText;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
......@@ -23,4 +50,17 @@ class FuzzyLikeThisQuery extends FuzzyLikeThisFieldQuery
{
return 'fuzzy_like_this';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$output = [
'fields' => $this->fields,
'like_text' => $this->likeText,
];
return $this->processArray($output);
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Tests\Unit\DSL\Query;
use ONGR\ElasticsearchDSL\Query\FuzzyLikeThisQuery;
/**
* Class FuzzyLikeThisQueryTest.
*/
class FuzzyLikeThisQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests if toArray returns data in correct format with right data from constructor.
*/
public function testQuery()
{
$fuzzyLikeThisQuery = new FuzzyLikeThisQuery(
['name.first', 'name.last'],
'text like this one',
[ 'max_query_terms' => 12 ]
);
$this->assertSame(
[
'fields' => ['name.first', 'name.last'],
'like_text' => 'text like this one',
'max_query_terms' => 12,
],
$fuzzyLikeThisQuery->toArray()
);
}
/**
* Tests if correct type is returned.
*/
public function testGetType()
{
/** @var FuzzyLikeThisQuery $fuzzyLikeThisQuery */
$fuzzyLikeThisQuery = $this->getMockBuilder('ONGR\ElasticsearchDSL\Query\FuzzyLikeThisQuery')
->disableOriginalConstructor()
->setMethods(null)
->getMock();
$this->assertEquals('fuzzy_like_this', $fuzzyLikeThisQuery->getType());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment