addService() public method

Adds a service for the named operation.
public addService ( string $operation, Bolt\Storage\Query\QueryInterface $service )
$operation string
$service Bolt\Storage\Query\QueryInterface
Example #1
0
 public function register(Application $app)
 {
     $app['query'] = function ($app) {
         $runner = new Query($app['query.parser']);
         return $runner;
     };
     $app['query.parser'] = function ($app) {
         $parser = new ContentQueryParser($app['storage']);
         $parser->addService('select', $app['query.select']);
         $parser->addService('search', $app['query.search']);
         $parser->addService('search_weighter', $app['query.search_weighter']);
         $parser->addService('search_config', $app['query.search_config']);
         return $parser;
     };
     $app['query.parser.handler'] = function ($app) {
         return new QueryParameterParser($app['storage']->createExpressionBuilder());
     };
     $app['query.select'] = function ($app) {
         return new SelectQuery($app['storage']->createQueryBuilder(), $app['query.parser.handler']);
     };
     $app['query.search'] = function ($app) {
         return new SearchQuery($app['storage']->createQueryBuilder(), $app['query.parser.handler'], $app['query.search_config']);
     };
     $app['query.search_config'] = $app->share(function ($app) {
         return new SearchConfig($app['config']);
     });
     $app['query.search_weighter'] = $app->share(function ($app) {
         return new SearchWeighter($app['query.search_config']);
     });
 }
Example #2
0
 public function testNativeSearchHandlerFallback()
 {
     $app = $this->getApp();
     $qb = new ContentQueryParser($app['storage'], $app['query.select']);
     $qb->addService('search', $app['query.search']);
     $qb->addService('search_weighter', $app['query.search_weighter']);
     $qb->setQuery('pages/nativesearch/4');
     $qb->setParameters(['filter' => 'lorem ipsum']);
     $res = $qb->fetch();
     $this->assertEquals(4, $res->count());
 }