mirror of
https://github.com/friendica/friendica
synced 2024-12-22 23:20:16 +00:00
Validate full search text
This commit is contained in:
parent
b2dd95affa
commit
b48467c3f8
6 changed files with 28 additions and 3 deletions
|
@ -506,6 +506,7 @@ CREATE TABLE IF NOT EXISTS `channel` (
|
|||
`media-type` smallint unsigned COMMENT 'Filtered media types',
|
||||
`languages` mediumtext COMMENT 'Desired languages',
|
||||
`publish` boolean COMMENT 'publish channel content',
|
||||
`valid` boolean COMMENT 'Set, when the full-text-search is valid',
|
||||
PRIMARY KEY(`id`),
|
||||
INDEX `uid` (`uid`),
|
||||
FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
|
||||
|
|
|
@ -20,6 +20,7 @@ Fields
|
|||
| media-type | Filtered media types | smallint unsigned | YES | | NULL | |
|
||||
| languages | Desired languages | mediumtext | YES | | NULL | |
|
||||
| publish | publish channel content | boolean | YES | | NULL | |
|
||||
| valid | Set, when the full-text-search is valid | boolean | YES | | NULL | |
|
||||
|
||||
Indexes
|
||||
------------
|
||||
|
|
|
@ -64,8 +64,10 @@ class Timeline extends \Friendica\BaseEntity
|
|||
protected $languages;
|
||||
/** @var bool */
|
||||
protected $publish;
|
||||
/** @var bool */
|
||||
protected $valid;
|
||||
|
||||
public function __construct(string $code = null, string $label = null, string $description = null, string $accessKey = null, string $path = null, int $uid = null, string $includeTags = null, string $excludeTags = null, string $fullTextSearch = null, int $mediaType = null, int $circle = null, array $languages = null, bool $publish = null)
|
||||
public function __construct(string $code = null, string $label = null, string $description = null, string $accessKey = null, string $path = null, int $uid = null, string $includeTags = null, string $excludeTags = null, string $fullTextSearch = null, int $mediaType = null, int $circle = null, array $languages = null, bool $publish = null, bool $valid = null)
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->label = $label;
|
||||
|
@ -80,5 +82,6 @@ class Timeline extends \Friendica\BaseEntity
|
|||
$this->circle = $circle;
|
||||
$this->languages = $languages;
|
||||
$this->publish = $publish;
|
||||
$this->valid = $valid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ final class UserDefinedChannel extends Timeline implements ICanCreateFromTableRo
|
|||
$row['circle'] ?? null,
|
||||
$row['languages'] ?? null,
|
||||
$row['publish'] ?? null,
|
||||
$row['valid'] ?? null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,6 +134,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
'media-type' => $Channel->mediaType,
|
||||
'languages' => serialize($Channel->languages),
|
||||
'publish' => $Channel->publish,
|
||||
'valid' => $this->isValid($Channel->fullTextSearch),
|
||||
];
|
||||
|
||||
if ($Channel->code) {
|
||||
|
@ -149,6 +150,18 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
return $Channel;
|
||||
}
|
||||
|
||||
private function isValid(string $searchtext): bool
|
||||
{
|
||||
if ($searchtext == '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->db->insert('check-full-text-search', ['pid' => getmypid(), 'searchtext' => $searchtext], Database::INSERT_UPDATE);
|
||||
$result = $this->db->select('check-full-text-search', [], ["`pid` = ? AND MATCH (`searchtext`) AGAINST (? IN BOOLEAN MODE)", getmypid(), $this->escapeKeywords($searchtext)]);
|
||||
$this->db->delete('check-full-text-search', ['pid' => getmypid()]);
|
||||
return $result !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -214,7 +227,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
|
||||
$uids = [];
|
||||
|
||||
$condition = ['uid' => $channelUids];
|
||||
$condition = ['uid' => $channelUids, 'valid' => true];
|
||||
if (!$relayMode) {
|
||||
$condition = DBA::mergeConditions($condition, ["`full-text-search` != ?", '']);
|
||||
} else {
|
||||
|
@ -298,11 +311,16 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
}
|
||||
|
||||
private function inFulltext(string $fullTextSearch): bool
|
||||
{
|
||||
return $this->db->exists('check-full-text-search', ["`pid` = ? AND MATCH (`searchtext`) AGAINST (? IN BOOLEAN MODE)", getmypid(), $this->escapeKeywords($fullTextSearch)]);
|
||||
}
|
||||
|
||||
private function escapeKeywords(string $fullTextSearch): string
|
||||
{
|
||||
foreach (Engagement::KEYWORDS as $keyword) {
|
||||
$fullTextSearch = preg_replace('~(' . $keyword . ':.[\w@\.-]+)~', '"$1"', $fullTextSearch);
|
||||
}
|
||||
return $this->db->exists('check-full-text-search', ["`pid` = ? AND MATCH (`searchtext`) AGAINST (? IN BOOLEAN MODE)", getmypid(), $fullTextSearch]);
|
||||
return $fullTextSearch;
|
||||
}
|
||||
|
||||
private function getUserCondition()
|
||||
|
|
|
@ -564,6 +564,7 @@ return [
|
|||
"media-type" => ["type" => "smallint unsigned", "comment" => "Filtered media types"],
|
||||
"languages" => ["type" => "mediumtext", "comment" => "Desired languages"],
|
||||
"publish" => ["type" => "boolean", "comment" => "publish channel content"],
|
||||
"valid" => ["type" => "boolean", "comment" => "Set, when the full-text-search is valid"],
|
||||
],
|
||||
"indexes" => [
|
||||
"PRIMARY" => ["id"],
|
||||
|
|
Loading…
Reference in a new issue