]> git.mxchange.org Git - friendica.git/commitdiff
Special search keywords added
authorMichael <heluecht@pirati.ca>
Fri, 22 Sep 2023 10:28:00 +0000 (10:28 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 22 Sep 2023 10:28:00 +0000 (10:28 +0000)
database.sql
src/Model/Post/Engagement.php
src/Module/Conversation/Timeline.php
src/Module/Settings/Channels.php
static/dbview.config.php

index 25f94cac85bbe11cca9a411e0eba4d13487396ad..a2b5887752e0d1cc4e0da2febd4f0a493871eaf2 100644 (file)
@@ -2090,6 +2090,7 @@ CREATE VIEW `post-user-view` AS SELECT
        `author`.`blocked` AS `author-blocked`,
        `author`.`hidden` AS `author-hidden`,
        `author`.`updated` AS `author-updated`,
+       `author`.`contact-type` AS `author-contact-type`,
        `author`.`gsid` AS `author-gsid`,
        `author`.`baseurl` AS `author-baseurl`,
        `post-user`.`owner-id` AS `owner-id`,
@@ -2274,6 +2275,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `author`.`blocked` AS `author-blocked`,
        `author`.`hidden` AS `author-hidden`,
        `author`.`updated` AS `author-updated`,
+       `author`.`contact-type` AS `author-contact-type`,
        `author`.`gsid` AS `author-gsid`,
        `post-thread-user`.`owner-id` AS `owner-id`,
        `owner`.`uri-id` AS `owner-uri-id`,
@@ -2442,6 +2444,7 @@ CREATE VIEW `post-view` AS SELECT
        `author`.`blocked` AS `author-blocked`,
        `author`.`hidden` AS `author-hidden`,
        `author`.`updated` AS `author-updated`,
+       `author`.`contact-type` AS `author-contact-type`,
        `author`.`gsid` AS `author-gsid`,
        `post`.`owner-id` AS `owner-id`,
        `owner`.`uri-id` AS `owner-uri-id`,
@@ -2587,6 +2590,7 @@ CREATE VIEW `post-thread-view` AS SELECT
        `author`.`blocked` AS `author-blocked`,
        `author`.`hidden` AS `author-hidden`,
        `author`.`updated` AS `author-updated`,
+       `author`.`contact-type` AS `author-contact-type`,
        `author`.`gsid` AS `author-gsid`,
        `post-thread`.`owner-id` AS `owner-id`,
        `owner`.`uri-id` AS `owner-uri-id`,
index 3aec0c1e1201333fa4be97872b4fc867a6fd5834..a23fe01840931d69a10415665b16a140932a718a 100644 (file)
@@ -53,8 +53,8 @@ class Engagement
                        return;
                }
 
-               $parent = Post::selectFirst(['uri-id', 'created', 'owner-id', 'uid', 'private', 'contact-contact-type', 'language',
-                       'title', 'content-warning', 'body', 'author-name', 'author-nick', 'author-addr', 'owner-name', 'owner-nick', 'owner-addr'],
+               $parent = Post::selectFirst(['uri-id', 'created', 'author-id', 'owner-id', 'uid', 'private', 'contact-contact-type', 'language', 'network',
+                       'title', 'content-warning', 'body', 'author-contact-type', 'author-nick', 'author-addr', 'owner-contact-type', 'owner-nick', 'owner-addr'],
                        ['uri-id' => $item['parent-uri-id']]);
 
                if ($parent['created'] < DateTimeFormat::utc('now - ' . DI::config()->get('channel', 'engagement_hours') . ' hour')) {
@@ -110,9 +110,52 @@ class Engagement
 
        private static function getSearchText(array $item): string
        {
-               $body = $item['title'] . ' ' . $item['content-warning'] . ' ' . $item['body'] . ' ' .
-                       $item['author-name'] . ' ' . $item['author-nick'] . ' ' . $item['author-addr'] . ' ' . 
-                       $item['owner-name'] . ' ' . $item['owner-nick'] . ' ' . $item['owner-addr']; 
+               $body = '[nosmile]network:' . $item['network'];
+
+               switch ($item['private']) {
+                       case Item::PUBLIC:
+                               $body .= ' visibility:public';
+                               break;
+                       case Item::UNLISTED:
+                               $body .= ' visibility:unlisted';
+                               break;
+                       case Item::PRIVATE:
+                               $body .= ' visibility:private';
+                               break;
+               }
+
+               if ($item['author-contact-type'] == Contact::TYPE_COMMUNITY) {
+                       $body .= ' group:' . $item['author-nick'] . ' group:' . $item['author-addr'];
+               } elseif (in_array($item['author-contact-type'], [Contact::TYPE_PERSON, Contact::TYPE_NEWS, Contact::TYPE_ORGANISATION])) {
+                       $body .= ' from:' . $item['author-nick'] . ' from:' . $item['author-addr'];
+               }
+
+               if ($item['author-id'] !=  $item['owner-id']) {
+                       if ($item['owner-contact-type'] == Contact::TYPE_COMMUNITY) {
+                               $body .= ' group:' . $item['owner-nick'] . ' group:' . $item['owner-addr'];
+                       } elseif (in_array($item['owner-contact-type'], [Contact::TYPE_PERSON, Contact::TYPE_NEWS, Contact::TYPE_ORGANISATION])) {
+                               $body .= ' from:' . $item['owner-nick'] . ' from:' . $item['owner-addr'];
+                       }
+               }
+
+               foreach (Tag::getByURIId($item['uri-id'], [Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION, Tag::AUDIENCE]) as $tag) {
+                       $contact = Contact::getByURL($tag['name'], false, ['nick', 'addr', 'contact-type']);
+                       if (empty($contact)) {
+                               continue;
+                       }
+
+                       if (($contact['contact-type'] == Contact::TYPE_COMMUNITY) && !strpos($body, 'group:' . $contact['addr'])) {
+                               $body .= ' group:' . $contact['nick'] . ' group:' . $contact['addr'];
+                       } elseif (in_array($contact['contact-type'], [Contact::TYPE_PERSON, Contact::TYPE_NEWS, Contact::TYPE_ORGANISATION])) {
+                               $body .= ' to:' . $contact['nick'] . ' to:' . $contact['addr'];
+                       }
+               }
+
+               foreach (Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]) as $tag) {
+                       $body .= ' tag:' . $tag['name'];
+               }
+
+               $body .= ' ' . $item['title'] . ' ' . $item['content-warning'] . ' ' . $item['body'];
 
                $body = Post\Media::addAttachmentsToBody($item['uri-id'], $body);
                $text = BBCode::toPlaintext($body, false);
index 44149d1ecc0edb18752b9232359bdc6f51342618..a33bee4d072d8d5ff8de3139f9614fca5a631502 100644 (file)
@@ -376,7 +376,11 @@ class Timeline extends BaseModule
                $condition = [];
 
                if (!empty($channel->fullTextSearch)) {
-                       $condition = DBA::mergeConditions($condition, ["MATCH (`searchtext`) AGAINST (? IN BOOLEAN MODE)", $channel->fullTextSearch]);
+                       $search = $channel->fullTextSearch;
+                       foreach (['from', 'to', 'group', 'tag', 'network', 'visibility'] as $keyword) {
+                               $search = preg_replace('~(' . $keyword . ':.[\w@\.-]+)~', '"$1"', $search);
+                       }
+                       $condition = DBA::mergeConditions($condition, ["MATCH (`searchtext`) AGAINST (? IN BOOLEAN MODE)", $search]);
                }
 
                if (!empty($channel->includeTags)) {
index ca9e8d168667f6539242d9dbc0bf9ae2978cb77a..0d4f47e148b1af002fc5573b57004af1760a8036 100644 (file)
@@ -134,7 +134,7 @@ class Channels extends BaseSettings
                        'access_key'   => ["new_access_key", $this->t("Access Key"), '', $this->t('When you want to access this channel via an access key, you can define it here. Pay attentioon to not use an already used one.')],
                        'include_tags' => ["new_include_tags", $this->t("Include Tags"), '', $this->t('Comma separated list of tags. A post will be used when it contains any of the listed tags.')],
                        'exclude_tags' => ["new_exclude_tags", $this->t("Exclude Tags"), '', $this->t('Comma separated list of tags. If a post contain any of these tags, then it will not be part of nthis channel.')],
-                       'text_search'  => ["new_text_search", $this->t("Full Text Search"), '', $this->t('Search terms for the body.')],
+                       'text_search'  => ["new_text_search", $this->t("Full Text Search"), '', $this->t('Search terms for the body.')], // @todo Add dcumentation for the keywords
                        'image'        => ['new_image', $this->t("Images"), false, $this->t("Check to display images in the channel.")],
                        'video'        => ["new_video", $this->t("Videos"), false, $this->t("Check to display videos in the channel.")],
                        'audio'        => ["new_audio", $this->t("Audio"), false, $this->t("Check to display audio in the channel.")],
index d688cef3faabdb464fb8e6b88e260ad424ee8137..057c8fccc5cc370955d79b45925853e60b278dd3 100644 (file)
                        "author-blocked" => ["author", "blocked"],
                        "author-hidden" => ["author", "hidden"],
                        "author-updated" => ["author", "updated"],
+                       "author-contact-type" => ["author", "contact-type"],
                        "author-gsid" => ["author", "gsid"],
                        "author-baseurl" => ["author", "baseurl"],
                        "owner-id" => ["post-user", "owner-id"],
                        "author-blocked" => ["author", "blocked"],
                        "author-hidden" => ["author", "hidden"],
                        "author-updated" => ["author", "updated"],
+                       "author-contact-type" => ["author", "contact-type"],
                        "author-gsid" => ["author", "gsid"],
                        "owner-id" => ["post-thread-user", "owner-id"],
                        "owner-uri-id" => ["owner", "uri-id"],
                        "author-blocked" => ["author", "blocked"],
                        "author-hidden" => ["author", "hidden"],
                        "author-updated" => ["author", "updated"],
+                       "author-contact-type" => ["author", "contact-type"],
                        "author-gsid" => ["author", "gsid"],
                        "owner-id" => ["post", "owner-id"],
                        "owner-uri-id" => ["owner", "uri-id"],
                        "author-blocked" => ["author", "blocked"],
                        "author-hidden" => ["author", "hidden"],
                        "author-updated" => ["author", "updated"],
+                       "author-contact-type" => ["author", "contact-type"],
                        "author-gsid" => ["author", "gsid"],
                        "owner-id" => ["post-thread", "owner-id"],
                        "owner-uri-id" => ["owner", "uri-id"],