]> git.mxchange.org Git - friendica.git/commitdiff
Improved performance with full text search
authorMichael <heluecht@pirati.ca>
Wed, 10 Jan 2024 21:17:21 +0000 (21:17 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 28 Jan 2024 15:37:43 +0000 (16:37 +0100)
src/Content/Conversation/Repository/UserDefinedChannel.php
src/Model/Post/Engagement.php
src/Protocol/ActivityPub/Processor.php

index bb8ad02f6b71d4346cb8a70cb38e8114b4b66c38..37e3ff06ff7af46607941d46dc7788054bf0c03b 100644 (file)
@@ -163,17 +163,13 @@ class UserDefinedChannel extends \Friendica\BaseRepository
        }
 
        /**
-        * Checks, if one of the user defined channels matches with the given search text
-        * @todo Combine all the full text statements in a single search text to improve the performance.
-        * Add a "valid" field for the channel that is set when the full text statement doesn't contain errors.
+        * Checks, if one of the user defined channels matches with the given search text or languages
         *
         * @param string $searchtext
         * @param string $language
-        * @param array  $tags
-        * @param int    $media_type
         * @return boolean
         */
-       public function match(string $searchtext, string $language, array $tags, int $media_type): bool
+       public function match(string $searchtext, string $language): bool
        {
                $users = $this->db->selectToArray('user', ['uid'], $this->getUserCondition());
                if (empty($users)) {
@@ -182,16 +178,24 @@ class UserDefinedChannel extends \Friendica\BaseRepository
 
                $uids = array_column($users, 'uid');
 
-               $condition = ['uid' => $uids];
-               $condition = DBA::mergeConditions($condition, ["`languages` != ? AND `include-tags` = ? AND `full-text-search` = ? AND circle = ?", '', '', '', 0]);
-
+               $usercondition = ['uid' => $uids];
+               $condition = DBA::mergeConditions($usercondition, ["`languages` != ? AND `include-tags` = ? AND `full-text-search` = ? AND `circle` = ?", '', '', '', 0]);
                foreach ($this->select($condition) as $channel) {
                        if (!empty($channel->languages) && in_array($language, $channel->languages)) {
                                return true;
                        }
                }
 
-               return !empty($this->getMatches($searchtext, $language, $tags, $media_type, 0, 0, $uids, false));
+               $search = '';
+               $condition = DBA::mergeConditions($usercondition, ["`full-text-search` != ? AND `circle` = ? AND `valid`", '', 0]);
+               foreach ($this->select($condition) as $channel) {
+                       $search .= '(' . $channel->fullTextSearch . ') ';
+               }
+
+               $this->db->insert('check-full-text-search', ['pid' => getmypid(), 'searchtext' => $searchtext], Database::INSERT_UPDATE);
+               $result = $this->inFulltext($search);
+               $this->db->delete('check-full-text-search', ['pid' => getmypid()]);
+               return $result;
        }
 
        /**
index 0476e08ca21eb073310a9cab51881894e894f9e7..61f73948de248db9bfd6294465470afa7f58927e 100644 (file)
@@ -91,9 +91,8 @@ class Engagement
 
                $searchtext = self::getSearchTextForItem($parent);
                if (!$store) {
-                       $tags     = array_column(Tag::getByURIId($item['parent-uri-id'], [Tag::HASHTAG]), 'name');
                        $language = !empty($parent['language']) ? (array_key_first(json_decode($parent['language'], true)) ?? '') : '';
-                       $store    = DI::userDefinedChannel()->match($searchtext, $language, $tags, $mediatype);
+                       $store    = DI::userDefinedChannel()->match($searchtext, $language);
                }
 
                $engagement = [
index f0fbf1185aeee974718efca0eb37cb33a62eb56f..593c1e783622743d0474d60275e5f424372c4f22 100644 (file)
@@ -1787,7 +1787,7 @@ class Processor
                $searchtext = Engagement::getSearchTextForActivity($content, $authorid, $messageTags, $receivers);
                $languages  = Item::getLanguageArray($content, 1, 0, $authorid);
                $language   = !empty($languages) ? array_key_first($languages) : '';
-               return DI::userDefinedChannel()->match($searchtext, $language, $messageTags, 0);
+               return DI::userDefinedChannel()->match($searchtext, $language);
        }
 
        /**