Skip to content

Commit

Permalink
Merge pull request #70 from einorler/Suggest
Browse files Browse the repository at this point in the history
changed Suggest to TermSuggest
  • Loading branch information
saimaz committed Mar 2, 2016
2 parents 3be0fa1 + e53cdf9 commit cfc67dd
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,11 @@ public function getHighlight()
/**
* Adds suggest into search.
*
* @param Suggest $suggest
* @param BuilderInterface $suggest
*
* @return $this
*/
public function addSuggest(Suggest $suggest)
public function addSuggest(BuilderInterface $suggest)
{
$this->getEndpoint(SuggestEndpoint::NAME)->add($suggest, $suggest->getName());

Expand Down
6 changes: 3 additions & 3 deletions src/SearchEndpoint/SuggestEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace ONGR\ElasticsearchDSL\SearchEndpoint;

use ONGR\ElasticsearchDSL\Suggest\Suggest;
use ONGR\ElasticsearchDSL\Suggest\TermSuggest;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
Expand All @@ -31,9 +31,9 @@ public function normalize(NormalizerInterface $normalizer, $format = null, array
{
$output = [];
if (count($this->getAll()) > 0) {
/** @var Suggest $suggest */
/** @var TermSuggest $suggest */
foreach ($this->getAll() as $suggest) {
$output[$suggest->getName()] = $suggest->toArray();
$output = array_merge($output, $suggest->toArray());
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Suggest/Suggest.php → src/Suggest/TermSuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;

class Suggest implements BuilderInterface
class TermSuggest implements BuilderInterface
{
use ParametersTrait;

Expand Down Expand Up @@ -44,7 +44,7 @@ public function __construct($name, $text, $parameters = [])
*/
public function getType()
{
return 'suggest';
return 'term_suggest';
}

/**
Expand All @@ -70,10 +70,10 @@ public function toArray()
$this->addParameter('size', self::DEFAULT_SIZE);
}

$output = [
$output = [$this->name => [
'text' => $this->text,
'term' => $this->getParameters(),
];
]];

return $output;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/SearchEndpoint/SuggestEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint;

use ONGR\ElasticsearchDSL\SearchEndpoint\SuggestEndpoint;
use ONGR\ElasticsearchDSL\Suggest\Suggest;
use ONGR\ElasticsearchDSL\Suggest\TermSuggest;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

Expand All @@ -33,7 +33,7 @@ public function testEndpointGetter()
{
$suggestName = 'acme_suggest';
$text = 'foo';
$suggest = new Suggest($suggestName, $text);
$suggest = new TermSuggest($suggestName, $text);
$endpoint = new SuggestEndpoint();
$endpoint->add($suggest, $suggestName);
$builders = $endpoint->getAll();
Expand All @@ -54,11 +54,11 @@ public function testNormalize()
'Symfony\Component\Serializer\Normalizer\NormalizerInterface'
);

$suggest = new Suggest('foo', 'bar');
$suggest = new TermSuggest('foo', 'bar');
$instance->add($suggest);

$this->assertEquals(
['foo' => $suggest->toArray()],
$suggest->toArray(),
$instance->normalize($normalizerInterface)
);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use ONGR\ElasticsearchDSL\Query\TermQuery;
use ONGR\ElasticsearchDSL\Search;
use ONGR\ElasticsearchDSL\Sort\FieldSort;
use ONGR\ElasticsearchDSL\Suggest\Suggest;
use ONGR\ElasticsearchDSL\Suggest\TermSuggest;

/**
* Test for Search.
Expand Down Expand Up @@ -266,7 +266,7 @@ public function getTestToArrayData()
],
],
],
(new Search())->addSuggest(new Suggest('foo', 'bar', ['field' => 'title', 'size' => 2])),
(new Search())->addSuggest(new TermSuggest('foo', 'bar', ['field' => 'title', 'size' => 2])),
];

$cases['multiple_suggests'] = [
Expand All @@ -283,8 +283,8 @@ public function getTestToArrayData()
],
],
(new Search())
->addSuggest(new Suggest('foo', 'bar', ['field' => 'title', 'size' => 2]))
->addSuggest(new Suggest('bar', 'foo', ['field' => 'title', 'size' => 2])),
->addSuggest(new TermSuggest('foo', 'bar', ['field' => 'title', 'size' => 2]))
->addSuggest(new TermSuggest('bar', 'foo', ['field' => 'title', 'size' => 2])),
];

return $cases;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace ONGR\ElasticsearchDSL\Tests\Suggest;

use ONGR\ElasticsearchDSL\Suggest\Suggest;
use ONGR\ElasticsearchDSL\Suggest\TermSuggest;

class SuggestTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -20,9 +20,9 @@ class SuggestTest extends \PHPUnit_Framework_TestCase
*/
public function testSuggestGetType()
{
$suggest = new Suggest('foo', 'bar');
$suggest = new TermSuggest('foo', 'bar');
$result = $suggest->getType();
$this->assertEquals('suggest', $result);
$this->assertEquals('term_suggest', $result);
}

/**
Expand All @@ -31,14 +31,14 @@ public function testSuggestGetType()
public function testSuggestWithoutFieldAndSize()
{
// Case #1 suggest without field and size params.
$suggest = new Suggest('foo', 'bar');
$expected = [
$suggest = new TermSuggest('foo', 'bar');
$expected = ['foo' => [
'text' => 'bar',
'term' => [
'field' => '_all',
'size' => 3,
],
];
]];
$this->assertEquals($expected, $suggest->toArray());
}

Expand All @@ -47,7 +47,7 @@ public function testSuggestWithoutFieldAndSize()
*/
public function testToArray()
{
$suggest = new Suggest(
$suggest = new TermSuggest(
'foo',
'bar',
[
Expand All @@ -56,14 +56,14 @@ public function testToArray()
'analyzer' => 'whitespace',
]
);
$expected = [
$expected = ['foo' => [
'text' => 'bar',
'term' => [
'field' => 'title',
'size' => 5,
'analyzer' => 'whitespace',
],
];
]];
$this->assertEquals($expected, $suggest->toArray());
}
}

0 comments on commit cfc67dd

Please sign in to comment.