Include more field in the fulltext search

This commit is contained in:
Michael 2020-09-19 10:45:11 +00:00
parent dfeae25e6d
commit 86592daaa1
3 changed files with 11 additions and 3 deletions

View file

@ -31,7 +31,7 @@ class ItemContent
{ {
public static function getURIIdListBySearch(string $search, int $uid = 0, int $start = 0, int $limit = 100) public static function getURIIdListBySearch(string $search, int $uid = 0, int $start = 0, int $limit = 100)
{ {
$condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`body`) AGAINST (? IN BOOLEAN MODE)) $condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE))
AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid]; AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid];
$params = [ $params = [
'order' => ['uri-id' => true], 'order' => ['uri-id' => true],
@ -50,6 +50,13 @@ class ItemContent
return $uriids; return $uriids;
} }
public static function countBySearch(string $search, int $uid = 0)
{
$condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE))
AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid];
return DBA::count('item', $condition);
}
/** /**
* Convert a message into plaintext for connectors to other networks * Convert a message into plaintext for connectors to other networks
* *

View file

@ -152,16 +152,17 @@ class Index extends BaseSearch
if ($tag) { if ($tag) {
Logger::info('Start tag search.', ['q' => $search]); Logger::info('Start tag search.', ['q' => $search]);
$uriids = Tag::getURIIdListByTag($search, local_user(), $pager->getStart(), $pager->getItemsPerPage()); $uriids = Tag::getURIIdListByTag($search, local_user(), $pager->getStart(), $pager->getItemsPerPage());
$count = Tag::countByTag($search, local_user());
} else { } else {
Logger::info('Start fulltext search.', ['q' => $search]); Logger::info('Start fulltext search.', ['q' => $search]);
$uriids = ItemContent::getURIIdListBySearch($search, local_user(), $pager->getStart(), $pager->getItemsPerPage()); $uriids = ItemContent::getURIIdListBySearch($search, local_user(), $pager->getStart(), $pager->getItemsPerPage());
$count = ItemContent::countBySearch($search, local_user());
} }
if (!empty($uriids)) { if (!empty($uriids)) {
$params = ['order' => ['id' => true], 'group_by' => ['uri-id']]; $params = ['order' => ['id' => true], 'group_by' => ['uri-id']];
$items = Item::selectForUser(local_user(), [], ['uri-id' => $uriids], $params); $items = Item::selectForUser(local_user(), [], ['uri-id' => $uriids], $params);
$r = Item::inArray($items); $r = Item::inArray($items);
$count = Tag::countByTag($search, local_user());
} else { } else {
$count = 0; $count = 0;
} }

View file

@ -857,7 +857,7 @@ return [
"indexes" => [ "indexes" => [
"PRIMARY" => ["id"], "PRIMARY" => ["id"],
"uri-plink-hash" => ["UNIQUE", "uri-plink-hash"], "uri-plink-hash" => ["UNIQUE", "uri-plink-hash"],
"body" => ["FULLTEXT", "body"], "title-content-warning-body" => ["FULLTEXT", "title", "content-warning", "body"],
"uri" => ["uri(191)"], "uri" => ["uri(191)"],
"plink" => ["plink(191)"], "plink" => ["plink(191)"],
"uri-id" => ["uri-id"] "uri-id" => ["uri-id"]