`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
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;
$this->circle = $circle;
$this->languages = $languages;
$this->publish = $publish;
+ $this->valid = $valid;
}
}
'media-type' => $Channel->mediaType,
'languages' => serialize($Channel->languages),
'publish' => $Channel->publish,
+ 'valid' => $this->isValid($Channel->fullTextSearch),
];
if ($Channel->code) {
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.
$uids = [];
- $condition = ['uid' => $channelUids];
+ $condition = ['uid' => $channelUids, 'valid' => true];
if (!$relayMode) {
$condition = DBA::mergeConditions($condition, ["`full-text-search` != ?", '']);
} else {
}
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()
"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"],