Improved performance with full text search

This commit is contained in:
Michael 2024-01-10 21:17:21 +00:00
parent b48467c3f8
commit dfce85a09f
3 changed files with 16 additions and 13 deletions

View 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;
}
/**

View 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 = [

View 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);
}
/**