Initial upload for secondary development

This commit is contained in:
2026-06-08 19:00:03 +08:00
commit b913b8c78c
81 changed files with 27139 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import jieba
import re
def tokenize(text: str) -> str:
return " ".join(jieba.cut(text))
def build_match_query(text: str, limit: int = 12) -> str:
"""Build a safe FTS5 MATCH query from user/model text."""
terms: list[str] = []
seen: set[str] = set()
for token in tokenize(text or "").split():
token = token.strip()
if not token or not re.search(r"\w", token, flags=re.UNICODE):
continue
upper = token.upper()
if upper in {"AND", "OR", "NOT", "NEAR"}:
continue
if token in seen:
continue
seen.add(token)
terms.append('"' + token.replace('"', '""') + '"')
if len(terms) >= limit:
break
return " OR ".join(terms)