diff --git a/src/Suggest/CompletionSuggest.php b/src/Suggest/CompletionSuggest.php index 74d9828abddab2e08ea2070b5dd41a8987f1f6d9..5219d7b80bc24aa3939c93f053c8daaf07c7f43b 100644 --- a/src/Suggest/CompletionSuggest.php +++ b/src/Suggest/CompletionSuggest.php @@ -62,7 +62,9 @@ class CompletionSuggest implements BuilderInterface */ public function toArray() { - $this->addParameter('field', 'suggest'); + if (!$this->hasParameter('field')) { + $this->addParameter('field', 'suggest'); + } if (!$this->hasParameter('size')) { $this->addParameter('size', self::DEFAULT_SIZE); diff --git a/tests/Suggest/CompletionSuggestTest.php b/tests/Suggest/CompletionSuggestTest.php index 322a23360c2bd8398c1fe43feeffc4b7ad28d972..8e4ce8c79daf0ae0b83f061ce004be5be4eb6083 100644 --- a/tests/Suggest/CompletionSuggestTest.php +++ b/tests/Suggest/CompletionSuggestTest.php @@ -56,6 +56,27 @@ class CompletionSuggestTest extends \PHPUnit_Framework_TestCase 'fuzzy' => ['fuzziness' => 2] ] ); + $expected = ['foo' => [ + 'text' => 'bar', + 'completion' => [ + 'field' => 'title', + 'size' => 5, + 'fuzzy' => ['fuzziness' => 2] + ], + ]]; + $this->assertEquals($expected, $suggest->toArray()); + } + + public function testToArrayWithoutField() + { + $suggest = new CompletionSuggest( + 'foo', + 'bar', + [ + 'size' => 5, + 'fuzzy' => ['fuzziness' => 2] + ] + ); $expected = ['foo' => [ 'text' => 'bar', 'completion' => [