Esempio n. 1
0
 public static function addSearchQueryWithScores(Doctrine_Table $table, Doctrine_Query $q = null, $luceneQuery, $culture, &$scores)
 {
     $name = $table->getOption('name');
     if (is_null($q)) {
         $q = Doctrine_Query::create()->from($name);
     }
     $scores = $table->searchLuceneWithScores($luceneQuery, $culture);
     $results = array_keys($scores);
     if (count($results)) {
         $alias = $q->getRootAlias();
         // Contrary to Jobeet the above is NOT enough, the results will
         // not be in Lucene result order. Use aDoctrine::orderByList to fix
         // that up in a portable way with a SQL92-compatible CASE statement.
         // Call addSelect so that we don't trash existing queries.
         $q->addSelect($alias . '.*');
         aDoctrine::orderByList($q, $results);
         $q->whereIn($alias . '.id', $results);
         $q->orderBy('field');
     } else {
         // Don't just let everything through when there are no hits!
         // Don't use just 'false', that is not guaranteed to be cross-database compatible.
         $q->andWhere('0 = 1');
     }
     return $q;
 }