3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
27 function __construct($target, $table)
29 $this->target = $target;
30 $this->table = $table;
37 function limit($offset, $count, $rss = false)
39 return $this->target->limit($offset, $count);
42 function set_sort_mode($mode)
44 if ('chron' === $mode)
45 return $this->target->orderBy('created desc');
49 class MySQLSearch extends SearchEngine
53 if ('profile' === $this->table) {
54 $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' .
55 'AGAINST (\''.addslashes($q).'\' IN BOOLEAN MODE)');
56 if (strtolower($q) != $q) {
57 $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' .
58 'AGAINST (\''.addslashes(strtolower($q)).'\' IN BOOLEAN MODE)', 'OR');
61 } else if ('notice' === $this->table) {
63 // Don't show imported notices
64 $this->target->whereAdd('notice.is_local != ' . Notice::GATEWAY);
66 if (strtolower($q) != $q) {
67 $this->target->whereAdd("( MATCH(content) AGAINST ('" . addslashes($q) .
68 "' IN BOOLEAN MODE)) OR ( MATCH(content) " .
69 "AGAINST ('" . addslashes(strtolower($q)) .
70 "' IN BOOLEAN MODE))");
72 $this->target->whereAdd('MATCH(content) ' .
73 'AGAINST (\''.addslashes($q).'\' IN BOOLEAN MODE)');
78 throw new ServerException('Unknown table: ' . $this->table);
83 class MySQLLikeSearch extends SearchEngine
87 if ('profile' === $this->table) {
88 $qry = sprintf('(nickname LIKE "%%%1$s%%" OR '.
89 ' fullname LIKE "%%%1$s%%" OR '.
90 ' location LIKE "%%%1$s%%" OR '.
91 ' bio LIKE "%%%1$s%%" OR '.
92 ' homepage LIKE "%%%1$s%%")', addslashes($q));
93 } else if ('notice' === $this->table) {
94 $qry = sprintf('content LIKE "%%%1$s%%"', addslashes($q));
96 throw new ServerException('Unknown table: ' . $this->table);
99 $this->target->whereAdd($qry);
105 class PGSearch extends SearchEngine
109 if ('profile' === $this->table) {
110 return $this->target->whereAdd('textsearch @@ plainto_tsquery(\''.addslashes($q).'\')');
111 } else if ('notice' === $this->table) {
113 // XXX: We need to filter out gateway notices (notice.is_local = -2) --Zach
115 return $this->target->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\''.addslashes($q).'\')');
117 throw new ServerException('Unknown table: ' . $this->table);