@velvetmonkey/vault-core 2.12.8 → 2.12.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/queries.js +22 -10
- package/package.json +1 -1
package/dist/queries.js
CHANGED
|
@@ -45,7 +45,10 @@ export function searchEntities(stateDb, query, limit = 20) {
|
|
|
45
45
|
* @param limit - Maximum results to return
|
|
46
46
|
*/
|
|
47
47
|
export function searchEntitiesPrefix(stateDb, prefix, limit = 20) {
|
|
48
|
-
|
|
48
|
+
// Append `*` BEFORE escaping so the suffix-aware quoter places it correctly
|
|
49
|
+
// (quoted phrase + outer `*` for prefix search). Pre-escaping here would
|
|
50
|
+
// produce already-quoted input that the second escape pass cannot reuse.
|
|
51
|
+
return searchEntities(stateDb, `${prefix}*`, limit);
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
51
54
|
* Get entity by exact name (case-insensitive)
|
|
@@ -341,20 +344,29 @@ export function escapeFts5Query(query) {
|
|
|
341
344
|
phrases.push(`"${phrase.replace(/"/g, '""')}"`);
|
|
342
345
|
return '';
|
|
343
346
|
});
|
|
344
|
-
// Clean remaining tokens
|
|
347
|
+
// Clean remaining tokens. Strips FTS5 syntax punctuation (`:` and `-` previously
|
|
348
|
+
// tripped queries like `2026-05-08` → SQLite parsed `05` as a column reference,
|
|
349
|
+
// returning `no such column: 05`). `+`, `.`, `_` were also unhandled — see
|
|
350
|
+
// 2026-05-08 morning-briefing failure.
|
|
345
351
|
const cleaned = withoutPhrases
|
|
346
|
-
.replace(/[(){}[\]
|
|
352
|
+
.replace(/[(){}[\]^~:+._-]/g, ' ')
|
|
347
353
|
.replace(/\s+/g, ' ')
|
|
348
354
|
.trim();
|
|
349
|
-
// Split into tokens, skip explicit AND/OR/NOT
|
|
350
|
-
const tokens = cleaned
|
|
351
|
-
|
|
355
|
+
// Split into tokens, skip explicit FTS5 operators (AND/OR/NOT/NEAR).
|
|
356
|
+
const tokens = cleaned
|
|
357
|
+
.split(' ')
|
|
358
|
+
.filter(t => t && t !== 'AND' && t !== 'OR' && t !== 'NOT' && t !== 'NEAR');
|
|
359
|
+
// Wrap each token as an FTS5 phrase literal so bareword reserved keywords and
|
|
360
|
+
// numeric tokens cannot be parsed as column references. Preserve trailing `*`
|
|
361
|
+
// for prefix search by placing it OUTSIDE the quotes (`"foo"*` not `"foo*"`).
|
|
362
|
+
const safeTokens = tokens.map(t => t.endsWith('*') ? `"${t.slice(0, -1)}"*` : `"${t}"`);
|
|
363
|
+
// Combine: quoted phrases + OR-joined safe tokens
|
|
352
364
|
const parts = [...phrases];
|
|
353
|
-
if (
|
|
354
|
-
parts.push(
|
|
365
|
+
if (safeTokens.length === 1) {
|
|
366
|
+
parts.push(safeTokens[0]);
|
|
355
367
|
}
|
|
356
|
-
else if (
|
|
357
|
-
parts.push(
|
|
368
|
+
else if (safeTokens.length > 1) {
|
|
369
|
+
parts.push(safeTokens.join(' OR '));
|
|
358
370
|
}
|
|
359
371
|
return parts.join(' ') || '';
|
|
360
372
|
}
|
package/package.json
CHANGED