Commit d082256

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-06-10 04:01:13
fix(history): also query segmented text
1 parent e27bd42
Changed files (1)
src
history
src/history/query.py
@@ -9,7 +9,7 @@ from pyrogram.client import Client
 from pyrogram.parser.markdown import BLOCKQUOTE_EXPANDABLE_DELIM, BLOCKQUOTE_EXPANDABLE_END_DELIM
 from pyrogram.types import Message
 
-from config import PREFIX
+from config import PREFIX, cutter
 from database.turso import turso_exec
 from history.turso import get_table_name
 from history.utils import TURSO_KWARGS, get_uid_by_username, is_admin, list_chat_ids, mtype_emoji
@@ -164,7 +164,8 @@ async def query_turso(client: Client, table_name: str, match_time: str, user: st
     """Query chat history from Turso."""
     # ruff: noqa: S608
     cid = int(table_name.split("-")[0])
-    sql = f"SELECT T.mid, T.mtype, T.time, T.fullname, T.content FROM '{table_name}' AS T JOIN fts_{cid} AS FTS ON T.mid = FTS.rowid WHERE FTS.segmented MATCH '{keyword}'"
+    segmented = " ".join(cutter.cutword(keyword))
+    sql = f"""SELECT T.mid, T.mtype, T.time, T.fullname, T.content FROM '{table_name}' AS T JOIN fts_{cid} AS FTS ON T.mid = FTS.rowid WHERE FTS.segmented MATCH '"{keyword}" OR "{segmented}"'"""
     if match_time:
         if len(match_time) == 4:  # 2025
             begin = f"{match_time}-01-01 00:00:00"