From e9f7ea0afa14e6afcf5f5e61d39b3996a26eb310 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 17 Jan 2024 20:25:49 +0000 Subject: [PATCH] New search keyword "language" --- doc/Channels.md | 1 + src/Model/Post/Engagement.php | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/doc/Channels.md b/doc/Channels.md index de3f6718d8..5c206c7896 100644 --- a/doc/Channels.md +++ b/doc/Channels.md @@ -80,6 +80,7 @@ Additionally to the search for content, there are additional keywords that can b * visibility:public * visibility:unlisted * visibility:private +* language - Use "language:code" to search for posts with the given language in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. Remember that you can combine these kerywords. So for example you can create a channel with all posts that talk about the Fediverse - that aren't posted in the Fediverse with the search terms: "fediverse -network:apub -network:dfrn" \ No newline at end of file diff --git a/src/Model/Post/Engagement.php b/src/Model/Post/Engagement.php index 5047d71dd2..1d1fa11124 100644 --- a/src/Model/Post/Engagement.php +++ b/src/Model/Post/Engagement.php @@ -24,7 +24,6 @@ namespace Friendica\Model\Post; use Friendica\Content\Text\BBCode; use Friendica\Core\Logger; use Friendica\Core\Protocol; -use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; @@ -39,7 +38,7 @@ use Friendica\Util\DateTimeFormat; class Engagement { - const KEYWORDS = ['source', 'server', 'from', 'to', 'group', 'tag', 'network', 'platform', 'visibility']; + const KEYWORDS = ['source', 'server', 'from', 'to', 'group', 'tag', 'network', 'platform', 'visibility', 'language']; /** * Store engagement data from an item array @@ -204,26 +203,26 @@ class Engagement switch ($item['private']) { case Item::PUBLIC: - $body .= ' visibility:public'; + $body .= ' visibility_public'; break; case Item::UNLISTED: - $body .= ' visibility:unlisted'; + $body .= ' visibility_unlisted'; break; case Item::PRIVATE: - $body .= ' visibility:private'; + $body .= ' visibility_private'; break; } if (in_array(Contact::TYPE_COMMUNITY, [$item['author-contact-type'], $item['owner-contact-type']])) { - $body .= ' source:group'; + $body .= ' source_group'; } elseif ($item['author-contact-type'] == Contact::TYPE_PERSON) { - $body .= ' source:person'; + $body .= ' source_person'; } elseif ($item['author-contact-type'] == Contact::TYPE_NEWS) { - $body .= ' source:service'; + $body .= ' source_service'; } elseif ($item['author-contact-type'] == Contact::TYPE_ORGANISATION) { - $body .= ' source:organization'; + $body .= ' source_organization'; } elseif ($item['author-contact-type'] == Contact::TYPE_RELAY) { - $body .= ' source:application'; + $body .= ' source_application'; } if ($item['author-contact-type'] == Contact::TYPE_COMMUNITY) { @@ -257,6 +256,11 @@ class Engagement $body .= ' tag_' . $tag; } + if (!empty($item['language'])) { + $languages = json_decode($item['language'], true); + $body .= ' language_' . array_key_first($languages); + } + $body .= ' ' . $item['title'] . ' ' . $item['content-warning'] . ' ' . $item['body']; return BBCode::toSearchText($body, $item['uri-id']);