-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from saimaz/variant_filter
Introduced variant filtering
- Loading branch information
Showing
7 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the ONGR package. | ||
* | ||
* (c) NFQ Technologies UAB <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ONGR\FilterManagerBundle\DependencyInjection\Filter; | ||
|
||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
/** | ||
* Factory for variant filter. | ||
*/ | ||
class VariantFilterFactory extends AbstractFilterFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure(Definition $definition, array $configuration) | ||
{ | ||
parent::configure($definition, $configuration); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getNamespace() | ||
{ | ||
return 'ONGR\FilterManagerBundle\Filters\Widget\Search\VariantFilter'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'variant'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the ONGR package. | ||
* | ||
* (c) NFQ Technologies UAB <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ONGR\FilterManagerBundle\Filters\Widget\Search; | ||
|
||
use ONGR\ElasticsearchBundle\DSL\Filter\BoolFilter; | ||
use ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter; | ||
use ONGR\ElasticsearchBundle\DSL\Search; | ||
use ONGR\FilterManagerBundle\Filters\FilterState; | ||
use ONGR\FilterManagerBundle\Search\SearchRequest; | ||
|
||
/** | ||
* This filter selects only parent documents. | ||
*/ | ||
class VariantFilter extends AbstractSingleValue | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) | ||
{ | ||
$filter = new MissingFilter($this->getField()); | ||
$search->addFilter($filter, BoolFilter::MUST); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
Tests/Functional/Filters/Widget/Search/VariantFilterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the ONGR package. | ||
* | ||
* (c) NFQ Technologies UAB <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ONGR\FilterManagerBundle\Tests\Functional\Filters\Widget\Search; | ||
|
||
use ONGR\ElasticsearchBundle\Test\ElasticsearchTestCase; | ||
use ONGR\FilterManagerBundle\Filters\Widget\Search\MatchSearch; | ||
use ONGR\FilterManagerBundle\Filters\Widget\Search\VariantFilter; | ||
use ONGR\FilterManagerBundle\Search\FiltersContainer; | ||
use ONGR\FilterManagerBundle\Search\FiltersManager; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class VariantFilterTest extends ElasticsearchTestCase | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getDataArray() | ||
{ | ||
return [ | ||
'default' => [ | ||
'product' => [ | ||
[ | ||
'_id' => 1, | ||
'title' => 'Foo', | ||
], | ||
[ | ||
'_id' => 2, | ||
'title' => 'Baz', | ||
'description' => 'tuna fish', | ||
'parent_id' => 1, | ||
], | ||
[ | ||
'_id' => 3, | ||
'title' => 'Foo bar', | ||
'parent_id' => 1, | ||
], | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Returns filter manager with MatchSearch set. | ||
* | ||
* @return FiltersManager | ||
*/ | ||
public function getFilerManger() | ||
{ | ||
$container = new FiltersContainer(); | ||
|
||
$variant = new VariantFilter(); | ||
$variant->setField('parent_id'); | ||
|
||
$container->set('variant', $variant); | ||
|
||
return new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product')); | ||
} | ||
|
||
/** | ||
* Tests if filter works. | ||
*/ | ||
public function testFiltering() | ||
{ | ||
$result = $this->getFilerManger()->execute(new Request()); | ||
|
||
$actual = []; | ||
foreach ($result->getResult() as $doc) { | ||
$actual[] = $doc->getId(); | ||
} | ||
|
||
$this->assertCount(1, $actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters