public static function addSearchQuery(Doctrine_Table $table, Doctrine_Query $q = null, $luceneQuery, $culture = null) { $name = $table->getOption('name'); if (is_null($q)) { $q = Doctrine_Query::create()->from($name); } $results = $table->searchLucene($luceneQuery, $culture); if (count($results)) { $alias = $q->getRootAlias(); // Call addSelect so that we don't trash existing queries. $q->addSelect($alias . '.*'); aDoctrine::orderByList($q, $results); $q->whereIn($alias . '.id', $results); return $q; } else { // Don't just let everything through when there are no hits! // Careful, be cross-database compatible $q->andWhere('0 = 1'); } return $q; }