Skip to content

Commit

Permalink
support elasticsearch-bundle 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Simonas Šerlinskas committed Feb 7, 2017
1 parent cf2166d commit 8804aa4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Document/SeoAwareTrait.php
Expand Up @@ -21,7 +21,7 @@ trait SeoAwareTrait
/**
* @var string URL.
*
* @ES\Property(name="url", type="string", options={"analyzer"="urlAnalyzer"})
* @ES\Property(name="url", type="text", options={"analyzer"="urlAnalyzer"})
*/
private $url;

Expand Down
14 changes: 10 additions & 4 deletions Routing/ElasticsearchRouteProvider.php
Expand Up @@ -12,10 +12,13 @@
namespace ONGR\RouterBundle\Routing;

use ONGR\ElasticsearchBundle\Mapping\MetadataCollector;
use ONGR\ElasticsearchBundle\Result\Result;
use ONGR\ElasticsearchBundle\Result\DocumentIterator;
use ONGR\ElasticsearchBundle\Result\ObjectIterator;
use ONGR\ElasticsearchBundle\Service\Manager;
use ONGR\ElasticsearchDSL\Query\MatchQuery;
use ONGR\ElasticsearchDSL\Query\Compound\BoolQuery;
use ONGR\ElasticsearchDSL\Query\FullText\MatchQuery;
use ONGR\ElasticsearchDSL\Search;
use ONGR\RouterBundle\Document\SeoAwareInterface;
use Symfony\Cmf\Component\Routing\RouteProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
Expand Down Expand Up @@ -92,10 +95,13 @@ public function getRouteCollectionForRequest(Request $request)
$requestPath = $request->getPathInfo();

$search = new Search();
$search->addFilter(new MatchQuery('url', $requestPath));
$search->addQuery(new MatchQuery('url', $requestPath), BoolQuery::FILTER);

$results = $this->manager->execute(array_keys($this->routeMap), $search, Result::RESULTS_OBJECT);
$results = $this->manager->search(array_keys($this->routeMap), $search->toArray());
#TODO Clean up this place.
$results = new DocumentIterator($results, $this->manager);
try {
/** @var SeoAwareInterface $document */
foreach ($results as $document) {
$type = $this->collector->getDocumentType(get_class($document));
if (isset($this->routeMap[$type])) {
Expand Down
10 changes: 7 additions & 3 deletions Tests/Unit/Routing/DocumentUrlGeneratorTest.php
Expand Up @@ -11,8 +11,10 @@

namespace ONGR\RouterBundle\Tests\Unit\Routing;

use ONGR\ElasticsearchBundle\Mapping\MetadataCollector;
use ONGR\RouterBundle\Routing\DocumentUrlGenerator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Cmf\Component\Routing\RouteProviderInterface;

class DocumentUrlGeneratorTest extends WebTestCase
{
Expand All @@ -22,7 +24,9 @@ class DocumentUrlGeneratorTest extends WebTestCase
public function testGettersAndSetters()
{
$routeMap = new \stdClass();
$routeProvider = $this->getMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
/** @var RouteProviderInterface $routeProvider */
$routeProvider = $this->createMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
/** @var MetadataCollector $collector */
$collector = $this->getMockBuilder('ONGR\ElasticsearchBundle\Mapping\MetadataCollector')
->disableOriginalConstructor()
->getMock();
Expand All @@ -44,7 +48,7 @@ public function testGettersAndSetters()
public function testGetDebugMessageWithBadObject()
{
$document = new \stdClass();
$routeProvider = $this->getMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
$routeProvider = $this->createMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
$urlGenerator = new DocumentUrlGenerator($routeProvider);
$debugMessage = $urlGenerator->getRouteDebugMessage($document);

Expand All @@ -62,7 +66,7 @@ public function testGetDebugMessageWithBadObject()
public function testGenerateException()
{
$document = new \stdClass();
$routeProvider = $this->getMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
$routeProvider = $this->createMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
$urlGenerator = new DocumentUrlGenerator($routeProvider);

$urlGenerator->generate($document);
Expand Down
13 changes: 4 additions & 9 deletions Tests/app/config/config_test.yml
Expand Up @@ -13,17 +13,12 @@ ongr_elasticsearch:
type: custom
tokenizer: keyword
filter: [lowercase]
connections:
default:
hosts:
- 127.0.0.1:9200
index_name: ongr-seo-test
analysis:
analyzer:
- urlAnalyzer
managers:
default:
connection: default
index:
hosts:
- 127.0.0.1:9200
index_name: ongr-seo-test
mappings:
- AppBundle

Expand Down
2 changes: 1 addition & 1 deletion Tests/app/fixture/AppBundle/Document/Product.php
Expand Up @@ -30,7 +30,7 @@ class Product implements SeoAwareInterface
public $id;

/**
* @ES\Property(type="string")
* @ES\Property(type="text")
*/
public $title;
}
10 changes: 5 additions & 5 deletions composer.json
Expand Up @@ -12,13 +12,13 @@
}
],
"require": {
"php": ">=5.5",
"symfony/symfony": "~2.7|~3.0",
"php": ">=5.6",
"symfony/symfony": "~2.8|~3.0",
"symfony-cmf/routing": "^1.4.0",
"ongr/elasticsearch-bundle": "~1.0"
"ongr/elasticsearch-bundle": "5.0.x-dev"
},
"require-dev": {
"phpunit/phpunit": "~4.4",
"phpunit/phpunit": "~5.5",
"symfony/monolog-bundle": "~2.3|~3.0",
"squizlabs/php_codesniffer": "~2.0",
"satooshi/php-coveralls": "~1.0"
Expand All @@ -30,7 +30,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "2.0-dev"
}
}
}

0 comments on commit 8804aa4

Please sign in to comment.