Looks like the Search API function setComment() is not required after all (cf. bug #0000902)
3 /* Reminder: always indent with 4 spaces (no tabs). */
4 // +---------------------------------------------------------------------------+
6 // +---------------------------------------------------------------------------+
7 // | searchcriteria.class.php |
9 // | This class acts as a container which allows data to be passed between the |
10 // | search engine and plugins. |
11 // +---------------------------------------------------------------------------+
12 // | Copyright (C) 2000-2009 by the following authors: |
14 // | Authors: Sami Barakat, s.m.barakat AT gmail DOT com |
15 // +---------------------------------------------------------------------------+
17 // | This program is free software; you can redistribute it and/or |
18 // | modify it under the terms of the GNU General Public License |
19 // | as published by the Free Software Foundation; either version 2 |
20 // | of the License, or (at your option) any later version. |
22 // | This program is distributed in the hope that it will be useful, |
23 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
24 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25 // | GNU General Public License for more details. |
27 // | You should have received a copy of the GNU General Public License |
28 // | along with this program; if not, write to the Free Software Foundation, |
29 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
31 // +---------------------------------------------------------------------------+
33 class SearchCriteria {
43 var $_results = array();
45 function SearchCriteria( $pluginName, $pluginLabel )
47 $this->_pluginName = $pluginName;
48 $this->_pluginLabel = $pluginLabel;
50 $this->_url_rewrite = false;
51 $this->_append_query = true;
54 function setSQL( $sql )
59 function setFTSQL( $ftsql )
61 $this->_ftsql = $ftsql;
64 function setRank( $rank )
69 function setURLRewrite( $url_rewrite )
71 $this->_url_rewrite = $url_rewrite;
74 function setAppendQuery( $append_query )
76 $this->_append_query = $append_query;
79 function setResults( $result_arr )
81 $this->_results = $result_arr;
93 // When only one SQL statment is set we assume it is for MySQL
94 if ($this->_ftsql != '' && (is_string($this->_ftsql) && $_DB_dbms == 'mysql') || is_array($this->_ftsql)) {
103 return $this->_pluginName;
108 return $this->_pluginLabel;
116 function UrlRewriteEnable()
118 return $this->_url_rewrite;
121 function AppendQueryEnable()
123 return $this->_append_query;
126 function getResults()
128 return $this->_results;
131 function buildSearchSQL( $keyType, $query, $columns, $sql = '' )
133 if ($keyType == 'all')
135 // must contain ALL of the keywords
136 $words = explode(' ', $query);
139 $ftwords['mysql'] = '+' . str_replace(' ', ' +', $query);
140 $ftwords['mssql'] = '"' . str_replace(' ', '" AND "', $query) . '"';
142 else if ($keyType == 'any')
144 // must contain ANY of the keywords
145 $words = explode(' ', $query);
147 $ftwords['mysql'] = $query;
148 $ftwords['mssql'] = '"' . str_replace(' ', '" OR "', $query) . '"';
152 // do an exact phrase search (default)
153 $words = array($query);
156 // Puttings quotes around a single word in mysql really slows things down
157 if (strpos($query, ' ') !== false) {
158 $ftwords['mysql'] = '"' . $query . '"';
160 $ftwords['mysql'] = $query;
162 $ftwords['mssql'] = '"' . $query . '"';
165 $titles = (isset($_GET['title']) && isset($columns['title'])) ? true : false;
168 $strcol = $columns['title'];
170 $strcol = implode(',', $columns);
173 $ftsql['mysql'] = $sql . "AND MATCH($strcol) AGAINST ('{$ftwords['mysql']}' IN BOOLEAN MODE)";
174 $ftsql['mssql'] = $sql . "AND CONTAINS(($strcol), '{$ftwords['mssql']}')";
177 foreach ($words AS $word)
183 $tmp .= $columns['title'] . " LIKE '%$word%' OR ";
185 foreach ($columns AS $col) {
186 $tmp .= "$col LIKE '%$word%' OR ";
189 $tmp = substr($tmp, 0, -4) . ") $sep ";
191 $sql .= substr($tmp, 0, -5) . ') ';
193 return array($sql,$ftsql);
196 function getDateRangeSQL( $type = 'WHERE', $column, $datestart, $dateend )
198 if (!empty($datestart) && !empty($dateend))
200 $delim = substr($datestart, 4, 1);
203 $DS = explode($delim, $datestart);
204 $DE = explode($delim, $dateend);
205 $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]);
206 $enddate = mktime(23,59,59,$DE[1],$DE[2],$DE[0]);
207 return " $type (UNIX_TIMESTAMP($column) BETWEEN '$startdate' AND '$enddate') ";