コード例 #1
0
 /**
  * @param QueryBuilder $qb
  * @param string       $query
  * @param int          $page
  * @param string       $lang
  */
 protected function buildQuery(QueryBuilder $qb, $query, $page, $lang)
 {
     $factory = $qb->getQOMFactory();
     $qb->select('a', 'jcr:uuid', 'uuid')->addSelect('a', 'phpcr:class', 'class')->from($factory->selector('a', 'nt:unstructured'))->where($factory->descendantNode('a', $this->searchPath))->setFirstResult(($page - 1) * $this->perPage)->setMaxResults($this->perPage);
     $constraint = null;
     foreach ($this->searchFields as $field) {
         $column = $field;
         if (2 === strlen($lang) && 'attribute' === $this->translationStrategy) {
             $field = "phpcr_locale:{$lang}-{$field}";
         }
         $qb->addSelect('a', $field, $column);
         $newConstraint = $factory->fullTextSearch('a', $field, $query);
         if (empty($constraint)) {
             $constraint = $newConstraint;
         } else {
             $constraint = $factory->orConstraint($constraint, $newConstraint);
         }
     }
     $qb->andWhere($constraint);
     if (2 === strlen($lang) && 'child' === $this->translationStrategy) {
         // TODO: check if we can/must validate lang to prevent evil hacking or accidental breakage
         $qb->andWhere($factory->comparison($factory->nodeName('a'), '=', $factory->literal('phpcr_locale:' . $lang)));
     }
 }