New search keyword "language"

This commit is contained in:
Michael 2024-01-17 20:25:49 +00:00
parent ee9a68e40c
commit e9f7ea0afa
2 changed files with 15 additions and 10 deletions

View File

@ -80,6 +80,7 @@ Additionally to the search for content, there are additional keywords that can b
* visibility:public * visibility:public
* visibility:unlisted * visibility:unlisted
* visibility:private * 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. 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" 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"

View File

@ -24,7 +24,6 @@ namespace Friendica\Model\Post;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
@ -39,7 +38,7 @@ use Friendica\Util\DateTimeFormat;
class Engagement 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 * Store engagement data from an item array
@ -204,26 +203,26 @@ class Engagement
switch ($item['private']) { switch ($item['private']) {
case Item::PUBLIC: case Item::PUBLIC:
$body .= ' visibility:public'; $body .= ' visibility_public';
break; break;
case Item::UNLISTED: case Item::UNLISTED:
$body .= ' visibility:unlisted'; $body .= ' visibility_unlisted';
break; break;
case Item::PRIVATE: case Item::PRIVATE:
$body .= ' visibility:private'; $body .= ' visibility_private';
break; break;
} }
if (in_array(Contact::TYPE_COMMUNITY, [$item['author-contact-type'], $item['owner-contact-type']])) { 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) { } elseif ($item['author-contact-type'] == Contact::TYPE_PERSON) {
$body .= ' source:person'; $body .= ' source_person';
} elseif ($item['author-contact-type'] == Contact::TYPE_NEWS) { } elseif ($item['author-contact-type'] == Contact::TYPE_NEWS) {
$body .= ' source:service'; $body .= ' source_service';
} elseif ($item['author-contact-type'] == Contact::TYPE_ORGANISATION) { } elseif ($item['author-contact-type'] == Contact::TYPE_ORGANISATION) {
$body .= ' source:organization'; $body .= ' source_organization';
} elseif ($item['author-contact-type'] == Contact::TYPE_RELAY) { } elseif ($item['author-contact-type'] == Contact::TYPE_RELAY) {
$body .= ' source:application'; $body .= ' source_application';
} }
if ($item['author-contact-type'] == Contact::TYPE_COMMUNITY) { if ($item['author-contact-type'] == Contact::TYPE_COMMUNITY) {
@ -257,6 +256,11 @@ class Engagement
$body .= ' tag_' . $tag; $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']; $body .= ' ' . $item['title'] . ' ' . $item['content-warning'] . ' ' . $item['body'];
return BBCode::toSearchText($body, $item['uri-id']); return BBCode::toSearchText($body, $item['uri-id']);