Fix matching scope after merge

This commit is contained in:
Donal McBreen
2025-11-21 11:42:07 +00:00
parent 366dbd393c
commit 2e4d0b38db
3 changed files with 7 additions and 5 deletions
+2 -2
View File
@@ -23,8 +23,8 @@ class Search::Record < ApplicationRecord
end
end
scope :matching, ->(query) do
matching_scope(query)
scope :matching, ->(query, account_id) do
matching_scope(query, account_id)
end
scope :for_user, ->(user) do
+1 -1
View File
@@ -15,7 +15,7 @@ module Search::Record::SQLite
self
end
def matching_scope(query)
def matching_scope(query, account_id)
joins("INNER JOIN search_records_fts ON search_records_fts.rowid = #{table_name}.id")
.where("search_records_fts MATCH ?", query)
end
+4 -2
View File
@@ -30,9 +30,11 @@ module Search::Record::Trilogy
Zlib.crc32(account_id.to_s) % SHARD_COUNT
end
def matching_scope(query)
def matching_scope(query, account_id)
stemmed_query = Search::Stemmer.stem(query)
where("MATCH(#{table_name}.content, #{table_name}.title) AGAINST(? IN BOOLEAN MODE)", stemmed_query)
account_key = "account#{account_id}"
full_query = "+#{account_key} +(#{stemmed_query})"
where("MATCH(#{table_name}.account_key, #{table_name}.content, #{table_name}.title) AGAINST(? IN BOOLEAN MODE)", full_query)
end
def search_scope(relation, query)