コード例 #1
0
 /**
  * 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'));
 }
コード例 #2
0
 /**
  * Returns filter manager with MatchSearch set.
  *
  * @return FiltersManager
  */
 public function getFilerManger()
 {
     $container = new FiltersContainer();
     $match = new MatchSearch();
     $match->setRequestField('q');
     $match->setField('title,description');
     $container->set('match', $match);
     return new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product'));
 }
コード例 #3
0
 /**
  * Return any kind of filters manager to test.
  *
  * @return FiltersManager
  */
 protected function getFilterManager()
 {
     $filter = new MatchSearch();
     $filter->setField('title');
     $filter->setRequestField('q');
     $container = new FiltersContainer();
     $container->set('title_match', $filter);
     return new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product'));
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 protected function getFilterManager()
 {
     $container = new FiltersContainer();
     $filter = new DocumentField();
     $filter->setRequestField('document');
     $filter->setField('categories');
     $container->set('category', $filter);
     return new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product'));
 }
コード例 #5
0
 /**
  * Returns filter manager.
  *
  * @return FiltersManager
  */
 protected function getFilterManager()
 {
     $container = new FiltersContainer();
     $filter = new MultiTermChoice();
     $filter->setRequestField('choice');
     $filter->setTags(['badged']);
     $filter->setField('color');
     $container->set('choice', $filter);
     return new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product'));
 }
コード例 #6
0
 /**
  * @return FiltersManager
  */
 protected function getFiltersManager()
 {
     $container = new FiltersContainer();
     $choices = [['label' => 'Stock ASC', 'field' => 'stock', 'order' => 'asc', 'default' => false, 'mode' => null], ['label' => 'Stock DESC', 'field' => 'stock', 'order' => 'desc', 'default' => true, 'mode' => null], ['label' => 'Stock Keyed', 'field' => 'stock', 'order' => 'desc', 'default' => false, 'key' => 'foo', 'mode' => null], ['label' => 'Items ASC', 'field' => 'items', 'order' => 'asc', 'default' => false, 'mode' => 'min'], ['label' => 'Items ASC', 'field' => 'items', 'order' => 'desc', 'default' => false, 'mode' => 'max'], ['label' => 'Items ASC', 'field' => 'items', 'order' => 'asc', 'default' => false, 'mode' => 'avg'], ['label' => 'Items ASC', 'field' => 'items', 'order' => 'asc', 'default' => false, 'mode' => 'sum'], ['label' => 'Items ASC', 'field' => 'words', 'order' => 'asc', 'default' => false, 'mode' => 'min'], ['label' => 'Items ASC', 'field' => 'words', 'order' => 'asc', 'default' => false, 'mode' => 'max'], ['label' => 'Items ASC', 'field' => 'words', 'order' => 'asc', 'default' => false, 'mode' => 'avg'], ['label' => 'Items ASC', 'field' => 'words', 'order' => 'asc', 'default' => false, 'mode' => 'sum']];
     $filter = new Sort();
     $filter->setRequestField('sort');
     $filter->setChoices($choices);
     $container->set('sorting', $filter);
     return new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product'));
 }
コード例 #7
0
 /**
  * Tests buildSearch method.
  */
 public function testBuildSearch()
 {
     $mockRequest = $this->getMock('ONGR\\FilterManagerBundle\\Search\\SearchRequest');
     $mockRequest->expects($this->once())->method('get')->will($this->returnValue(null));
     $mockFilterInterface = $this->getMock('ONGR\\FilterManagerBundle\\Filters\\FilterInterface');
     $mockFilterInterface->expects($this->once())->method('modifySearch')->withConsecutive($this->isInstanceOf('ONGR\\ElasticsearchBundle\\DSL\\Search'), $this->equalTo('testName'), $this->identicalTo($mockRequest));
     $filtersContainer = new FiltersContainer();
     $filtersContainer->add([$mockFilterInterface]);
     $result = $filtersContainer->buildSearch($mockRequest);
     $this->assertInstanceOf('ONGR\\ElasticsearchBundle\\DSL\\Search', $result);
 }
コード例 #8
0
 /**
  * @return FiltersManager
  */
 protected function getFiltersManager()
 {
     $container = new FiltersContainer();
     $filter = new SingleTermChoice();
     $filter->setRequestField('c');
     $filter->setField('color');
     $filter->setSortType(['type' => '_term', 'order' => 'asc', 'priorities' => []]);
     $container->set('color', $filter);
     $filter = new SingleTermChoice();
     $filter->setRequestField('m');
     $filter->setField('manufacturer');
     $filter->setSortType(['type' => '_term', 'order' => 'asc', 'priorities' => []]);
     $container->set('manufacturer', $filter);
     return new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product'));
 }
コード例 #9
0
 /**
  * Returns filter manager.
  *
  * @param array $options
  *
  * @return FiltersManager
  */
 protected function getFiltersManager(array $options)
 {
     $container = new FiltersContainer();
     $choices = [['label' => 'Stock ASC', 'field' => 'stock', 'order' => 'asc', 'default' => false, 'mode' => null]];
     $filter = new Pager();
     $filter->setRequestField('page');
     if (isset($options['count_per_page'])) {
         $filter->setCountPerPage($options['count_per_page']);
     }
     if (isset($options['max_pages'])) {
         $filter->setMaxPages($options['max_pages']);
     }
     $container->set('pager', $filter);
     $sort = new Sort();
     $sort->setRequestField('sort');
     $sort->setChoices($choices);
     $container->set('sorting', $sort);
     return new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product'));
 }
コード例 #10
0
 /**
  * Tests if search works.
  *
  * @param array            $expected
  * @param Request          $request
  * @param string|int|float $fuzziness
  * @param int              $prefixLength
  * @param int              $maxExpansions
  *
  * @dataProvider getTestingData
  */
 public function testFiltering($expected, $request, $fuzziness = null, $prefixLength = null, $maxExpansions = null)
 {
     $container = new FiltersContainer();
     $fuzzy = new FuzzySearch();
     $fuzzy->setRequestField('q');
     $fuzzy->setField('color');
     $fuzzy->setFuzziness($fuzziness);
     $fuzzy->setPrefixLength($prefixLength);
     $fuzzy->setMaxExpansions($maxExpansions);
     $container->set('fuzzy', $fuzzy);
     $fmb = new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product'));
     $result = $fmb->execute($request);
     $actual = [];
     foreach ($result->getResult() as $doc) {
         $actual[] = $doc->getId();
     }
     sort($actual);
     $this->assertEquals($expected, $actual);
 }
コード例 #11
0
 /**
  * Creates view data for each filter.
  *
  * @param DocumentIterator $result
  * @param SearchRequest    $request
  *
  * @return ViewData[]
  */
 protected function getFiltersViewData(DocumentIterator $result, SearchRequest $request)
 {
     $out = [];
     /** @var FilterInterface[] $filters */
     $filters = $this->container->all();
     foreach ($filters as $name => $filter) {
         if ($filter instanceof ViewDataFactoryInterface) {
             $viewData = $filter->createViewData();
         } else {
             $viewData = new ViewData();
         }
         $viewData->setName($name);
         $viewData->setUrlParameters($this->composeUrlParameters($request, $filter));
         $viewData->setState($request->get($name));
         $viewData->setTags($filter->getTags());
         $viewData->setResetUrlParameters($this->composeUrlParameters($request, $filter, [$name]));
         $out[$name] = $filter->getViewData($result, $viewData);
     }
     return $out;
 }
コード例 #12
0
 /**
  * Returns filter managers.
  *
  * @return FiltersManager[]
  */
 protected function getFilterManager()
 {
     $managers = [];
     $container = new FiltersContainer();
     $choices = [['label' => 'Stock ASC', 'field' => 'price', 'order' => 'asc', 'default' => false, 'mode' => null]];
     $filter = new Range();
     $filter->setRequestField('range');
     $filter->setField('price');
     $container->set('range', $filter);
     $filter = new Range();
     $filter->setRequestField('inclusive_range');
     $filter->setField('price');
     $filter->setInclusive(true);
     $container->set('inclusive_range', $filter);
     $sort = new Sort();
     $sort->setRequestField('sort');
     $sort->setChoices($choices);
     $container->set('sorting', $sort);
     $managers['range'] = new FiltersManager($container, $this->getManager()->getRepository('AcmeTestBundle:Product'));
     $managers['bar_range'] = self::createClient()->getContainer()->get('ongr_filter_manager.bar_filters');
     return $managers;
 }