示例#1
0
 /**
  * @param ContentQueryParser $contentQuery
  *
  * @return QueryResultset
  */
 public function __invoke(ContentQueryParser $contentQuery)
 {
     $params = $contentQuery->getEntityManager()->createQueryBuilder()->getConnection()->getParams();
     if (strpos($params['driver'], 'mysql') !== false) {
         $contentQuery->setDirective('order', 'RAND()');
     } else {
         $contentQuery->setDirective('order', 'RANDOM()');
     }
     return call_user_func_array($contentQuery->getHandler('select'), [$contentQuery]);
 }
示例#2
0
 /**
  * @param ContentQueryParser $contentQuery
  *
  * @return SearchQueryResultset
  */
 public function __invoke(ContentQueryParser $contentQuery)
 {
     $set = new SearchQueryResultset();
     foreach ($contentQuery->getContentTypes() as $contenttype) {
         $query = $contentQuery->getService('search');
         $repo = $contentQuery->getEntityManager()->getRepository($contenttype);
         $query->setQueryBuilder($repo->createQueryBuilder($contenttype));
         $query->setContentType($contenttype);
         $searchParam = $contentQuery->getParameter('filter');
         $query->setParameters($contentQuery->getParameters());
         $query->setSearch($searchParam);
         $contentQuery->runDirectives($query);
         $result = $repo->queryWith($query);
         if ($result) {
             if (count($result) > 0) {
                 $weighter = $contentQuery->getService('search_weighter');
                 $weighter->setContentType($contenttype);
                 $weighter->setResults($result);
                 $weighter->setSearchWords($query->getSearchWords());
                 $scores = $weighter->weight();
                 $set->add($result, $contenttype, $scores);
             } else {
                 $set->add($result, $contenttype);
             }
         }
     }
     if ($query->getSingleFetchMode()) {
         return $set->current();
     } else {
         return $set;
     }
 }
示例#3
0
 public function postgresSearch(ContentQueryParser $contentQuery)
 {
     $set = new SearchQueryResultset();
     foreach ($contentQuery->getContentTypes() as $contenttype) {
         $repo = $contentQuery->getEntityManager()->getRepository($contenttype);
         $query = $repo->createQueryBuilder($contenttype);
         $config = $contentQuery->getService('search_config');
         $search = $contentQuery->getParameter('filter');
         $adapter = new PostgresSearch($query, $config, explode(' ', $search));
         $adapter->setContentType($contenttype);
         $result = $repo->findWith($adapter->getQuery());
         $set->add($result, $contenttype);
     }
     return $set;
 }
示例#4
0
 /**
  * @param ContentQueryParser $contentQuery
  *
  * @return mixed
  */
 public function __invoke(ContentQueryParser $contentQuery)
 {
     if (is_numeric($contentQuery->getIdentifier())) {
         $contentQuery->setParameter('id', $contentQuery->getIdentifier());
     } else {
         $contentQuery->setParameter('slug', $contentQuery->getIdentifier());
     }
     if (count($contentQuery->getContentTypes()) === 1) {
         $contentQuery->setDirective('returnsingle', true);
     }
     return call_user_func_array($contentQuery->getHandler('select'), [$contentQuery]);
 }
示例#5
0
 /**
  * @param ContentQueryParser $contentQuery
  *
  * @return QueryResultset
  */
 public function __invoke(ContentQueryParser $contentQuery)
 {
     $set = new QueryResultset();
     /** @var SelectQuery $query */
     $query = $contentQuery->getService('select');
     foreach ($contentQuery->getContentTypes() as $contentType) {
         $repo = $contentQuery->getEntityManager()->getRepository($contentType);
         $query->setQueryBuilder($repo->createQueryBuilder($contentType));
         $query->setContentType($contentType);
         /** Run the parameters through the whitelister. If we get a false back from this method it's because there
          * is no need to continue with the query.
          */
         $params = $this->whitelistParameters($contentQuery->getParameters(), $repo);
         if (!$params && count($contentQuery->getParameters())) {
             continue;
         }
         /** Continue and run the query add the results to the set */
         $query->setParameters($params);
         $contentQuery->runDirectives($query);
         $result = $repo->queryWith($query);
         if ($result) {
             $set->add($result, $contentType);
         }
     }
     if ($query->getSingleFetchMode()) {
         return $set->current();
     } else {
         return $set;
     }
 }
示例#6
0
 public function register(Application $app)
 {
     $app['query'] = function ($app) {
         $runner = new Query($app['query.parser']);
         return $runner;
     };
     $app['query.parser'] = $app->share(function ($app) {
         $parser = new ContentQueryParser($app['storage']);
         $parser->addService('select', $app['query.select']);
         return $parser;
     });
     $app['query.parser.handler'] = $app->share(function ($app) {
         return new QueryParameterParser($app['storage']->createExpressionBuilder());
     });
     $app['query.select'] = $app->share(function ($app) {
         return new SelectQuery($app['storage']->createQueryBuilder(), $app['query.parser.handler']);
     });
 }
示例#7
0
 /**
  * @param ContentQueryParser $contentQuery
  *
  * @return QueryResultset
  */
 public function __invoke(ContentQueryParser $contentQuery)
 {
     $set = new QueryResultset();
     foreach ($contentQuery->getContentTypes() as $contenttype) {
         $query = $contentQuery->getService('select');
         $repo = $contentQuery->getEntityManager()->getRepository($contenttype);
         $query->setQueryBuilder($repo->createQueryBuilder($contenttype));
         $query->setContentType($contenttype);
         $query->setParameters($contentQuery->getParameters());
         $contentQuery->runDirectives($query);
         $result = $repo->queryWith($query);
         if ($result) {
             $set->add($result, $contenttype);
         }
     }
     if ($query->getSingleFetchMode()) {
         return $set->current();
     } else {
         return $set;
     }
 }
示例#8
0
 /**
  * @param ContentQueryParser $contentQuery
  *
  * @return QueryResultset
  */
 public function __invoke(ContentQueryParser $contentQuery)
 {
     $contentQuery->setDirective('order', '-id');
     return call_user_func_array($contentQuery->getHandler('select'), [$contentQuery]);
 }
示例#9
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());
 }
示例#10
0
 public function testSingleItemMode()
 {
     $app = $this->getApp();
     $qb = new ContentQueryParser($app['storage'], $app['query.select']);
     $qb->setQuery('pages/5');
     $qb->setParameter('printquery', true);
     $qb->parse();
     $this->assertEquals(['pages'], $qb->getContentTypes());
     $this->assertEquals('namedselect', $qb->getOperation());
     $this->assertEquals('5', $qb->getIdentifier());
     $this->expectOutputString('SELECT pages.* FROM bolt_pages pages WHERE pages.id = :id_1');
     $res = $qb->fetch();
     $this->assertInstanceOf('Bolt\\Storage\\Entity\\Content', $res);
 }
示例#11
0
 public function testRemoveOperation()
 {
     $app = $this->getApp();
     $qb = new ContentQueryParser($app['storage'], $app['query.select']);
     $qb->addOperation('featured');
     $this->assertTrue(in_array('featured', $qb->getOperations()));
     $qb->removeOperation('featured');
     $this->assertFalse(in_array('featured', $qb->getOperations()));
 }