00001 <?php
00002
00003
00004
00005
00006
00007
00008 class DBWhereFulltext extends DBWhere {
00009
00010
00011
00012
00013
00014 protected $match;
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 public function __construct(IDBTable $table, $column, $value, $threshold = 0, $mode = IDBWhere::LOGIC_AND) {
00025 if (!is_array($value)) {
00026 $value = String::explode_terms($value);
00027 }
00028 parent::__construct(
00029 $table,
00030 $this->build_fulltext_sql($table, $column, $value, $threshold, $mode),
00031 null,
00032 null,
00033 $mode
00034 );
00035 $this->match = $this->build_fulltext_match($table, $column, $value, $mode);
00036 }
00037
00038
00039
00040
00041
00042
00043 public function get_match() {
00044 return $this->match;
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 protected function build_fulltext_sql(IDBTable $table, $column, $value, $threshold, $mode) {
00058 $threshold = Cast::float($threshold);
00059 $addition = 'IN BOOLEAN MODE';
00060 $ret = '';
00061 if ($threshold > 0) {
00062 $addition = '';
00063 $ret = ' > ' . $threshold;
00064 }
00065 $ret = $this->build_fulltext_match($table, $column, $value, $mode, $addition) . $ret;
00066 return $ret;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 public function build_fulltext_match(IDBTable $table, $column, $value, $mode, $additions = '') {
00080 $where = "";
00081 $fieldName = $this->prefix_table_name($column, $table);
00082 foreach($value as $token) {
00083 if (substr($token, 0, 1) !== "-" && $mode == self::LOGIC_AND)
00084 $where .= "+";
00085
00086 if (substr($token, -1) != "\"")
00087 $token .= "*";
00088
00089 $where .= $token . " ";
00090 }
00091
00092 return "(MATCH (" . $fieldName . ") AGAINST ('" . $table->get_table_driver()->escape($where) . "' " . $table->get_table_driver()->escape($additions) . "))";
00093 }
00094
00095 }