3 * StatusNet, the distributed open-source microblogging tool
5 * Action for showing Twitter-like JSON search results
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2008-2010 StatusNet, Inc.
26 * @copyright 2013 Free Software Foundation, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://www.gnu.org/software/social/
31 if (!defined('GNUSOCIAL')) { exit(1); }
34 * Action handler for Twitter-compatible API search
38 * @author Zach Copley <zach@status.net>
39 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
40 * @link http://status.net/
43 class ApiSearchJSONAction extends ApiPrivateAuthAction
56 * @param array $args Web and URL arguments
58 * @return boolean true if nothing goes wrong
60 function prepare(array $args = array())
62 parent::prepare($args);
64 $this->query = $this->trimmed('q');
65 $this->lang = $this->trimmed('lang');
66 $this->rpp = $this->trimmed('rpp');
72 if ($this->rpp > 100) {
76 $this->page = $this->trimmed('page');
82 // TODO: Suppport max_id -- we need to tweak the backend
83 // Search classes to support it.
85 $this->since_id = $this->trimmed('since_id');
86 $this->geocode = $this->trimmed('geocode');
94 * @param array $args Arguments from $_REQUEST
101 $this->showResults();
105 * Show search results
109 function showResults()
111 // TODO: Support search operators like from: and to:, boolean, etc.
113 $notice = new Notice();
115 $this->notices = array();
116 $search_engine = $notice->getSearchEngine('notice');
117 $search_engine->set_sort_mode('chron');
118 $search_engine->limit(($this->page - 1) * $this->rpp, $this->rpp + 1);
119 if ($search_engine->query($this->query)) {
120 $cnt = $notice->find();
121 $this->notices = $notice->fetchAll();
124 $this->showJsonTimeline($this->notices);
128 * Do we need to write to the database?
130 * @return boolean true
132 function isReadOnly($args)