Validate full search text
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user