]> git.mxchange.org Git - friendica.git/commitdiff
Issue 9165: Make pager work for search
authorMichael <heluecht@pirati.ca>
Thu, 17 Sep 2020 21:10:59 +0000 (21:10 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 17 Sep 2020 21:10:59 +0000 (21:10 +0000)
src/Model/Tag.php
src/Module/Search/Index.php

index 7eb475d727009e8642524895ed2b8a90597ead1c..40f2f8d6a1600ffe0622ca81ec6d09fa0259c482 100644 (file)
@@ -440,6 +440,21 @@ class Tag
                return $return;
        }
 
+       /**
+        * Counts posts for given tag
+        *
+        * @param string $search
+        * @param integer $uid
+        * @return integer number of posts
+        */
+       public static function countByTag(string $search, int $uid = 0)
+       {
+               $condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid];
+               $params = ['group_by' => ['uri-id']];
+
+               return DBA::count('tag-search-view', $condition, $params);
+       }
+
        /**
         * Search posts for given tag
         *
index bf3ae2585b19de398b99ef90f2f9163aa8c35b4c..6cee581c2bf54f80e76e19331eb6f1286f3ab1cb 100644 (file)
@@ -156,8 +156,9 @@ class Index extends BaseSearch
                                $params = ['order' => ['id' => true], 'group_by' => ['uri-id']];
                                $items = Item::selectForUser(local_user(), [], ['uri-id' => $uriids], $params);
                                $r = Item::inArray($items);
+                               $count = Tag::countByTag($search, local_user());
                        } else {
-                               $r = [];
+                               $count = 0;
                        }
                } else {
                        Logger::info('Start fulltext search.', ['q' => $search]);
@@ -173,6 +174,7 @@ class Index extends BaseSearch
                        ];
                        $items = Item::selectForUser(local_user(), [], $condition, $params);
                        $r = Item::inArray($items);
+                       $count = DBA::count('item', $condition);
                }
 
                if (!DBA::isResult($r)) {
@@ -194,7 +196,7 @@ class Index extends BaseSearch
 
                $o .= conversation(DI::app(), $r, 'search', false, false, 'commented', local_user());
 
-               $o .= $pager->renderMinimal(count($r));
+               $o .= $pager->renderMinimal($count);
 
                return $o;
        }