Commit eb8812e
Changed files (1)
src
history
src/history/query.py
@@ -165,7 +165,8 @@ async def query_turso(client: Client, table_name: str, match_time: str, user: st
# ruff: noqa: S608
cid = int(table_name.split("-")[0])
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}"'"""
+ texts_to_match = keyword if segmented == keyword else f'"{keyword}" OR "{segmented}"' # must use double quotes for inner part
+ 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 '{texts_to_match}' ORDER BY T.mid DESC"
if match_time:
if len(match_time) == 4: # 2025
begin = f"{match_time}-01-01 00:00:00"