Beispiel #1
0
 /**
  * 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 array    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->getSqlQuery();
         $key = (array) $this->getOption('table')->getIdentifier();
         $newQuery->addWhere($query->getRootAlias() . '.' . current($key) . ' IN (SQL:' . $q->getSqlQuery() . ')', $q->getParams());
         return $newQuery;
     } else {
         $q->query($string);
         return $this->_options['connection']->fetchAll($q->getSqlQuery(), $q->getParams());
     }
 }
 public function testQuerySupportsMultiWordNegationOperatorSearchWithQuotesWeights()
 {
     $q = new Doctrine_Search_Query('SearchTestIndex');
     $q->search("doctrine^2 'dbal database' -rdbms");
     $sql = "SELECT foreign_id, SUM(relevancy) AS relevancy_sum FROM\n                        (SELECT COUNT(keyword) * 2 AS relevancy, foreign_id\n                            FROM search_index\n                            WHERE keyword = 'doctrine'\n                            GROUP BY foreign_id\n                    INTERSECT\n                         SELECT COUNT(keyword) AS relevancy, foreign_id\n                            FROM search_index) AS query_alias\n                            WHERE keyword = 'dbal' AND (position + 1) = (SELECT position FROM search_index WHERE keyword = 'database')\n                            GROUP BY foreign_id\n                    EXCEPT\n                         SELECT COUNT(keyword) AS relevancy, foreign_id\n                            FROM search_index) AS query_alias\n                            WHERE keyword != 'rdbms'\n                            GROUP BY foreign_id                            \n                            )\n                GROUP BY foreign_id\n                ORDER BY relevancy_sum";
     $this->assertEqual($q->getSqlQuery(), $sql);
 }
Beispiel #3
0
 public function testSearchSupportsMultipleTermsWithQuotes()
 {
     $q = new Doctrine_Search_Query('SearchTestIndex');
     $q->query("doctrine 'orm database'");
     $sql = 'SELECT COUNT(keyword) AS relevance, id ' . 'FROM search_test_index ' . 'WHERE id IN (SELECT id FROM search_test_index WHERE keyword = ?) ' . 'AND id IN (SELECT id FROM search_test_index WHERE keyword = ? ' . 'AND (position + 1) = (SELECT position FROM search_test_index WHERE keyword = ?)) ' . 'GROUP BY id ORDER BY relevance DESC';
     $this->assertEqual($q->getParams(), array('doctrine', 'orm', 'database'));
     $this->assertEqual($q->getSqlQuery(), $sql);
 }
Beispiel #4
0
 public function testGenerateSearchQueryForWeightedSearch()
 {
     $oQuery = new Doctrine_Search_Query('SearchTest');
     $oQuery->query('^test');
     $this->assertEqual($oQuery->getSqlQuery(), 'SELECT SUM(sub_relevance) AS relevance, id FROM search_test WHERE keyword = ? GROUP BY id ORDER BY relevance DESC');
 }
 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_Core::getTable('WikiTranslationIndex');
     $oQuery = new Doctrine_Search_Query($t);
     $oQuery->query("jordan");
     $out = $this->conn->fetchAll($oQuery->getSqlQuery(), $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);
 }