feat: make search() FTS-safe; complete Tier 2 helper-shape contract tests

search() falls back to safe per-token quoting on malformed FTS input instead of
crashing (documented in api-reference.md). Adds raw() to the doc-synced shape
contract. Full suite 107/107.
This commit is contained in:
tommy0103
2026-07-08 16:35:10 +08:00
parent 25537d3a53
commit a32461b2ab
5 changed files with 260 additions and 19 deletions
+13
View File
@@ -65,6 +65,19 @@ function searchDb() {
return db;
}
test('search falls back to safe tokenization for FTS-special input instead of throwing', () => {
const db = searchDb();
const api = createQueryApi(db);
// 'needle-reply' is FTS5 operator syntax (a hyphen). Raw MATCH would throw;
// search() must fall back to safe per-token quoting ("needle" "reply") and
// still find the message that contains both tokens.
const rows = api.search('needle-reply', { limit: 5 });
assert.deepEqual(rows.map(r => r.message.uuid), ['msg-text']);
db.close();
});
test('search exposes content_type on hits and temporal context', () => {
const db = searchDb();
const api = createQueryApi(db);