From d02cef93ee974546ae10f7ec64ddd15c6368add4 Mon Sep 17 00:00:00 2001 From: celestora Date: Mon, 15 Aug 2022 09:08:07 +0300 Subject: [PATCH] Search hashtags via word index (#655) --- Web/Models/Repositories/Posts.php | 2 +- install/sqls/00029-hashtag-search.sql | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 install/sqls/00029-hashtag-search.sql diff --git a/Web/Models/Repositories/Posts.php b/Web/Models/Repositories/Posts.php index 6dde27c8..7aadc0bb 100644 --- a/Web/Models/Repositories/Posts.php +++ b/Web/Models/Repositories/Posts.php @@ -71,7 +71,7 @@ class Posts { $hashtag = "#$hashtag"; $sel = $this->posts - ->where("content LIKE ?", "%$hashtag%") + ->where("MATCH (content) AGAINST (? IN BOOLEAN MODE)", "+$hashtag") ->where("deleted", 0) ->order("created DESC") ->page($page, $perPage ?? OPENVK_DEFAULT_PER_PAGE); diff --git a/install/sqls/00029-hashtag-search.sql b/install/sqls/00029-hashtag-search.sql new file mode 100644 index 00000000..9aa9618b --- /dev/null +++ b/install/sqls/00029-hashtag-search.sql @@ -0,0 +1 @@ +ALTER TABLE `posts` ADD FULLTEXT `content` (`content`); \ No newline at end of file