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')) {
29 function __construct($target, $table)
31 $this->target = $target;
32 $this->table = $table;
39 function limit($offset, $count, $rss = false)
41 return $this->target->limit($offset, $count);
44 function set_sort_mode($mode)
48 return $this->target->orderBy('created DESC');
51 return $this->target->orderBy('created ASC');
54 if ($this->table != 'profile') {
56 'nickname_desc sort mode can only be use when searching profile.'
59 return $this->target->orderBy(sprintf('%1$s.nickname DESC', $this->table));
63 if ($this->table != 'profile') {
65 'nickname_desc sort mode can only be use when searching profile.'
68 return $this->target->orderBy(sprintf('%1$s.nickname ASC', $this->table));
72 return $this->target->orderBy('created DESC');
78 class MySQLSearch extends SearchEngine
82 if ('profile' === $this->table) {
83 $this->target->whereAdd(
84 sprintf('MATCH (%2$s.nickname, %2$s.fullname, %2$s.location, %2$s.bio, %2$s.homepage) ' .
85 'AGAINST ("%1$s" IN BOOLEAN MODE)',
86 $this->target->escape($q, true),
89 if (strtolower($q) != $q) {
90 $this->target->whereAdd(
91 sprintf('MATCH (%2$s.nickname, %2$s.fullname, %2$s.location, %2$s.bio, %2$s.homepage) ' .
92 'AGAINST ("%1$s" IN BOOLEAN MODE)',
93 $this->target->escape(strtolower($q), true),
99 } else if ('notice' === $this->table) {
101 // Don't show imported notices
102 $this->target->whereAdd('notice.is_local != ' . Notice::GATEWAY);
104 $this->target->whereAdd(
105 sprintf('MATCH (%2$s.content) AGAINST ("%1$s" IN BOOLEAN MODE)',
106 $this->target->escape($q, true),
109 if (strtolower($q) != $q) {
110 $this->target->whereAdd(
111 sprintf('MATCH (%2$s.content) AGAINST ("%1$s" IN BOOLEAN MODE)',
112 $this->target->escape(strtolower($q), true),
120 throw new ServerException('Unknown table: ' . $this->table);
125 class MySQLLikeSearch extends SearchEngine
129 if ('profile' === $this->table) {
130 $qry = sprintf('(%2$s.nickname LIKE "%%%1$s%%" OR ' .
131 ' %2$s.fullname LIKE "%%%1$s%%" OR ' .
132 ' %2$s.location LIKE "%%%1$s%%" OR ' .
133 ' %2$s.bio LIKE "%%%1$s%%" OR ' .
134 ' %2$s.homepage LIKE "%%%1$s%%")',
135 $this->target->escape($q, true),
137 } else if ('notice' === $this->table) {
138 $qry = sprintf('content LIKE "%%%1$s%%"', $this->target->escape($q, true));
140 throw new ServerException('Unknown table: ' . $this->table);
143 $this->target->whereAdd($qry);
149 class PGSearch extends SearchEngine
153 if ('profile' === $this->table) {
154 return $this->target->whereAdd('textsearch @@ plainto_tsquery(\'' . $this->target->escape($q) . '\')');
155 } else if ('notice' === $this->table) {
157 // XXX: We need to filter out gateway notices (notice.is_local = -2) --Zach
159 return $this->target->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\'' . $this->target->escape($q) . '\')');
161 throw new ServerException('Unknown table: ' . $this->table);