@yaks/fts 0.0.0-stage → 0.2.36

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/mod.ts ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @yaks/fts — full-text search over a yaks graph, on any text property.
3
+ *
4
+ * Search is not limited to a single "document" component. A vocabulary declares
5
+ * components, and some of their properties hold prose — a book's title, a
6
+ * review's paragraph, a shop's own description. Each such property is marked
7
+ * `"search": true` in the vocabulary; this package indexes every marked
8
+ * property and searches all of them at once.
9
+ *
10
+ * It is four small pieces, each usable on its own:
11
+ *
12
+ * - {@link fields} reads the searchable properties off a
13
+ * {@link https://jsr.io/@yaks/vocab | @yaks/vocab} schema — the ones marked
14
+ * `"search": true`;
15
+ * - {@link schema} returns the SQL that creates the SQLite FTS5 indexes and the
16
+ * triggers that keep them in step with the component tables;
17
+ * - {@link search} — the {@link https://jsr.io/@yaks/sql | @yaks/sql} extension
18
+ * — makes a bare word in a query compile to an FTS5 `match`, so words and
19
+ * filters mix in one query: `hobbit .book.price<20`;
20
+ * - {@link find} ranks the matches and marks each one for display.
21
+ *
22
+ * ```ts
23
+ * import { loadVocab } from '@yaks/vocab'
24
+ * import { graph } from '@yaks/graph'
25
+ * import { storage } from '@yaks/sqlite'
26
+ * import { open } from '@yaks/sqlite/db'
27
+ * import { fields, find, schema, search } from '@yaks/fts'
28
+ * import { compile } from '@yaks/sql'
29
+ * import { parse } from '@yaks/query'
30
+ *
31
+ * let title = { type: 'string', search: true }
32
+ * let price = { type: 'number' }
33
+ * let shop = loadVocab([{
34
+ * $defs: { book: { component: true, properties: { title, price } } },
35
+ * }])
36
+ * let db = open(':memory:')
37
+ * let store = storage(db, shop)
38
+ * for (let stmt of store.ddl()) db.query(stmt)
39
+ *
40
+ * let text = fields(shop) // the properties the vocabulary marks searchable
41
+ * for (let stmt of schema(text)) db.query(stmt)
42
+ * graph({ storage: store, vocab: shop }).apply([
43
+ * { entity: { eid: 'book-1' }, book: { title: 'The Hobbit', price: 12 } },
44
+ * ])
45
+ *
46
+ * // which books match, with the rest of the query still filtering
47
+ * let matched = db.query(
48
+ * compile(parse('hobbit .book.price<20'), shop, { extend: [search(text)] }),
49
+ * )
50
+ *
51
+ * // and which come first, with a snippet marking each match
52
+ * let ranked = find(db, text, 'hobbit')
53
+ * ```
54
+ *
55
+ * It assumes the storage layout that @yaks/sql's SQLite dialect reads and
56
+ * {@link https://jsr.io/@yaks/sqlite | @yaks/sqlite} creates: an `entity` table
57
+ * of integer ids, one table per component keyed by an `entity` owner column,
58
+ * and a `tombstone` table listing deleted entities. For nearest-meaning results
59
+ * alongside these literal matches, pair it with `@yaks/embedding`.
60
+ *
61
+ * @module
62
+ */
63
+
64
+ export * from './fields.js'
65
+ export * from './term.js'
66
+ export * from './ddl.js'
67
+ export * from './compile.js'
68
+ export * from './search.js'
69
+ export * from './lexicon.js'
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "@yaks/fts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.36",
4
+ "homepage": "https://jsr.io/@yaks/fts",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./_dist/mod.d.ts",
9
+ "default": "./mod.js"
10
+ },
11
+ "./fields": {
12
+ "types": "./_dist/fields.d.ts",
13
+ "default": "./fields.js"
14
+ },
15
+ "./lexicon": {
16
+ "types": "./_dist/lexicon.d.ts",
17
+ "default": "./lexicon.js"
18
+ },
19
+ "./term": {
20
+ "types": "./_dist/term.d.ts",
21
+ "default": "./term.js"
22
+ }
23
+ },
24
+ "license": "Apache-2.0",
25
+ "dependencies": {
26
+ "@yaks/graph": "0.2.36",
27
+ "@yaks/query": "0.2.36",
28
+ "@yaks/sql": "0.2.36",
29
+ "@yaks/vocab": "0.2.36"
30
+ },
31
+ "description": "Indexes a graph's text properties with SQLite FTS5 and adds ranked full-text search to queries.",
32
+ "repository": "https://github.com/yak-sh/yak.git"
33
+ }
package/search.js ADDED
@@ -0,0 +1,466 @@
1
+ // Ranked results, with a snippet.
2
+ //
3
+ // The extension (./compile.ts) decides membership — which entities a search
4
+ // selects. This module answers the other question a search box asks: of those,
5
+ // which come first, and what text matched? That is FTS5's `bm25` relevance and
6
+ // its `snippet()`, both of which can only be read in a statement that queries
7
+ // the index itself, so this module builds those statements and runs them.
8
+ //
9
+ // `hits()` runs them through a driver and returns {@link Hit}s; `find()` reads
10
+ // the indexes' sources off the file first. Ranking is by relevance alone;
11
+ // mixing in recency, popularity or anything else is an application's policy,
12
+ // applied to the results it gets back.
13
+ import { absentFrom, among, and, array, as, at, catalogue, col, desc, eq, exists, field, fn, from, lit, member, not, op, or, select, sourceScreen, sub, table, val, when } from "@yaks/sql";
14
+ import { columnsOf, indexes, tableOf, trim, worded } from "./fields.js";
15
+ import { excerpt, match, named, wordings } from "./term.js";
16
+ import { cut } from "./snippet.js";
17
+ // The most owners a screen read whole (@yaks/sql `Selection.whole`) holds for
18
+ // a CPU sort to ask whether any of them carries an index's component before
19
+ // opening it (`best`). Such a screen is read in full to be joined, whichever
20
+ // side drives: `(!entry&!knock&!notification|.created.by.person)` took 3.7 s
21
+ // to say none of the box's 1.9M transcript entries was among its owners,
22
+ // where opening the index and probing each match by key took 0.2 s. A screen
23
+ // past this is read no further, and the index is opened.
24
+ export let PROVE = 1024;
25
+ // Each index has one text source and may be gated by another component.
26
+ // Restrict both before matching, so a public owner cannot reveal private text.
27
+ export let screens = (fields, vocab, opts)=>Object.fromEntries(indexes(worded(fields)).flatMap(({ name, comp, on })=>{
28
+ let screen = sourceScreen(vocab, opts, [
29
+ comp,
30
+ ...on ? [
31
+ on
32
+ ] : []
33
+ ]);
34
+ return screen ? [
35
+ [
36
+ name,
37
+ screen
38
+ ]
39
+ ] : [];
40
+ }));
41
+ export let permitted = (name, owner, screens)=>{
42
+ let screen = screens?.[name];
43
+ return screen ? exists(select({
44
+ cols: [
45
+ lit(1)
46
+ ],
47
+ from: from(screen, '__allowed'),
48
+ where: eq(col('id', '__allowed'), owner)
49
+ })) : lit(true);
50
+ };
51
+ // Component owner IDs are integer primary keys, so SQLite can test their
52
+ // indexes directly for IN without building a set or running a subquery per hit.
53
+ export let unworn = (comps = [], owner)=>comps.map((comp)=>not(among(owner, select({
54
+ cols: [
55
+ col('entity')
56
+ ],
57
+ from: table(comp)
58
+ }))));
59
+ // A prefix match can reopen and merge its postings for each keyed seek.
60
+ export let FEW = 4;
61
+ // Seek into the postings' rowid range once, then test membership without
62
+ // asking FTS5 to reopen and merge a prefix's postings for each owner.
63
+ export let withinOwners = (owner, ids)=>ids.length <= FEW ? among(owner, ids.map((id)=>lit(id))) : and(op('>=', owner, lit(Math.min(...ids))), op('<=', owner, lit(Math.max(...ids))), among(op('+', owner, lit(0)), array(ids)));
64
+ // The ranked hits for a search, best first, or null when the text contains no
65
+ // word. The words are ANDed terms (./term.ts) and bm25 orders the results, so
66
+ // a search behaves as a set of words rather than as one phrase.
67
+ //
68
+ // The ranking is `best`; a snippet is read last, and only for the rows
69
+ // returned. FTS5 reads a row's text back to cut one, and a search over
70
+ // transcripts matches thousands of rows, some of them megabytes of command
71
+ // output: cutting a snippet for every match before choosing twenty took
72
+ // seconds where ranking alone takes milliseconds.
73
+ let alternatives = (forms)=>forms.length == 1 ? forms[0] : forms.map((f)=>`(${f})`).join(' OR ');
74
+ // Compare positions across wordings. Putting every term in one BM25 query
75
+ // rewards rows that repeat several spellings, which buries the original text
76
+ // under later discussions of how to find it.
77
+ let interleave = (rankings, limit)=>{
78
+ let kept = new Map();
79
+ let depth = Math.max(0, ...rankings.map((rows)=>rows.length));
80
+ for(let i = 0; i < depth; i++){
81
+ for (let rows of rankings){
82
+ let hit = rows[i];
83
+ if (!hit || kept.has(hit.owner)) continue;
84
+ kept.set(hit.owner, hit);
85
+ if (kept.size >= limit) return [
86
+ ...kept.values()
87
+ ];
88
+ }
89
+ }
90
+ return [
91
+ ...kept.values()
92
+ ];
93
+ };
94
+ export let hits = (db, fields, text, opts = {})=>{
95
+ let forms = wordings(text);
96
+ let rank = (words)=>best(db, fields, match(words), {
97
+ name: named(words),
98
+ ...opts
99
+ });
100
+ let literal = rank(text);
101
+ if (!literal) return null;
102
+ let ranking = forms.length == 1 ? literal : interleave([
103
+ literal,
104
+ ...forms.slice(1).map((words)=>rank(words) ?? [])
105
+ ], opts.limit ?? 20);
106
+ if (!ranking.length) return [];
107
+ let context = opts.context ?? 10;
108
+ // Membership and rank still use the full match; the excerpt leaves common
109
+ // terms unmarked, so FTS5 does less work cutting large matching texts.
110
+ let marked = alternatives(forms.map(excerpt));
111
+ let ids = (rows)=>rows.map((r)=>lit(r.owner));
112
+ // FTS5 takes a rowid list beside a match as one seek an id, and each seek
113
+ // merges again every token a prefix term begins: the forty hits of
114
+ // `yaks.app test space probe live operator our own space` in the box's
115
+ // transcripts merged `test*`, `own*` and the rest forty times, 14.6 s where
116
+ // one pass takes 0.4 s. A CPU sort has already read every match to rank it,
117
+ // so it reads them once more and keeps the ranked ones: `rowid + 0` is no
118
+ // constraint FTS5 is offered. Index-order pages seek, for billed rows.
119
+ let kept = opts.plan == 'sort' ? (fts)=>op('+', col('rowid', fts), lit(0)) : (fts)=>col('rowid', fts);
120
+ // Each eid is read by id, a seek a row: asked as a set, SQLite may walk
121
+ // `entity` whole however few the ids, whatever its statistics say.
122
+ let o = at('__owner'), e = at('entity');
123
+ let eids = new Map(db.query(select({
124
+ cols: [
125
+ as(o('column1'), 'id'),
126
+ as(sub(select({
127
+ cols: [
128
+ e('eid')
129
+ ],
130
+ from: table('entity'),
131
+ where: eq(e('id'), o('column1'))
132
+ })), 'eid')
133
+ ],
134
+ from: from({
135
+ t: 'values',
136
+ rows: ids(ranking).map((id)=>[
137
+ id
138
+ ])
139
+ }, '__owner')
140
+ })).map((r)=>[
141
+ Number(r.id),
142
+ String(r.eid)
143
+ ]));
144
+ let snippets = new Map();
145
+ indexes(worded(fields), db.stored?.v).forEach((ix, i)=>{
146
+ let mine = ranking.filter((r)=>r.arm == i);
147
+ if (!mine.length) return;
148
+ let fts = tableOf(ix);
149
+ let cuts = db.query(select({
150
+ cols: [
151
+ as(col('rowid', fts), 'owner'),
152
+ as(cut(fts, columnsOf(ix), marked, context, opts.content?.[ix.name]), 'snippet')
153
+ ],
154
+ from: table(fts),
155
+ where: and(op('match', col(fts), val(marked)), among(kept(fts), ids(mine)))
156
+ }));
157
+ for (let r of cuts)snippets.set(`${i} ${r.owner}`, String(r.snippet ?? ''));
158
+ });
159
+ return ranking.flatMap((r)=>{
160
+ let entity = eids.get(r.owner);
161
+ return entity == null ? [] : [
162
+ {
163
+ entity,
164
+ rank: r.rank,
165
+ snippet: snippets.get(`${r.arm} ${r.owner}`) ?? ''
166
+ }
167
+ ];
168
+ });
169
+ };
170
+ // The same ranking over a match expression already built from the words
171
+ // (term.ts), without snippets — what `.order=search` ranks by (./compile.ts):
172
+ // the entities' integer owners, best first.
173
+ export let ranked = (db, fields, t, opts = {})=>(best(db, fields, t, opts) ?? []).map((r)=>r.owner);
174
+ // The best `limit` entities, one row each. An entity's best rank is its
175
+ // `min` across indexes, and its arm the index that rank came from.
176
+ //
177
+ // The ranking runs as a statement a step, and each statement admits through
178
+ // one index's screen. Workerd's SQLite refuses to name a common table
179
+ // expression once a statement holds 100 cursors (@yaks/sql `cursors`), and a
180
+ // visibility screen reads dozens, so four indexes' pages refused as one
181
+ // statement with their screens named, and written out without CTEs they pass
182
+ // the engine's 100 KB. So each index's page, its tied places and its
183
+ // exact names are read alone, and what joins them (the edge of a page, an
184
+ // entity's best index, the order) is plain arithmetic here.
185
+ //
186
+ // A page stops reading at its best rows. Each index answers only its own best
187
+ // `limit` admitted rows (`page`), through FTS5's own `order by rank`, which
188
+ // sorts inside the index and hands back just the rows taken: a yaks.app store
189
+ // bills each row a cursor hands back, so a broad word costs a page, not every
190
+ // match. The best `limit` entities across indexes are among each index's best
191
+ // `limit`, so nothing is lost by cutting each first. Admission (the screen,
192
+ // visibility, a tombstone) is tested as the index hands rows back, so a row
193
+ // the rest of the query refuses never takes a place.
194
+ //
195
+ // Equal matches go newest first, as a listing does, but FTS5 hands equal ranks
196
+ // back oldest first. So an index-order page reads one row past its last place,
197
+ // and when that row ranks the same as the last place, the places at that rank
198
+ // are taken again, newest first, by a `rowid desc` scan of the rows ranking
199
+ // exactly that (`newest`). A CPU sort orders ties itself.
200
+ //
201
+ // A name comes first. bm25 rewards a word said often in a short text, so a
202
+ // task saying "Mossvale" twice in its title outranks the project whose title
203
+ // is the one word, which sat past a hundred others for `mossvale`. So the
204
+ // matches whose stored text is exactly the words, ignoring case (`exactly`),
205
+ // rank before every other. They are found through the index as rows whose
206
+ // text begins with the words (FTS5's `^`), and only those rows are read to
207
+ // compare.
208
+ let best = (db, fields, t, opts)=>{
209
+ let arms = indexes(worded(fields), db.stored?.v);
210
+ if (!t || !arms.length) return null;
211
+ if (opts.owners?.length == 0) return [];
212
+ let limit = opts.limit ?? 20;
213
+ let sorting = opts.plan == 'sort';
214
+ // A compiler screen can join the postings by owner ID. Keep the FTS cursor
215
+ // first so a sparse term never walks the visibility relation to find its
216
+ // matches. A bare screen on the CPU sort is read once per statement.
217
+ let keyed = opts.owners ? undefined : opts.screen?.keyed;
218
+ let probed = !!opts.screen?.probe;
219
+ let screen = opts.screen && (sorting && !opts.owners || !keyed && !probed) ? [
220
+ {
221
+ name: '__fts_screen',
222
+ // Selection already projects id. Keep the CTE eligible for unfolding.
223
+ q: opts.screen,
224
+ materialized: sorting && !probed
225
+ }
226
+ ] : [];
227
+ let ask = (q, arm, named)=>{
228
+ let joins = keyed ? [
229
+ {
230
+ how: 'cross',
231
+ src: from(keyed, '__fts_visible'),
232
+ on: eq(col('id', '__fts_visible'), col('rowid', tableOf(arms[arm])))
233
+ }
234
+ ] : [];
235
+ return db.query({
236
+ ...q,
237
+ with: screen,
238
+ joins
239
+ }).map((r)=>({
240
+ owner: Number(r.owner),
241
+ rank: Number(r.rank),
242
+ arm,
243
+ named
244
+ }));
245
+ };
246
+ let eligible = (owner)=>probed ? member(opts.screen, owner) : exists(select({
247
+ cols: [
248
+ lit(1)
249
+ ],
250
+ from: table('__fts_screen'),
251
+ where: eq(col('id', '__fts_screen'), owner)
252
+ }));
253
+ // A kind can have no owners in an index at all. A CPU sort proves that
254
+ // through the selected owners' component keys before opening its cursor.
255
+ // Joined, not crossed, with the index's component first: SQLite drives from
256
+ // the smaller side, so a broad screen seeks a rare component's few owners,
257
+ // and a rare component seeks a broad screen's, rather than walking either
258
+ // in id order to find one. A screen's own CROSS JOIN pins every table
259
+ // written after it, so the component written second could only be probed:
260
+ // `.entry` walked 1.9M transcript entries to find one carrying a doc.
261
+ let source = (arm)=>table(arm.on ?? arm.comp, '__source');
262
+ let owned = (arm)=>opts.owners ? select({
263
+ cols: [
264
+ lit(1)
265
+ ],
266
+ from: from(array(opts.owners), '__fts_screen'),
267
+ joins: [
268
+ {
269
+ how: 'cross',
270
+ src: source(arm),
271
+ on: eq(col('entity', '__source'), col('value', '__fts_screen'))
272
+ }
273
+ ]
274
+ }) : select({
275
+ cols: [
276
+ lit(1)
277
+ ],
278
+ from: source(arm),
279
+ joins: [
280
+ {
281
+ how: 'join',
282
+ src: table('__fts_screen'),
283
+ on: eq(col('entity', '__source'), col('id', '__fts_screen'))
284
+ }
285
+ ]
286
+ });
287
+ // A screen read whole is asked no further than PROVE owners: one past them
288
+ // opens the index.
289
+ let wide = (n)=>!opts.owners && opts.screen?.whole ? [
290
+ [
291
+ exists(select({
292
+ cols: [
293
+ lit(1)
294
+ ],
295
+ from: table('__fts_screen'),
296
+ limit: lit(1),
297
+ offset: lit(PROVE)
298
+ })),
299
+ lit(n)
300
+ ]
301
+ ] : [];
302
+ let take = (arm, n)=>opts.owners || sorting && opts.screen ? when([
303
+ ...wide(n),
304
+ [
305
+ exists(owned(arm)),
306
+ lit(n)
307
+ ]
308
+ ], lit(0)) : lit(n);
309
+ // An index's rows matching `expr`, among the live owners the caller admits.
310
+ let admitted = (ix, expr)=>{
311
+ let fts = tableOf(ix);
312
+ let owner = col('rowid', fts);
313
+ return and(op('match', col(fts), val(expr)), ...opts.owners ? [
314
+ withinOwners(owner, opts.owners)
315
+ ] : [], permitted(ix.name, owner, opts.screens), ...unworn([
316
+ 'tombstone',
317
+ ...ix.not ?? []
318
+ ], owner), ...opts.screen && !keyed ? [
319
+ eligible(owner)
320
+ ] : []);
321
+ };
322
+ let found = arms.flatMap((arm, i)=>{
323
+ let page = ask(select({
324
+ cols: [
325
+ as(col('rowid'), 'owner'),
326
+ as(col('rank'), 'rank')
327
+ ],
328
+ from: table(tableOf(arm)),
329
+ where: admitted(arm, t),
330
+ order: [
331
+ col('rank'),
332
+ ...sorting ? [
333
+ desc(col('rowid'))
334
+ ] : []
335
+ ],
336
+ limit: take(arm, sorting ? limit : limit + 1)
337
+ }), i, 0);
338
+ let worst = page.at(-1)?.rank;
339
+ let tied = page.filter((r)=>r.rank == worst).length;
340
+ let placed = page.length > limit ? [
341
+ ...page.filter((r)=>r.rank != worst),
342
+ ...tied > 1 ? ask(newest(arm, t, worst, tied - 1, admitted), i, 0) : []
343
+ ] : page;
344
+ let names = opts.name ? ask(exactly(arm, t, opts.name, take(arm, limit), admitted), i, 1) : [];
345
+ return [
346
+ ...placed,
347
+ ...names
348
+ ];
349
+ });
350
+ let by = new Map();
351
+ for (let c of found){
352
+ let held = by.get(c.owner);
353
+ if (!held) by.set(c.owner, {
354
+ ...c
355
+ });
356
+ else {
357
+ if (c.rank < held.rank) Object.assign(held, {
358
+ rank: c.rank,
359
+ arm: c.arm
360
+ });
361
+ held.named = Math.max(held.named, c.named);
362
+ }
363
+ }
364
+ return [
365
+ ...by.values()
366
+ ].sort((a, b)=>b.named - a.named || a.rank - b.rank || b.owner - a.owner).slice(0, limit);
367
+ };
368
+ // An index's places at its worst rank `worst` when the row past its last place
369
+ // ties with them, taken again newest first: `room` of them, all who share that
370
+ // rank but the row past. It matches the rank through `bm25`, since FTS5 reads
371
+ // a constraint on `rank` as its configuration.
372
+ let newest = (ix, t, worst, room, admitted)=>{
373
+ let fts = tableOf(ix);
374
+ return select({
375
+ cols: [
376
+ as(col('rowid'), 'owner'),
377
+ as(col('rank'), 'rank')
378
+ ],
379
+ from: table(fts),
380
+ where: and(eq(fn('bm25', col(fts)), val(worst)), admitted(ix, t)),
381
+ order: [
382
+ desc(col('rowid'))
383
+ ],
384
+ limit: lit(room)
385
+ });
386
+ };
387
+ // An index's best `limit` admitted owners whose stored text, in any of its
388
+ // columns, is exactly `name`: the rows whose text begins with it (`^`), each
389
+ // read once to compare, and each ranked by the words `t` as a hit is. In an
390
+ // index of one column every such row says the same words in the same length,
391
+ // so all rank alike and the best are the newest: the scan stops at `limit`.
392
+ // In an index of several, the rest of a row moves its rank, so every name is
393
+ // ranked. A property kept elsewhere is compared as stored: a body @yaks/blob
394
+ // holds is its address, never its words.
395
+ let exactly = (ix, t, name, limit, admitted)=>{
396
+ let { comp, props } = ix, fts = tableOf(ix);
397
+ let n = at('__named');
398
+ let same = (p)=>eq(fn('lower', fn('trim', n(field(p)))), fn('lower', val(name)));
399
+ let rank = sub(select({
400
+ cols: [
401
+ col('rank', '__rank')
402
+ ],
403
+ from: table(fts, '__rank'),
404
+ where: and(op('match', col(fts, '__rank'), val(t)), eq(col('rowid', '__rank'), col('rowid', fts)))
405
+ }));
406
+ return select({
407
+ cols: [
408
+ as(col('rowid'), 'owner'),
409
+ as(rank, 'rank')
410
+ ],
411
+ from: table(fts),
412
+ where: and(admitted(ix, `^"${name.replaceAll('"', '')}"`), exists(select({
413
+ cols: [
414
+ lit(1)
415
+ ],
416
+ from: table(comp, '__named'),
417
+ where: and(eq(n('entity'), col('rowid', fts)), or(...props.map(same)))
418
+ }))),
419
+ order: [
420
+ ...props.length > 1 ? [
421
+ col('rank')
422
+ ] : [],
423
+ desc(col('rowid'))
424
+ ],
425
+ limit
426
+ });
427
+ };
428
+ // The hits for a search, closest first. Returns [] for text containing no word
429
+ // and for a vocabulary with nothing indexed — a search that cannot be run finds
430
+ // nothing, rather than everything.
431
+ export let find = (db, fields, text, { scope, vocab, ...opts } = {})=>{
432
+ let v = db.stored?.v;
433
+ let layout = v ?? vocab;
434
+ if (scope && !layout) throw new Error('a scoped search requires a vocabulary');
435
+ let tables = catalogue(db).filter((o)=>o.type == 'table');
436
+ let namesOf = new Map(indexes(worded(fields), v).map((ix)=>[
437
+ tableOf(ix),
438
+ ix.name
439
+ ]));
440
+ let content = Object.fromEntries(tables.flatMap((o)=>{
441
+ let source = /content='([^']*)'/.exec(o.sql ?? '')?.[1];
442
+ let name = namesOf.get(o.name);
443
+ return source && name != null ? [
444
+ [
445
+ name,
446
+ source
447
+ ]
448
+ ] : [];
449
+ }));
450
+ // An index stands once its component's first write made it, and a scope
451
+ // reads a component no table stands for as worn by nobody (@yaks/sqlite).
452
+ let names = new Set(tables.map((o)=>o.name));
453
+ let live = fields.filter((f)=>(f.on ?? f.comp) in content).map((f)=>trim(f, (comp)=>names.has(comp)));
454
+ return hits(db, live, text, {
455
+ plan: db.file ? 'sort' : 'index',
456
+ content,
457
+ ...scope && layout && {
458
+ screens: screens(live, layout, {
459
+ ...scope,
460
+ absent: absentFrom(layout, names)
461
+ })
462
+ },
463
+ ...opts
464
+ }) ?? [];
465
+ };
466
+ //# sourceMappingURL=search.js.map
package/search.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.js","sources":["./search.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;AAC9E,0EAA0E;AAC1E,EAAE;AACF,+EAA+E;AAC/E,0EAA0E;AAC1E,6EAA6E;AAC7E,uCAAuC;AAGvC,SACE,UAAU,EACV,KAAK,EACL,GAAG,EACH,KAAK,EACL,EAAE,EACF,EAAE,EAEF,SAAS,EACT,GAAG,EAEH,IAAI,EAEJ,EAAE,EACF,MAAM,EAEN,KAAK,EACL,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