[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/search/src/db/query/ -> lmbMySQL4FullTextSearchQuery.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  lmb_require('limb/dbal/src/query/lmbSelectQuery.class.php');
  10  
  11  /**

  12   * class lmbMySQL4FullTextSearchQuery.

  13   *

  14   * @package search

  15   * @version $Id: lmbMySQL4FullTextSearchQuery.class.php 5945 2007-06-06 08:31:43Z pachanga $

  16   */
  17  class lmbMySQL4FullTextSearchQuery extends lmbSelectQuery
  18  {
  19    function __construct($table, $words, $use_boolean_mode = true, $conn)
  20    {
  21      $match = $this->_buildMatch($words, $use_boolean_mode);
  22      $where = $this->_buildWhere($words, $use_boolean_mode);
  23  
  24      $sql = "SELECT {$table}.*, {$match} %fields% FROM {$table} %tables% %left_join% ".
  25             "{$where} %where% %group% %having%  ORDER BY score DESC %order%";
  26      parent :: __construct($sql, $conn);
  27    }
  28  
  29    protected function _buildMatch($words, $use_boolean_mode)
  30    {
  31      $query_words = $this->_getQueryWords($words, $use_boolean_mode);
  32  
  33      if($use_boolean_mode)
  34        $boolean_mode = " IN BOOLEAN MODE";
  35      else
  36        $boolean_mode = '';
  37  
  38      return "(MATCH (content) AGAINST (\"{$query_words}\"{$boolean_mode})) as score";
  39    }
  40  
  41    protected function _buildWhere($words, $use_boolean_mode)
  42    {
  43      $query_words = $this->_getQueryWords($words, $use_boolean_mode);
  44  
  45      if($use_boolean_mode)
  46        $boolean_mode = " IN BOOLEAN MODE";
  47      else
  48        $boolean_mode = '';
  49  
  50      return "WHERE MATCH (content) AGAINST (\"{$query_words}\"{$boolean_mode})";
  51    }
  52  
  53    function _getQueryWords($words, $use_boolean_mode)
  54    {
  55      foreach($words as $key => $word)
  56        $words[$key] = mysql_escape_string($word);
  57  
  58      if($use_boolean_mode)
  59        return implode('* ', $words) . '*';
  60      else
  61        return implode(' ', $words);
  62    }
  63  }
  64  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7