@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.
@@ -0,0 +1,37 @@
1
+ import type { Prop, Vocab } from "@yaks/vocab";
2
+ export type Field = {
3
+ comp: string;
4
+ prop: string;
5
+ on?: string;
6
+ not?: string[];
7
+ trigram?: true;
8
+ separate?: true;
9
+ };
10
+ export type Pick = (prop: Prop) => boolean;
11
+ export declare let searched: Pick;
12
+ export declare let fields: (vocab: Vocab, pick?: Pick) => Field[];
13
+ export declare let unfound: (vocab: Vocab) => {
14
+ not?: string[];
15
+ };
16
+ export declare let trim: (f: Field, stands: (comp: string) => boolean) => Field;
17
+ export declare let grams: (vocab: Vocab, pick?: Pick) => Field[];
18
+ export declare let indexed: (vocab: Vocab) => Field[];
19
+ export declare let worded: (fields: Field[]) => Field[];
20
+ export type Index = {
21
+ name: string;
22
+ comp: string;
23
+ props: string[];
24
+ on?: string;
25
+ not?: string[];
26
+ trigram?: true;
27
+ };
28
+ export declare let indexes: (fields: Field[], v?: Vocab) => Index[];
29
+ /** The columns handled by FTS, in the order the index declares them. */ export declare let columnsOf: (ix: Index) => string[];
30
+ export declare let indexName: (name: string) => string;
31
+ export declare let gramName: (name: string) => string;
32
+ export declare let tableOf: (ix: Index) => string;
33
+ export declare let viewOf: (ix: Index) => string;
34
+ export declare let tailOf: (ix: Index) => string;
35
+ export declare let piecesOf: (ix: Index) => string;
36
+ export declare let textName: (name: string) => string;
37
+ //# sourceMappingURL=fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.d.ts","sources":["../fields.ts"],"names":[],"mappings":"AAsBA,cAAc,IAAI,EAAE,KAAK,2BAAgC;AAMzD,YAAY;EACV,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,KAAK,MAAM;EAEX,MAAM,MAAM;EACZ,UAAU,IAAI;EACd,WAAW,IAAI;;AAKjB,YAAY,QAAQ,MAAM,SAAS,OAAO;AAqB1C,OAAO,YAAI,UAAU,KAAkC;AAMvD,OAAO,YAAI,SAAU,OAAO,OAAO,OAAM,SAAkB,QAa1D;AAID,OAAO,YAAI,UAAW,OAAO;EAAU,MAAM,MAAM;EAGlD;AAID,OAAO,YAAI,OAAQ,GAAG,OAAO,SAAS,MAAM,MAAM,KAAK,OAAO,KAAG,MACQ;AAIzE,OAAO,YAAI,QAAS,OAAO,OAAO,OAAM,SAA6B,QAalE;AAIH,OAAO,YAAI,UAAW,OAAO,UAAQ,QAGpC;AAGD,OAAO,YAAI,SAAU,QAAQ,YAAU,QACL;AAMlC,YAAY;EACV,MAAM,MAAM;EACZ,MAAM,MAAM;EACZ,OAAO,MAAM;EACb,KAAK,MAAM;EAEX,MAAM,MAAM;EACZ,UAAU,IAAI;;AAIhB,OAAO,YAAI,UAAW,QAAQ,SAAS,IAAI,UAAQ,QAkClD;AAKD,sEAAsE,GACtE,OAAO,YAAI,YAAa,IAAI,UAAQ,MAAM,GACK;AAG/C,OAAO,YAAI,YAAa,MAAM,MAAM,KAAG,MAAM,CAAiB;AAG9D,OAAO,YAAI,WAAY,MAAM,MAAM,KAAG,MAAM,CAAqB;AAGjE,OAAO,YAAI,UAAW,IAAI,UAAQ,MAAM,CACqB;AAG7D,OAAO,YAAI,SAAU,IAAI,UAAQ,MAAM,CACqB;AAK5D,OAAO,YAAI,SAAU,IAAI,UAAQ,MAAM,CAAmC;AAC1E,OAAO,YAAI,WAAY,IAAI,UAAQ,MAAM,CAAoC;AAQ7E,OAAO,YAAI,WAAY,MAAM,MAAM,KAAG,MAAM,CAAkB"}
@@ -0,0 +1,33 @@
1
+ /** How many letters of a word a lexicon keeps. */ export declare let PREFIX: number;
2
+ /**
3
+ * The lexicon entries a text adds: each of its words, folded and cut to
4
+ * {@link PREFIX} letters, once each.
5
+ *
6
+ * ```ts
7
+ * import { assertEquals } from '@std/assert'
8
+ * assertEquals(lexemes('Crème brûlée, crème caramel'), ['crem', 'brul', 'cara'])
9
+ * ```
10
+ */ export declare let lexemes: (text: string) => string[];
11
+ /**
12
+ * Two lexicons as one, sorted, which is the order {@link admits} reads.
13
+ *
14
+ * ```ts
15
+ * import { assertEquals } from '@std/assert'
16
+ * assertEquals(joined(['soup'], ['crem', 'soup']), ['crem', 'soup'])
17
+ * ```
18
+ */ export declare let joined: (a: readonly string[], b: readonly string[]) => string[];
19
+ /**
20
+ * Whether a store with this sorted lexicon could match every one of the
21
+ * words, as a search box's words match: each word, or each word of a quoted
22
+ * run, begins some word the store holds. False only when one of them cannot.
23
+ *
24
+ * ```ts
25
+ * import { assertEquals } from '@std/assert'
26
+ * let soups = joined(lexemes('Tomato soup'), [])
27
+ * assertEquals(admits(soups, 'tom'), true)
28
+ * assertEquals(admits(soups, 'tomatoes soup'), true)
29
+ * assertEquals(admits(soups, 'soup bread'), false)
30
+ * assertEquals(admits(soups, '"tomato soup"'), true)
31
+ * ```
32
+ */ export declare let admits: (lexicon: readonly string[], words: string) => boolean;
33
+ //# sourceMappingURL=lexicon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lexicon.d.ts","sources":["../lexicon.ts"],"names":[],"mappings":"AAqBA,gDAAgD,GAChD,OAAO,YAAI,eAAU;AAOrB;;;;;;;;CAQC,GACD,OAAO,YAAI,UAAW,MAAM,MAAM,KAAG,MAAM,GAE1C;AAED;;;;;;;CAOC,GACD,OAAO,YAAI,SAAU,YAAY,MAAM,IAAI,YAAY,MAAM,OAAK,MAAM,GACrC;AAanC;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,SAAU,kBAAkB,MAAM,IAAI,OAAO,MAAM,KAAG,OAAO,CAKrE"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,68 @@
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
+ */ export * from "./fields.js";
63
+ export * from "./term.js";
64
+ export * from "./ddl.js";
65
+ export * from "./compile.js";
66
+ export * from "./search.js";
67
+ export * from "./lexicon.js";
68
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6DC,GAED,4BAA2B;AAC3B,0BAAyB;AACzB,yBAAwB;AACxB,6BAA4B;AAC5B,4BAA2B;AAC3B,6BAA4B"}
@@ -0,0 +1,36 @@
1
+ import type { Eid } from "@yaks/graph";
2
+ import { type BindOpts, col, type Driver, type Expr, type Raw, type Selection } from "@yaks/sql";
3
+ import type { Vocab } from "@yaks/vocab";
4
+ import { type Field } from "./fields.js";
5
+ export type Hit = {
6
+ entity: Eid;
7
+ rank: number;
8
+ snippet: string;
9
+ };
10
+ export type SearchOpts = {
11
+ limit?: number;
12
+ plan?: 'index' | 'sort';
13
+ screen?: Selection;
14
+ screens?: Record<string, Raw>;
15
+ context?: number;
16
+ content?: Record<string, string>;
17
+ name?: string;
18
+ };
19
+ type RankOpts = SearchOpts & {
20
+ owners?: readonly number[];
21
+ };
22
+ export declare let PROVE: number;
23
+ export declare let screens: (fields: Field[], vocab: Vocab, opts: BindOpts) => Record<string, Raw>;
24
+ export declare let permitted: (name: string, owner: ReturnType<typeof col>, screens?: Record<string, Raw>) => Expr;
25
+ export declare let unworn: (comps: string[] | undefined, owner: Expr) => Expr[];
26
+ export declare let FEW: number;
27
+ export declare let withinOwners: (owner: Expr, ids: readonly number[]) => Expr;
28
+ export declare let hits: (db: Driver, fields: Field[], text: string, opts?: SearchOpts) => Hit[] | null;
29
+ export declare let ranked: (db: Driver, fields: Field[], t: string, opts?: RankOpts) => number[];
30
+ /** What {@link find} is asked beside its words: {@link SearchOpts} less the
31
+ * screens and sources it reads off the file itself. */ export type FindOpts = Omit<SearchOpts, 'screens' | 'content'> & {
32
+ scope?: BindOpts;
33
+ vocab?: Vocab;
34
+ };
35
+ export declare let find: (db: Driver, fields: Field[], text: string, _dts_1: never) => Hit[];
36
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sources":["../search.ts"],"names":[],"mappings":"AAaA,cAAc,GAAG,2BAAgC;AACjD,SAOE,KAAK,QAAQ,EAEb,GAAG,EAGH,KAAK,MAAM,EAGX,KAAK,IAAI,EAUT,KAAK,GAAG,EAGR,KAAK,SAAS,yBAMa;AAC7B,cAAc,KAAK,2BAAgC;AACnD,SAEE,KAAK,KAAK,sBAMQ;AAKpB,YAAY;EAEV,QAAQ;EAER,MAAM,MAAM;EAEZ,SAAS,MAAM;;AAGjB,YAAY;EAEV,QAAQ,MAAM;EAGd,OAAO,UAAU;EAIjB,SAAS;EAET,UAAU,OAAO,MAAM,EAAE;EAEzB,UAAU,MAAM;EAEhB,UAAU,OAAO,MAAM,EAAE,MAAM;EAI/B,OAAO,MAAM;;KAGV,WAAW;EAEd,kBAAkB,MAAM;;AAU1B,OAAO,YAAI,cAAY;AAIvB,OAAO,YAAI,UACT,QAAQ,SACR,OAAO,OACP,MAAM,aACL,OAAO,MAAM,EAAE,KAMf;AAEH,OAAO,YAAI,YACT,MAAM,MAAM,EACZ,OAAO,kBAAkB,MACzB,UAAU,OAAO,MAAM,EAAE,SACxB,KASF;AAID,OAAO,YAAI,SAAU,OAAO,MAAM,gBAAS,OAAO,SAAO,OAGtD;AAGH,OAAO,YAAI,YAAO;AAIlB,OAAO,YAAI,eAAgB,OAAO,MAAM,cAAc,MAAM,OAAK,KAK9D;AA+BH,OAAO,YAAI,OACT,IAAI,QACJ,QAAQ,SACR,MAAM,MAAM,EACZ,OAAM,eACL,QAAQ,IAAI,CA6Ed;AAKD,OAAO,YAAI,SACT,IAAI,QACJ,QAAQ,SACR,GAAG,MAAM,EACT,OAAM,aACL,MAAM,GAA2D;AAqQpE;qDACqD,GACrD,YAAY,WAAW,KAAK,YAAY,YAAY;EAGlD,QAAQ;EACR,QAAQ;;AAMV,OAAO,YAAI,OACT,IAAI,QACJ,QAAQ,SACR,MAAM,MAAM,EACZ,kBACC,MA6BF"}
@@ -0,0 +1,16 @@
1
+ export declare let OPEN: string;
2
+ export declare let CLOSE: string;
3
+ export declare let term: (text: string) => string;
4
+ export declare let split: (text: string) => string[];
5
+ export declare let match: (text: string) => string;
6
+ export declare let named: (text: string) => string;
7
+ export declare let keywords: (text: string) => string[];
8
+ export declare let lifecycleTerms: readonly string[];
9
+ /** Literal and alternate word searches for a product's end of life. */ export declare let wordings: (text: string) => string[];
10
+ /** Wording to embed for a ranked search. Keep the literal query for FTS. */ export declare let meaningWords: (text: string) => string;
11
+ /** The subject immediately before an end-of-life premise in prose. */ export declare let lifecycleSubject: (text: string) => string | undefined;
12
+ export declare let excerpt: (text: string) => string;
13
+ export declare let GRAMS: number;
14
+ export declare let grammed: (needle: string) => string | null;
15
+ export declare let phrased: (needle: string) => string | null;
16
+ //# sourceMappingURL=term.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"term.d.ts","sources":["../term.ts"],"names":[],"mappings":"AA2BA,OAAO,YAAI,aAAa;AACxB,OAAO,YAAI,cAAc;AAWzB,OAAO,YAAI,OAAQ,MAAM,MAAM,KAAG,MAAM,CAOvC;AAwBD,OAAO,YAAI,QAAS,MAAM,MAAM,KAAG,MAAM,GAA6B;AAMtE,OAAO,YAAI,QAAS,MAAM,MAAM,KAAG,MAAM,CACQ;AAKjD,OAAO,YAAI,QAAS,MAAM,MAAM,KAAG,MAAM,CAGX;AAI9B,OAAO,YAAI,WAAY,MAAM,MAAM,KAAG,MAAM,GACC;AAO7C,OAAO,YAAI,yBAAyB,MAAM,GAAsC;AAQhF,qEAAqE,GACrE,OAAO,YAAI,WAAY,MAAM,MAAM,KAAG,MAAM,GAO3C;AAED,0EAA0E,GAC1E,OAAO,YAAI,eAAgB,MAAM,MAAM,KAAG,MAAM,CAA6B;AAE7E,oEAAoE,GACpE,OAAO,YAAI,mBAAoB,MAAM,MAAM,KAAG,MAAM,GAAG,SAAS,CAO/D;AAOD,OAAO,YAAI,UAAW,MAAM,MAAM,KAAG,MAAM,CAK1C;AAKD,OAAO,YAAI,cAAS;AAYpB,OAAO,YAAI,UAAW,QAAQ,MAAM,KAAiB,MAAM,GAAG,IAAI,CAcjE;AAkBD,OAAO,YAAI,UAAW,QAAQ,MAAM,KAAG,MAAM,GAAG,IAAI,CAKnD"}
package/compile.js ADDED
@@ -0,0 +1,391 @@
1
+ // The query half: a bare word in a query compiles to an FTS5 match.
2
+ //
3
+ // A query mixes words and filters — `hobbit .book.price<20` — and @yaks/query parses
4
+ // each bare word as a `text` clause. @yaks/sql compiles every clause except
5
+ // that one; this module is the @yaks/sql extension that compiles it, registered
6
+ // through `compile(ast, vocab, { extend: [search(fields)] })`.
7
+ //
8
+ // One clause is one word, or one run somebody quoted (@yaks/query splits on
9
+ // whitespace), so `term` converts it — a word matches as a prefix, a quoted run
10
+ // stays a phrase — and several words are ANDed together the way every other
11
+ // clause is.
12
+ //
13
+ // The generated condition is one `in` subquery per indexed component, ORed
14
+ // together: an index's rowid is the entity's integer id in the `entity` table,
15
+ // so a match yields ids the surrounding statement already uses, and no join is
16
+ // needed. The AND between words comes from how @yaks/sql combines clauses, not
17
+ // from this file.
18
+ //
19
+ // `.order=search` ranks what the words selected by relevance, closest first
20
+ // (`.order=-search` the weakest first). bm25 can only be read in a statement
21
+ // that matches the index, and an ORDER BY term re-matching per row costs a
22
+ // whole search per row, so the ranking runs once, through the server's own
23
+ // connection, among the rows the rest of the query admits (./search.ts). The
24
+ // order is then each entity's place in it, spelled over integer ids: the one
25
+ // value an ORDER BY here can carry. A window of a query with words that states
26
+ // no order is ranked the same way (`ranks`): a page of a search is its best
27
+ // rows, as a search box's are, never its newest. Its first page ranks only as
28
+ // many as it shows and reads only those (`reach`), so a broad word costs a
29
+ // page, not every match. A search composed without a connection selects but
30
+ // does not rank.
31
+ import { among, and, as, col, count, eq, FALSE, from, lit, lookup, not, op, or, select, table, unionAll, Unsupported, val } from "@yaks/sql";
32
+ import { FEW, permitted, ranked, screens, unworn, withinOwners } from "./search.js";
33
+ import { indexes, tableOf, tailOf, trim, worded } from "./fields.js";
34
+ import { grammed, named, phrased, term } from "./term.js";
35
+ import { DONE, PAST, PIECES, SPAN } from "./ddl.js";
36
+ import { map, words as wordsIn } from "@yaks/query/core";
37
+ // The ranking `.order=` names.
38
+ export let SEARCH = 'search';
39
+ // How many of the best matches `.order=search` puts in order; any past them
40
+ // follow, newest first.
41
+ export let RANKED = 1000;
42
+ let mandatory = (c)=>c.kind == 'and' ? c.clauses.reduce((n, child)=>n + mandatory(child), 0) : Number(c.kind == 'text');
43
+ // How many of a query's best rows its answer reaches, when those are all it
44
+ // reaches: the first page (no `.after`) of a window of at most `RANKED` rows
45
+ // ordered by search, whose words are all mandatory clauses of its own. A word
46
+ // under OR or a child filter selects rows an all-word ranking never sees.
47
+ ///
48
+ /// let { parse } = await import('@yaks/query')
49
+ /// reach(parse('dragon .limit=5 .order=search')) -> 5
50
+ /// reach(parse('dragon .limit=5 .order=-search')) -> null
51
+ /// reach(parse('dragon .limit=5 .order=search .after=7')) -> null
52
+ /// reach(parse('(dragon|scale) .limit=5 .order=search')) -> null
53
+ /// reach(parse('dragon (scale) .limit=5 .order=search')) -> 5
54
+ /// reach(parse('dragon .limit=5000 .order=search')) -> null
55
+ export let reach = (q)=>{
56
+ let limit = q.clauses.find((c)=>c.kind == 'limit');
57
+ let orders = q.clauses.filter((c)=>c.kind == 'order');
58
+ if (!limit || limit.n < 1 || limit.n > RANKED || orders.length != 1 || orders[0].value != SEARCH || q.clauses.some((c)=>c.kind == 'after')) return null;
59
+ let all = 0;
60
+ map(q, (c)=>{
61
+ if (c.kind == 'text') all++;
62
+ return c;
63
+ });
64
+ let own = mandatory(q);
65
+ return all == own ? limit.n : null;
66
+ };
67
+ // How many rows a substring index may find for a `~=` needle for a read to
68
+ // be driven from them, each read and tested. Past it the needle is common, and
69
+ // a read in its own order stops at its page sooner. On the box's 700,000
70
+ // transcript texts the two cost the same near 4,000: a page of 25 of a needle
71
+ // that many hold is found within about 4,400 texts in order.
72
+ export let FEW_TEXTS = 4000;
73
+ // Try the indexed screen first for a filtered ranking. Keep only a bounded
74
+ // set in the compiler, falling back to keyed probes for a wide screen.
75
+ let SCREEN = 4096;
76
+ let candidates = (db, screen)=>{
77
+ let seek = screen.seek?.();
78
+ if (!seek) return;
79
+ let ids = db.query(select({
80
+ cols: [
81
+ col('id')
82
+ ],
83
+ from: from(seek),
84
+ limit: lit(SCREEN + 1)
85
+ })).map((r)=>Number(r.id));
86
+ return ids.length <= SCREEN ? ids : undefined;
87
+ };
88
+ // The @yaks/sql extension that resolves bare words against the search indexes.
89
+ // It handles the `text` clause, covering every indexed field, and orders by
90
+ // relevance to those words. Without this extension @yaks/sql rejects bare
91
+ // words rather than assuming an index exists. It also answers which owners a
92
+ // `~=` test of a substring-indexed property can hold (`contains`), sized
93
+ // through `db`; `fill` says which index is still being filled, and holds only
94
+ // the rows its cursor has passed until it is, so it answers nothing.
95
+ export let search = (fields, db, fill)=>{
96
+ // Whether the file holds a substring index, asked once a read.
97
+ let standing = new Map();
98
+ let stands = (fts)=>{
99
+ let is = standing.get(fts);
100
+ if (is == null) {
101
+ standing.set(fts, is = !!db.query(select({
102
+ cols: [
103
+ lit(1)
104
+ ],
105
+ from: table('sqlite_schema'),
106
+ where: eq(col('name'), val(fts))
107
+ })).length);
108
+ }
109
+ return is;
110
+ };
111
+ // What each needle's index found this query, by index and needle: one
112
+ // read asks again for each plan it weighs.
113
+ let found = new Map();
114
+ // The words this query searched for (as terms, and as typed), and what the
115
+ // rest of it selects, remembered for its `.order=search`.
116
+ let words = [];
117
+ let said = [];
118
+ let asked = null;
119
+ // The owners in relevance order, resolved once a query.
120
+ let held = null;
121
+ let scoped;
122
+ let sources = {};
123
+ let membership = new Map();
124
+ let shared = new Map();
125
+ // How many of the best rows this query's answer reaches, when that is all
126
+ // it reaches (`reach`), and whether the ranking is being read.
127
+ let page = null;
128
+ let ranking = false;
129
+ let aspects = {};
130
+ // The fields whose index stands: one over a component no table stands for
131
+ // yet (@yaks/sql `Site.absent`) holds nothing, and has no index to ask, and
132
+ // nobody wears such a component to be left out by it.
133
+ let live = fields;
134
+ let seen = (site)=>{
135
+ let gone = new Set(site.absent);
136
+ live = gone.size ? fields.filter((f)=>!gone.has(f.comp) && !(f.on && gone.has(f.on))).map((f)=>trim(f, (comp)=>!gone.has(comp))) : fields;
137
+ aspects = screens(live, site.vocab, {
138
+ visibility: {
139
+ components: site.visibility?.components
140
+ },
141
+ absent: site.absent
142
+ });
143
+ };
144
+ let rank = ()=>{
145
+ if (held) return held;
146
+ let screen = asked?.() ?? undefined;
147
+ ranking = true;
148
+ try {
149
+ // A session's indexed entries can be read once before MATCH. Probing
150
+ // the full screen per posting seeks dates and transcript text for hits
151
+ // from unrelated sessions, long before LIMIT can take effect.
152
+ scoped = screen && db.file ? candidates(db, screen) : undefined;
153
+ held = ranked(db, live, words.join(' '), {
154
+ screen,
155
+ owners: scoped,
156
+ // The query's screen already admits the owner through entity visibility.
157
+ // Repeating it for each text source multiplies the ranking's VM program.
158
+ screens: screen ? aspects : sources,
159
+ limit: page ?? RANKED,
160
+ plan: db.file ? 'sort' : 'index',
161
+ name: named(said.join(' '))
162
+ });
163
+ } finally{
164
+ ranking = false;
165
+ }
166
+ return held;
167
+ };
168
+ return {
169
+ name: 'fts',
170
+ // A ranked page's words select its best rows, `page` owners at most.
171
+ few: (q)=>db && reach(q) != null ? [
172
+ 'text'
173
+ ] : [],
174
+ begin: (screen, q)=>{
175
+ found.clear();
176
+ standing.clear();
177
+ asked = screen;
178
+ held = null;
179
+ scoped = undefined;
180
+ sources = {};
181
+ membership.clear();
182
+ shared.clear();
183
+ page = db ? reach(q) : null;
184
+ // A page's words are all the query's own, so they are known now.
185
+ words = [];
186
+ said = [];
187
+ for (let w of page == null ? [] : wordsIn(q)){
188
+ let t = term(w);
189
+ if (t && !words.includes(t)) {
190
+ words.push(t);
191
+ said.push(w);
192
+ }
193
+ }
194
+ },
195
+ compile: {
196
+ text: (clause, site)=>{
197
+ if (clause.kind != 'text') return null;
198
+ let t = term(clause.value);
199
+ seen(site);
200
+ // A search containing no word matches nothing. Compiling it to a
201
+ // constant false keeps the query away from the index rather than
202
+ // widening the result set. Nor does one with no index to search.
203
+ if (!t || !live.length) return FALSE;
204
+ // A first page of a search is its best rows and no others, so when the
205
+ // ranking fills it, its words select just those, ranked once among
206
+ // what the rest of the query admits, rather than every match. A page
207
+ // the ranking leaves short reads every match: words found in different
208
+ // indexes match where no one index ranks them, and follow the ranked.
209
+ if (page != null && !ranking) {
210
+ sources = screens(live, site.vocab, {
211
+ visibility: site.visibility,
212
+ absent: site.absent
213
+ });
214
+ let ids = rank();
215
+ if (ids.length == page) {
216
+ return among(site.owner, ids.map((id)=>lit(id)));
217
+ }
218
+ }
219
+ // A screen compiled for another extension reads this clause again.
220
+ if (!words.includes(t)) {
221
+ words.push(t);
222
+ said.push(clause.value);
223
+ }
224
+ sources = screens(live, site.vocab, {
225
+ visibility: site.visibility,
226
+ absent: site.absent
227
+ });
228
+ let screen = site.screen;
229
+ let allowed;
230
+ let scope = page != null && !ranking ? scoped : undefined;
231
+ if (!scope && screen?.maximum != null && screen.maximum <= FEW) {
232
+ if (!membership.has(screen)) membership.set(screen, screen());
233
+ let within = membership.get(screen);
234
+ if (within) {
235
+ allowed = shared.get(screen);
236
+ if (!allowed) shared.set(screen, allowed = site.share(within));
237
+ }
238
+ }
239
+ // The owner is a row the query already admits through entity
240
+ // visibility, so a posting is asked only what its component's own
241
+ // visibility says. Asking each posting the entity's too sought the
242
+ // entity table once for every row holding the word: `task` beside a
243
+ // project's tasks read millions of transcript rows' entities cold.
244
+ return or(...indexes(worded(live), db?.stored?.v ?? site.vocab).map((ix)=>{
245
+ let { name, not } = ix, fts = tableOf(ix);
246
+ return among(site.owner, select({
247
+ cols: [
248
+ col('rowid')
249
+ ],
250
+ from: table(fts),
251
+ where: and(op('match', col(fts), val(t)), permitted(name, col('rowid', fts), aspects), ...unworn(not, col('rowid', fts)), ...scope ? [
252
+ withinOwners(col('rowid', fts), scope)
253
+ ] : [], ...allowed ? [
254
+ among(col('rowid', fts), select({
255
+ cols: [
256
+ col('id')
257
+ ],
258
+ from: allowed
259
+ }))
260
+ ] : [])
261
+ }));
262
+ }));
263
+ }
264
+ },
265
+ // The texts a property's substring index finds holding all of a needle's
266
+ // trigrams, in their first CUT or a piece of their tail past it, and the
267
+ // ones longer than CUT whose pieces are still owed (`PAST` without
268
+ // `DONE`), and whether there are at most FEW_TEXTS of them. A needle's
269
+ // first SPAN characters lie whole in the first CUT or in one piece, so
270
+ // its trigrams are those characters'. Until the tail index stands,
271
+ // the marker alone identifies every longer text.
272
+ //
273
+ // More than FEW_TEXTS of them, the texts a word index finds holding the
274
+ // needle's whole words in order (`phrased`) take their place where those
275
+ // are few: one that covers the property for every owner the read keeps,
276
+ // its text's own or one of a component the read requires (`within`). A
277
+ // phrase of common words is in every long text's trigrams, and few of
278
+ // their words: `.entry & .content.body~="apps shows the new button"`
279
+ // found 18,841 texts holding 1.1 GB, and walked the box's every entity
280
+ // to test them, 11 s (bug 14fa2b99); "shows the new" is in 117, and
281
+ // "shows the new button" * fewer still.
282
+ contains: (comp, prop, needle, within = [])=>{
283
+ // SQLite's trigram tokenizer and Unicode lowercasing can disagree.
284
+ // Only use its candidates for the ASCII LIKE path.
285
+ if (/\P{ASCII}/u.test(needle)) return null;
286
+ let ix = indexes(fields, db?.stored?.v).find((ix)=>ix.trigram && ix.comp == comp && ix.props.includes(prop));
287
+ let m = ix && grammed([
288
+ ...needle
289
+ ].slice(0, SPAN).join(''));
290
+ if (!ix || !m) return null;
291
+ let fts = tableOf(ix), tail = tailOf(ix);
292
+ let match = (t, q)=>op('match', col(t), val(q));
293
+ let owners = db && stands(tail) ? unionAll(select({
294
+ cols: [
295
+ col('rowid')
296
+ ],
297
+ from: table(fts),
298
+ where: match(fts, m)
299
+ }), select({
300
+ cols: [
301
+ op('/', col('rowid'), lit(PIECES))
302
+ ],
303
+ from: table(tail),
304
+ where: match(tail, m)
305
+ }), select({
306
+ cols: [
307
+ col('rowid')
308
+ ],
309
+ from: table(fts),
310
+ where: and(match(fts, `"${PAST}"`), not(among(op('*', col('rowid'), lit(PIECES)), select({
311
+ cols: [
312
+ col('rowid')
313
+ ],
314
+ from: table(tail),
315
+ where: match(tail, `"${DONE}"`)
316
+ }))))
317
+ })) : select({
318
+ cols: [
319
+ col('rowid')
320
+ ],
321
+ from: table(fts),
322
+ where: match(fts, `(${m}) OR "${PAST}"`)
323
+ });
324
+ // An index this file does not hold yet (its writer has not opened it
325
+ // with this vocabulary), or holds while still filling it, finds too
326
+ // few: the read goes in its own order and tests every text, and,
327
+ // answered rather than declined, is built again next time rather than
328
+ // kept (@yaks/sql kept.ts).
329
+ if (!db || !stands(fts) || fill?.pending(fts)) return {
330
+ few: false
331
+ };
332
+ let phrase = phrased(needle);
333
+ let words = phrase ? indexes(worded(fields), db.stored?.v).find((w)=>w.comp == comp && w.props.includes(prop) && (!w.on || within.includes(w.on)) && stands(tableOf(w)) && !fill?.pending(tableOf(w))) : undefined;
334
+ let key = `${fts}\0${m}\0${words ? tableOf(words) : ''}`;
335
+ let known = found.get(key);
336
+ if (known) return known;
337
+ // Only a caller's read begins, so a compile that never does (a rule's
338
+ // patterns) keeps no more than a few.
339
+ if (found.size >= 64) found.clear();
340
+ let few = (q)=>Number(db.query(select({
341
+ cols: [
342
+ as(count(), 'n')
343
+ ],
344
+ from: from({
345
+ ...q,
346
+ limit: lit(FEW_TEXTS + 1)
347
+ }, 'r')
348
+ }))[0].n) <= FEW_TEXTS;
349
+ let said = words && select({
350
+ cols: [
351
+ col('rowid')
352
+ ],
353
+ from: table(tableOf(words)),
354
+ where: match(tableOf(words), phrase)
355
+ });
356
+ let answer = few(owners) ? {
357
+ owners,
358
+ few: true
359
+ } : said && few(said) ? {
360
+ owners: said,
361
+ few: true
362
+ } : {
363
+ owners,
364
+ few: false
365
+ };
366
+ found.set(key, answer);
367
+ return answer;
368
+ },
369
+ // A window of a query with words in it is a search's best rows unless it
370
+ // says otherwise, where there is a connection to rank through.
371
+ ranks: (q)=>db && wordsIn(q).some((w)=>!!term(w)) ? SEARCH : null,
372
+ order: (value, site)=>{
373
+ if (value != SEARCH) return null;
374
+ seen(site);
375
+ if (!words.length || !db) {
376
+ throw new Unsupported(`.order=${SEARCH}`, db ? 'nothing to rank by — it orders the words of a text search' : 'a search composed without a connection does not rank', '@yaks/fts');
377
+ }
378
+ let ids = rank();
379
+ // No match selects no rows, so there is nothing to put in order.
380
+ if (!ids.length) return lit(null);
381
+ // Site.owner is this row's stable integer id, including cursor anchors.
382
+ return lookup(site.owner, ids.map((id, i)=>[
383
+ id,
384
+ lit(i)
385
+ ]), {
386
+ stable: true
387
+ }, lit(ids.length));
388
+ }
389
+ };
390
+ };
391
+ //# sourceMappingURL=compile.js.map
package/compile.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.js","sources":["./compile.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,EAAE;AACF,qFAAqF;AACrF,4EAA4E;AAC5E,gFAAgF;AAChF,+DAA+D;AAC/D,EAAE;AACF,4EAA4E;AAC5E,gFAAgF;AAChF,4EAA4E;AAC5E,aAAa;AACb,EAAE;AACF,2EAA2E;AAC3E,+EAA+E;AAC/E,+EAA+E;AAC/E,+EAA+E;AAC/E,kBAAkB;AAClB,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,2EAA2E;AAC3E,6EAA6E;AAC7E,6EA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