@velvetmonkey/vault-core 2.0.139 → 2.0.140

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.d.ts CHANGED
@@ -115,7 +115,10 @@ export declare function getStateDbMetadata(stateDb: StateDb): StateDbMetadata;
115
115
  */
116
116
  export declare function isEntityDataStale(stateDb: StateDb, thresholdMs?: number): boolean;
117
117
  /**
118
- * Escape special FTS5 characters in a query
118
+ * Escape special FTS5 characters and convert to OR-joined query.
119
+ * BM25 ranking naturally scores documents with more matching terms higher,
120
+ * so OR semantics gives AND-like results at the top while surfacing partial matches.
121
+ * Preserves quoted phrases as exact matches and * for prefix matching.
119
122
  */
120
123
  export declare function escapeFts5Query(query: string): string;
121
124
  /**
package/dist/queries.js CHANGED
@@ -322,20 +322,37 @@ export function isEntityDataStale(stateDb, thresholdMs = 60 * 60 * 1000 // 1 hou
322
322
  // Utility Functions
323
323
  // =============================================================================
324
324
  /**
325
- * Escape special FTS5 characters in a query
325
+ * Escape special FTS5 characters and convert to OR-joined query.
326
+ * BM25 ranking naturally scores documents with more matching terms higher,
327
+ * so OR semantics gives AND-like results at the top while surfacing partial matches.
328
+ * Preserves quoted phrases as exact matches and * for prefix matching.
326
329
  */
327
330
  export function escapeFts5Query(query) {
328
- // Handle empty query
329
331
  if (!query || !query.trim()) {
330
332
  return '';
331
333
  }
332
- // Remove or escape FTS5 special characters
333
- // Keep * for prefix matching, escape others
334
- return query
335
- .replace(/"/g, '""') // Escape quotes
336
- .replace(/[(){}[\]^~:-]/g, ' ') // Remove special operators including hyphen
337
- .replace(/\s+/g, ' ') // Normalize whitespace
334
+ // Extract quoted phrases first (preserve as AND-joined phrase matches)
335
+ const phrases = [];
336
+ const withoutPhrases = query.replace(/"([^"]+)"/g, (_, phrase) => {
337
+ phrases.push(`"${phrase.replace(/"/g, '""')}"`);
338
+ return '';
339
+ });
340
+ // Clean remaining tokens
341
+ const cleaned = withoutPhrases
342
+ .replace(/[(){}[\]^~:-]/g, ' ')
343
+ .replace(/\s+/g, ' ')
338
344
  .trim();
345
+ // Split into tokens, skip explicit AND/OR/NOT operators
346
+ const tokens = cleaned.split(' ').filter(t => t && t !== 'AND' && t !== 'OR' && t !== 'NOT');
347
+ // Combine: quoted phrases + OR-joined tokens
348
+ const parts = [...phrases];
349
+ if (tokens.length === 1) {
350
+ parts.push(tokens[0]);
351
+ }
352
+ else if (tokens.length > 1) {
353
+ parts.push(tokens.join(' OR '));
354
+ }
355
+ return parts.join(' ') || '';
339
356
  }
340
357
  /**
341
358
  * Rebuild the entities_fts index from the entities table.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velvetmonkey/vault-core",
3
- "version": "2.0.139",
3
+ "version": "2.0.140",
4
4
  "description": "Shared vault utilities for Flywheel ecosystem (entity scanning, wikilinks, protected zones)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",