@@ -22,65 +22,19 @@ describe('eql_v3 text_search column', () => {
2222 expect ( v3 ) . toStrictEqual ( v2 )
2323 } )
2424
25- it ( '.freeTextSearch(opts) overrides each provided key and keeps the rest as defaults' , ( ) => {
26- const built = types
27- . TextSearch ( 'email' )
28- . freeTextSearch ( {
29- tokenizer : { kind : 'ngram' , token_length : 4 } ,
30- k : 8 ,
31- m : 4096 ,
32- include_original : false ,
33- } )
34- . build ( )
25+ it ( 'default build() emits the unique, ore, and match indexes' , ( ) => {
26+ const built = types . TextSearch ( 'email' ) . build ( )
27+ expect ( built . indexes . unique ) . toEqual ( { token_filters : [ ] } )
28+ expect ( built . indexes . ore ) . toEqual ( { } )
3529 expect ( built . indexes . match ) . toEqual ( {
36- tokenizer : { kind : 'ngram' , token_length : 4 } ,
37- // omitted -> default downcase filter retained
30+ tokenizer : { kind : 'ngram' , token_length : 3 } ,
3831 token_filters : [ { kind : 'downcase' } ] ,
39- k : 8 ,
40- m : 4096 ,
41- include_original : false ,
32+ k : 6 ,
33+ m : 2048 ,
34+ include_original : true ,
4235 } )
4336 } )
4437
45- it ( '.freeTextSearch({ token_filters: [] }) overrides the downcase default with an empty array' , ( ) => {
46- // LOAD-BEARING: `[] ?? default` evaluates to `[]` (an empty array is not
47- // nullish), so an explicit empty array must OVERRIDE the downcase default,
48- // not fall back to it. Mirrors v2 (schema-builders.test.ts).
49- const built = types
50- . TextSearch ( 'email' )
51- . freeTextSearch ( { token_filters : [ ] } )
52- . build ( )
53- expect ( built . indexes . match . token_filters ) . toEqual ( [ ] )
54- } )
55-
56- it ( 'repeated .freeTextSearch() calls are last-call-wins-fully (each re-merges against defaults, not prior state)' , ( ) => {
57- // Each call re-merges against a fresh defaultMatchOpts(), not the
58- // accumulated matchOpts — so the second call resets k back to its default
59- // of 6. This is intentional: it mirrors v2 exactly. Pinned here so a future
60- // "merge against current state" change can't silently slip in.
61- const built = types
62- . TextSearch ( 'email' )
63- . freeTextSearch ( { k : 8 } )
64- . freeTextSearch ( { m : 4096 } )
65- . build ( )
66- expect ( built . indexes . match . k ) . toBe ( 6 )
67- expect ( built . indexes . match . m ) . toBe ( 4096 )
68- } )
69-
70- it ( '.freeTextSearch() with no argument is a no-op: build() equals the default build()' , ( ) => {
71- // Pins the opts === undefined branch: every `opts?.x ?? default` falls
72- // through, so a bare call must emit exactly the default match block.
73- expect ( types . TextSearch ( 'email' ) . freeTextSearch ( ) . build ( ) ) . toStrictEqual (
74- types . TextSearch ( 'email' ) . build ( ) ,
75- )
76- } )
77-
78- it ( '.freeTextSearch() is tuning-only: unique and ore indexes stay present' , ( ) => {
79- const built = types . TextSearch ( 'email' ) . freeTextSearch ( { k : 8 } ) . build ( )
80- expect ( built . indexes . unique ) . toEqual ( { token_filters : [ ] } )
81- expect ( built . indexes . ore ) . toEqual ( { } )
82- } )
83-
8438 it ( 'built columns share no mutable state: mutating one build() output does not affect another' , ( ) => {
8539 // Guards against the shared-defaults aliasing bug: defaults come from a
8640 // per-instance factory and build() deep-clones the match block.
@@ -104,29 +58,6 @@ describe('eql_v3 text_search column', () => {
10458 expect ( c . indexes . match . k ) . toBe ( 6 )
10559 expect ( c . indexes . match . token_filters ) . toEqual ( [ { kind : 'downcase' } ] )
10660 } )
107-
108- it ( 'clones caller opts on freeTextSearch(): mutating them before build() does not leak' , ( ) => {
109- // build() deep-clones at build time, but if freeTextSearch stored the
110- // caller's nested tokenizer / token_filters by reference, a caller mutating
111- // their own opts object between freeTextSearch(opts) and build() would leak
112- // the mutation into the emitted config. freeTextSearch must clone on write.
113- const opts = {
114- tokenizer : { kind : 'ngram' as const , token_length : 3 } ,
115- token_filters : [ { kind : 'downcase' as const } ] ,
116- }
117- const col = types . TextSearch ( 'email' ) . freeTextSearch ( opts )
118-
119- // Mutate the caller's own opts AFTER freeTextSearch but BEFORE build().
120- opts . tokenizer . token_length = 999
121- opts . token_filters . push ( { kind : 'downcase' as const } )
122-
123- const built = col . build ( )
124- expect ( built . indexes . match . tokenizer ) . toEqual ( {
125- kind : 'ngram' ,
126- token_length : 3 ,
127- } )
128- expect ( built . indexes . match . token_filters ) . toEqual ( [ { kind : 'downcase' } ] )
129- } )
13061} )
13162
13263describe ( 'eql_v3 text_match column' , ( ) => {
0 commit comments