/** * Searchable keyword search * * @param string $string Keyword string to search for * @param Doctrine_Query $query Query object to alter. Adds where condition to limit the results using the search index * @return mixed The Doctrine_Collection or array of ids and relevancy */ public function search($string, $query = null) { $q = new Doctrine_Search_Query($this->_table); if ($query instanceof Doctrine_Query) { $q->query($string, false); $newQuery = $query->copy(); $query->getSql(); $newQuery->addWhere($query->getRootAlias() . '.id IN(' . $q->getSql() . ')', $q->getParams()); return $newQuery; } else { $q->query($string); return $this->_options['connection']->fetchAll($q->getSql(), $q->getParams()); } }
/** * Searchable keyword search * * @param string $string Keyword string to search for * @param Doctrine_Query $query Query object to alter. Adds where condition to limit the results using the search index * @return mixed The Doctrine_Collection or array of ids and relevancy */ public function search($string, $query = null) { $q = new Doctrine_Search_Query($this->_table); if ($query instanceof Doctrine_Query) { $q->query($string, false); $newQuery = $query->copy(); $query->getSql(); $key = (array) $this->getOption('table')->getIdentifier(); $newQuery->addWhere($query->getRootAlias() . '.' . current($key) . ' IN (SQL:' . $q->getSql() . ')', $q->getParams()); return $newQuery; } else { $q->query($string); return $this->_options['connection']->fetchAll($q->getSql(), $q->getParams()); } }
public function testSearchableChildTemplate() { $this->conn->clear(); $wiki = new Wiki(); $wiki->state(Doctrine_Record::STATE_TDIRTY); $wiki->save(); $fi = $wiki->Translation['FI']; $fi->title = 'New Title'; $fi->content = "Sorry, I'm not able to write a Finish sentence about Michael Jordan..."; $fi->save(); $t = Doctrine::getTable('WikiTranslationIndex'); $oQuery = new Doctrine_Search_Query($t); $oQuery->query("jordan"); $out = $this->conn->fetchAll($oQuery->getSql(), $oQuery->getParams()); $this->assertEqual($out[0]['relevance'], 2); $this->assertEqual($out[1]['relevance'], 1); $this->assertEqual($out[0]['id'], 1); $this->assertEqual($out[1]['id'], 2); }
public function testSearchReturnsFalseForEmptyStrings() { $q = new Doctrine_Search_Query('SearchTestIndex'); $result = $q->query(' '); $this->assertFalse($result); }
/** * search * * @param string $query * @return Doctrine_Collection The collection of search results */ public function search($query) { $q = new Doctrine_Search_Query($this->_table); $q->query($query); return $this->_options['connection']->fetchAll($q->getSql(), $q->getParams()); }
public function testGenerateSearchQueryForWeightedSearch() { $oQuery = new Doctrine_Search_Query("SearchTest"); $oQuery->query("^test"); $this->assertEqual($oQuery->getSql(), "SELECT SUM(sub_relevance) AS relevance, id FROM search_test WHERE keyword = ? GROUP BY id ORDER BY relevance DESC"); }