API search is now done via "tag" as well

This commit is contained in:
Michael 2020-05-01 09:41:17 +00:00
parent 8602bbb3b9
commit 2b8dabcd95
3 changed files with 12 additions and 19 deletions

View File

@ -1540,32 +1540,24 @@ function api_search($type)
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
if (preg_match('/^#(\w+)$/', $searchTerm, $matches) === 1 && isset($matches[1])) { if (preg_match('/^#(\w+)$/', $searchTerm, $matches) === 1 && isset($matches[1])) {
$searchTerm = $matches[1]; $searchTerm = $matches[1];
/// @todo $uriids = Tag::getURIIdListForTag($searchTerm, local_user()); $condition = ["`iid` > ? AND `name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $since_id, $searchTerm, local_user()];
$condition = ["`oid` > ? $tags = DBA::select('tag-search-view', ['uri-id'], $condition);
AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) $uriids = [];
AND `otype` = ? AND `type` = ? AND `term` = ?", while ($tag = DBA::fetch($tags)) {
$since_id, local_user(), Term::OBJECT_TYPE_POST, Tag::HASHTAG, $searchTerm]; $uriids[] = $tag['uri-id'];
if ($max_id > 0) {
$condition[0] .= ' AND `oid` <= ?';
$condition[] = $max_id;
} }
$terms = DBA::select('term', ['oid'], $condition, []); DBA::close($tags);
$itemIds = [];
while ($term = DBA::fetch($terms)) {
$itemIds[] = $term['oid'];
}
DBA::close($terms);
if (empty($itemIds)) { if (empty($uriids)) {
return api_format_data('statuses', $type, $data); return api_format_data('statuses', $type, $data);
} }
$preCondition = ['`id` IN (' . implode(', ', $itemIds) . ')']; $condition = ['uri-id' => $uriids];
if ($exclude_replies) { if ($exclude_replies) {
$preCondition[] = '`id` = `parent`'; $condition['gravity'] = GRAVITY_PARENT;
} }
$condition = [implode(' AND ', $preCondition)]; $params['group_by'] = ['uri-id'];
} else { } else {
$condition = ["`id` > ? $condition = ["`id` > ?
" . ($exclude_replies ? " AND `id` = `parent` " : ' ') . " " . ($exclude_replies ? " AND `id` = `parent` " : ' ') . "

View File

@ -51,7 +51,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1342); define('DB_UPDATE_VERSION', 1343);
} }
return [ return [

View File

@ -223,6 +223,7 @@ return [
"tag-search-view" => [ "tag-search-view" => [
"fields" => [ "fields" => [
"uri-id" => ["post-tag", "uri-id"], "uri-id" => ["post-tag", "uri-id"],
"iid" => ["item", "id"],
"uri" => ["item", "uri"], "uri" => ["item", "uri"],
"guid" => ["item", "guid"], "guid" => ["item", "guid"],
"uid" => ["item", "uid"], "uid" => ["item", "uid"],