]> git.mxchange.org Git - friendica.git/commitdiff
API search is now done via "tag" as well
authorMichael <heluecht@pirati.ca>
Fri, 1 May 2020 09:41:17 +0000 (09:41 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 1 May 2020 09:41:17 +0000 (09:41 +0000)
include/api.php
static/dbstructure.config.php
static/dbview.config.php

index 97c30e317acf3f26413d0cb3409e843a8eab7e83..beddc5adcba25105dd30c44d2f5b0dc22499db73 100644 (file)
@@ -1540,32 +1540,24 @@ function api_search($type)
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
        if (preg_match('/^#(\w+)$/', $searchTerm, $matches) === 1 && isset($matches[1])) {
                $searchTerm = $matches[1];
-               /// @todo $uriids = Tag::getURIIdListForTag($searchTerm, local_user());
-               $condition = ["`oid` > ?
-                       AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) 
-                       AND `otype` = ? AND `type` = ? AND `term` = ?",
-                       $since_id, local_user(), Term::OBJECT_TYPE_POST, Tag::HASHTAG, $searchTerm];
-               if ($max_id > 0) {
-                       $condition[0] .= ' AND `oid` <= ?';
-                       $condition[] = $max_id;
-               }
-               $terms = DBA::select('term', ['oid'], $condition, []);
-               $itemIds = [];
-               while ($term = DBA::fetch($terms)) {
-                       $itemIds[] = $term['oid'];
+               $condition = ["`iid` > ? AND `name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $since_id, $searchTerm, local_user()];
+               $tags = DBA::select('tag-search-view', ['uri-id'], $condition);
+               $uriids = [];
+               while ($tag = DBA::fetch($tags)) {
+                       $uriids[] = $tag['uri-id'];
                }
-               DBA::close($terms);
+               DBA::close($tags);
 
-               if (empty($itemIds)) {
+               if (empty($uriids)) {
                        return api_format_data('statuses', $type, $data);
                }
 
-               $preCondition = ['`id` IN (' . implode(', ', $itemIds) . ')'];
+               $condition = ['uri-id' => $uriids];
                if ($exclude_replies) {
-                       $preCondition[] = '`id` = `parent`';
+                       $condition['gravity'] = GRAVITY_PARENT;
                }
 
-               $condition = [implode(' AND ', $preCondition)];
+               $params['group_by'] = ['uri-id'];
        } else {
                $condition = ["`id` > ?
                        " . ($exclude_replies ? " AND `id` = `parent` " : ' ') . "
index 72235d2777d8625b4fef87a5a245f506c04f56e0..2c3a9fb5fd42c3b97899d7773b80dba66db535ba 100755 (executable)
@@ -51,7 +51,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1342);
+       define('DB_UPDATE_VERSION', 1343);
 }
 
 return [
index 59b8686d0bba415b3ec8c65937ff1cede9a7b940..3be78bf6943fa4f29cc5f946ebe61ad8d9045748 100755 (executable)
@@ -223,6 +223,7 @@ return [
        "tag-search-view" => [
                "fields" => [
                        "uri-id" => ["post-tag", "uri-id"],
+                       "iid" => ["item", "id"],
                        "uri" => ["item", "uri"],
                        "guid" => ["item", "guid"],
                        "uid" => ["item", "uid"],