コード例 #1
0
ファイル: Search.php プロジェクト: JimmyVB/Symfony-v1.2
 /**
  * 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());
     }
 }
コード例 #2
0
ファイル: Search.php プロジェクト: yasirgit/afids
 /**
  * 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());
     }
 }
コード例 #3
0
ファイル: Search.php プロジェクト: walterfrs/mladek
 /**
  * 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());
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 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");
 }
コード例 #6
0
    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
                        (SELECT COUNT(keyword) * 2 AS relevancy, foreign_id
                            FROM search_index
                            WHERE keyword = 'doctrine'
                            GROUP BY foreign_id
                    INTERSECT
                         SELECT COUNT(keyword) AS relevancy, foreign_id
                            FROM search_index) AS query_alias
                            WHERE keyword = 'dbal' AND (position + 1) = (SELECT position FROM search_index WHERE keyword = 'database')
                            GROUP BY foreign_id
                    EXCEPT
                         SELECT COUNT(keyword) AS relevancy, foreign_id
                            FROM search_index) AS query_alias
                            WHERE keyword != 'rdbms'
                            GROUP BY foreign_id                            
                            )
                GROUP BY foreign_id
                ORDER BY relevancy_sum";
                
        $this->assertEqual($q->getSql(), $sql);
    }
コード例 #7
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->getSql(), $sql);
    }