diff --git a/src/Query/FuzzyLikeThisQuery.php b/src/Query/FuzzyLikeThisQuery.php index c19c36be0858aa789d646b45f72b5d70f14ecb55..af2ff21c6a910bcb0c36bbe76f3d1c8e6f6ba6e9 100644 --- a/src/Query/FuzzyLikeThisQuery.php +++ b/src/Query/FuzzyLikeThisQuery.php @@ -32,12 +32,16 @@ class FuzzyLikeThisQuery implements BuilderInterface private $likeText; /** - * @param string[] $fields - * @param string $likeText - * @param array $parameters + * @param string|string[] $fields + * @param string $likeText + * @param array $parameters */ - public function __construct(array $fields, $likeText, array $parameters = []) + public function __construct($fields, $likeText, array $parameters = []) { + if (!is_array($fields)) { + $fields = [$fields]; + } + $this->fields = $fields; $this->likeText = $likeText; $this->setParameters($parameters); diff --git a/tests/Query/FuzzyLikeThisQueryTest.php b/tests/Query/FuzzyLikeThisQueryTest.php index 32e193ab968b441c2ab4c1fa55b89ee6fd0cbefb..3563b6455f9fee75c1e1a16398b40ce3eef6b583 100644 --- a/tests/Query/FuzzyLikeThisQueryTest.php +++ b/tests/Query/FuzzyLikeThisQueryTest.php @@ -52,4 +52,25 @@ class FuzzyLikeThisQueryTest extends \PHPUnit_Framework_TestCase $this->assertEquals('fuzzy_like_this', $fuzzyLikeThisQuery->getType()); } + + /** + * Tests if query accepts single field as string. + */ + public function testSingleField() + { + $fuzzyLikeThisQuery = new FuzzyLikeThisQuery( + 'name.first', + 'text like this one', + [ 'max_query_terms' => 12 ] + ); + + $this->assertSame( + [ + 'fields' => ['name.first'], + 'like_text' => 'text like this one', + 'max_query_terms' => 12, + ], + $fuzzyLikeThisQuery->toArray() + ); + } }