-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharel_builder_unit_spec.rb
More file actions
537 lines (509 loc) · 22.4 KB
/
Copy patharel_builder_unit_spec.rb
File metadata and controls
537 lines (509 loc) · 22.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# frozen_string_literal: true
require "spec_helper"
RSpec.describe "ArelBuilderUnitTest" do
before do
@builder = ParadeDB::Arel::Builder.new(:products)
@no_table_builder = ParadeDB::Arel::Builder.new
end
def sql(node)
ParadeDB::Arel.to_sql(node)
end
# ---- Builder accessor and basics ----
it "builder table accessor" do
assert_equal :products, @builder.table
end
it "builder without table" do
assert_nil @no_table_builder.table
end
it "bracket accessor returns attribute" do
attr = @builder[:description]
assert_instance_of Arel::Attributes::Attribute, attr
assert_equal "description", attr.name
assert_equal "products", attr.relation.name
end
it "bracket accessor without table" do
attr = @no_table_builder[:description]
assert_instance_of Arel::Nodes::SqlLiteral, attr
assert_equal "description", sql(attr)
end
it "column node with invalid type" do
error = assert_raises(ArgumentError) do
@builder.match(123, "term")
end
assert_match(/Unsupported column type: Integer/, error.message)
end
it "attribute without table renders column only" do
attr = @no_table_builder[:description]
assert_equal "description", sql(attr)
end
it "attribute with table renders table dot column" do
attr = @builder[:description]
assert_equal %("products"."description"), sql(attr)
end
# ---- match (match_all) ----
it "match single term" do
node = @builder.match(:description, "shoes")
assert_equal %("products"."description" &&& 'shoes'), sql(node)
end
it "match query" do
node = @builder.match(:description, "running shoes lightweight")
assert_equal %("products"."description" &&& 'running shoes lightweight'), sql(node)
end
it "match accepts sql function term" do
term = Arel::Nodes::NamedFunction.new("lower", [Arel::Nodes.build_quoted("SHOES")])
node = @builder.match(:description, term)
assert_equal %("products"."description" &&& lower('SHOES')), sql(node)
end
it "match with boost" do
node = @builder.match(:description, "shoes", boost: 2.5)
assert_equal %("products"."description" &&& 'shoes'::pdb.boost(2.5)), sql(node)
end
it "match with tokenizer override" do
node = @builder.match(:description, "running shoes", tokenizer: ParadeDB::Tokenizer.whitespace())
assert_equal %("products"."description" &&& 'running shoes'::pdb.whitespace), sql(node)
end
it "match with tokenizer override and args" do
node = @builder.match(:description, "running shoes", tokenizer: ParadeDB::Tokenizer.whitespace(options: {lowercase: false}))
assert_equal %("products"."description" &&& 'running shoes'::pdb.whitespace('lowercase=false')), sql(node)
end
it "match without boost" do
node = @builder.match(:description, "shoes", boost: nil)
assert_equal %("products"."description" &&& 'shoes'), sql(node)
end
# ---- match_any ----
it "match any single term" do
node = @builder.match_any(:description, "wireless")
assert_equal %("products"."description" ||| 'wireless'), sql(node)
end
it "match any query" do
node = @builder.match_any(:description, "wireless bluetooth earbuds")
assert_equal %("products"."description" ||| 'wireless bluetooth earbuds'), sql(node)
end
it "match any accepts sql function term" do
term = Arel.sql("trim(' shoes ')")
node = @builder.match_any(:description, term)
assert_equal %("products"."description" ||| trim(' shoes ')), sql(node)
end
# ---- phrase ----
it "phrase without slop" do
node = @builder.phrase(:description, "running shoes")
assert_equal %("products"."description" ### 'running shoes'), sql(node)
end
it "phrase with slop zero" do
node = @builder.phrase(:description, "running shoes", slop: 0)
assert_equal %("products"."description" ### 'running shoes'::pdb.slop(0)), sql(node)
end
it "phrase with slop large" do
node = @builder.phrase(:description, "running shoes", slop: 10)
assert_equal %("products"."description" ### 'running shoes'::pdb.slop(10)), sql(node)
end
it "phrase with tokenizer override" do
node = @builder.phrase(:description, "running shoes", tokenizer: ParadeDB::Tokenizer.whitespace())
assert_equal %("products"."description" ### 'running shoes'::pdb.whitespace), sql(node)
end
it "phrase with slop and constant score bridges through query" do
node = @builder.phrase(:description, "running shoes", slop: 2, constant_score: 1.0)
assert_equal %("products"."description" ### 'running shoes'::pdb.slop(2)::pdb.query::pdb.const(1.0)), sql(node)
end
it "phrase array renders array literal" do
node = @builder.phrase(:description, %w[running shoes])
assert_equal %("products"."description" ### ARRAY['running', 'shoes']), sql(node)
end
it "phrase array with slop and constant score bridges through query" do
node = @builder.phrase(:description, %w[shoes running], slop: 2, constant_score: 1.0)
assert_equal %("products"."description" ### ARRAY['shoes', 'running']::pdb.slop(2)::pdb.query::pdb.const(1.0)), sql(node)
end
# ---- term ----
it "term without boost" do
node = @builder.term(:category, "footwear")
assert_equal %("products"."category" === 'footwear'), sql(node)
end
it "term with integer boost" do
node = @builder.term(:category, "footwear", boost: 3)
assert_equal %("products"."category" === 'footwear'::pdb.boost(3)), sql(node)
end
it "term with float boost" do
node = @builder.term(:category, "footwear", boost: 1.5)
assert_equal %("products"."category" === 'footwear'::pdb.boost(1.5)), sql(node)
end
it "term with boolean value" do
node = @builder.term(:in_stock, true)
assert_equal %("products"."in_stock" === TRUE), sql(node)
end
it "term with integer value" do
node = @builder.term(:rating, 5)
assert_equal %("products"."rating" === 5), sql(node)
end
it "term accepts sql function value" do
term = Arel::Nodes::NamedFunction.new("lower", [Arel::Nodes.build_quoted("SHOES")])
node = @builder.term(:description, term)
assert_equal %("products"."description" === lower('SHOES')), sql(node)
end
it "term set with strings" do
node = @builder.term_set(:category, %w[audio footwear])
assert_equal %("products"."category" @@@ pdb.term_set(ARRAY['audio', 'footwear'])), sql(node)
end
it "term set with integers" do
node = @builder.term_set(:rating, [4, 5])
assert_equal %("products"."rating" @@@ pdb.term_set(ARRAY[4, 5])), sql(node)
end
it "term set with empty values raises" do
error = assert_raises(ArgumentError) { @builder.term_set(:category, []) }
assert_includes error.message, "term_set requires at least one value"
end
# ---- fuzzy options (flattened into match/term) ----
it "term with distance" do
node = @builder.term(:description, "shose", distance: 2)
assert_equal %("products"."description" === 'shose'::pdb.fuzzy(2)), sql(node)
end
it "term with prefix true" do
node = @builder.term(:description, "runn", distance: 1, prefix: true)
assert_equal %("products"."description" === 'runn'::pdb.fuzzy(1, "true")), sql(node)
end
it "term with prefix false" do
node = @builder.term(:description, "shose", distance: 2, prefix: false)
# prefix: false should not emit the "true" flag
assert_equal %("products"."description" === 'shose'::pdb.fuzzy(2)), sql(node)
end
it "term with boost only" do
node = @builder.term(:description, "shose", distance: 2, boost: 1.5)
assert_equal %("products"."description" === 'shose'::pdb.fuzzy(2)::pdb.boost(1.5)), sql(node)
end
it "term with constant score bridges through query" do
node = @builder.term(:description, "shose", distance: 2, constant_score: 1.0)
assert_equal %("products"."description" === 'shose'::pdb.fuzzy(2)::pdb.query::pdb.const(1.0)), sql(node)
end
it "term with transposition cost one" do
node = @builder.term(:description, "shose", distance: 1, transposition_cost_one: true)
assert_equal %("products"."description" === 'shose'::pdb.fuzzy(1, "false", "true")), sql(node)
end
it "term with prefix and transposition cost one" do
node = @builder.term(:description, "shose", distance: 1, prefix: true, transposition_cost_one: true)
assert_equal %("products"."description" === 'shose'::pdb.fuzzy(1, "true", "true")), sql(node)
end
it "matching any with distance" do
node = @builder.match_any(:description, "shoes", distance: 0)
assert_equal %("products"."description" ||| 'shoes'::pdb.fuzzy(0)), sql(node)
end
# ---- regex ----
it "regex simple" do
node = @builder.regex(:description, "run.*")
assert_equal %("products"."description" @@@ pdb.regex('run.*')), sql(node)
end
it "regex complex pattern" do
node = @builder.regex(:description, "(wireless|bluetooth).*earbuds")
assert_equal %("products"."description" @@@ pdb.regex('(wireless|bluetooth).*earbuds')), sql(node)
end
it "regex accepts sql function pattern" do
node = @builder.regex(:description, Arel.sql("lower('RUN.*')"))
assert_equal %("products"."description" @@@ pdb.regex(lower('RUN.*'))), sql(node)
end
it "regex phrase" do
node = @builder.regex_phrase(:description, "run.*", "sho.*")
assert_equal %("products"."description" @@@ pdb.regex_phrase(ARRAY['run.*', 'sho.*'])), sql(node)
end
it "regex phrase with options" do
node = @builder.regex_phrase(:description, "run.*", "sho.*", slop: 2, max_expansions: 100)
assert_equal %("products"."description" @@@ pdb.regex_phrase(ARRAY['run.*', 'sho.*'], slop => 2, max_expansions => 100)), sql(node)
end
# ---- near ----
it "near distance 1" do
node = @builder.near(:description, ParadeDB.proximity("running").within(1, "shoes"))
assert_equal %("products"."description" @@@ ('running' ## 1 ## 'shoes')), sql(node)
end
it "near ordered" do
node = @builder.near(:description, ParadeDB.proximity("running").within(1, "shoes", ordered: true))
assert_equal %("products"."description" @@@ ('running' ##> 1 ##> 'shoes')), sql(node)
end
it "near large distance" do
node = @builder.near(:description, ParadeDB.proximity("running").within(5, "shoes"))
assert_equal %("products"."description" @@@ ('running' ## 5 ## 'shoes')), sql(node)
end
it "near with array left operand" do
node = @builder.near(:description, ParadeDB.proximity("sleek", "white").within(1, "shoes"))
assert_equal %("products"."description" @@@ (pdb.prox_array('sleek', 'white') ## 1 ## 'shoes')), sql(node)
end
it "near with regex wrapper" do
node = @builder.near(:description, ParadeDB.regex_term("sl.*").within(1, "shoes"))
assert_equal %("products"."description" @@@ (pdb.prox_regex('sl.*') ## 1 ## 'shoes')), sql(node)
end
it "near with mixed array left operand" do
node = @builder.near(:description, ParadeDB.proximity(ParadeDB.regex_term("sl.*"), "white").within(1, "shoes"))
assert_equal %("products"."description" @@@ (pdb.prox_array(pdb.prox_regex('sl.*'), 'white') ## 1 ## 'shoes')), sql(node)
end
it "near with array right operand" do
node = @builder.near(:description, ParadeDB.proximity("sleek").within(1, "white", "shoes"))
assert_equal %("products"."description" @@@ ('sleek' ## 1 ## pdb.prox_array('white', 'shoes'))), sql(node)
end
it "near with mixed array right operand" do
node = @builder.near(:description, ParadeDB.proximity("sleek").within(1, "white", ParadeDB.regex_term("sho.*")))
assert_equal %("products"."description" @@@ ('sleek' ## 1 ## pdb.prox_array('white', pdb.prox_regex('sho.*')))), sql(node)
end
it "near with regex wrapper max expansions" do
node = @builder.near(:description, ParadeDB.regex_term("sl.*", max_expansions: 100).within(1, "shoes"))
assert_equal %("products"."description" @@@ (pdb.prox_regex('sl.*', 100) ## 1 ## 'shoes')), sql(node)
end
it "near with boost" do
node = @builder.near(:description, ParadeDB.proximity("running").within(1, "shoes"), boost: 2.0)
assert_equal %("products"."description" @@@ ('running' ## 1 ## 'shoes')::pdb.boost(2.0)), sql(node)
end
it "near with const" do
node = @builder.near(:description, ParadeDB.proximity("running").within(1, "shoes"), const: 1.0)
assert_equal %("products"."description" @@@ ('running' ## 1 ## 'shoes')::pdb.const(1.0)), sql(node)
end
it "near nested clauses" do
node = @builder.near(
:description,
ParadeDB.proximity(ParadeDB.regex_term("sl.*"), "running")
.within(1, "shoes")
.within(3, ParadeDB.regex_term("right").within(3, "associative"))
)
assert_equal %("products"."description" @@@ ((pdb.prox_array(pdb.prox_regex('sl.*'), 'running') ## 1 ## 'shoes') ## 3 ## (pdb.prox_regex('right') ## 3 ## 'associative'))), sql(node)
end
it "near rejects a non proximity clause" do
error = assert_raises(ArgumentError) do
@builder.near(:description, "running")
end
assert_includes error.message, "near requires a ParadeDB.proximity"
end
it "near rejects a proximity clause without within" do
error = assert_raises(ArgumentError) do
@builder.near(:description, ParadeDB.proximity("running"))
end
assert_includes error.message, "near requires at least one within clause"
end
it "near rejects boost and const together" do
error = assert_raises(ArgumentError) do
@builder.near(:description, ParadeDB.proximity("running").within(1, "shoes"), boost: 2.0, const: 1.0)
end
assert_includes error.message, "boost and const are mutually exclusive"
end
# ---- phrase_prefix ----
it "phrase prefix single term" do
node = @builder.phrase_prefix(:description, "run")
assert_equal %("products"."description" @@@ pdb.phrase_prefix(ARRAY['run'])), sql(node)
end
it "phrase prefix multiple terms" do
node = @builder.phrase_prefix(:description, "running", "sh")
assert_equal %("products"."description" @@@ pdb.phrase_prefix(ARRAY['running', 'sh'])), sql(node)
end
it "phrase prefix with max expansion" do
node = @builder.phrase_prefix(:description, "running", "sh", max_expansion: 100)
assert_equal %("products"."description" @@@ pdb.phrase_prefix(ARRAY['running', 'sh'], 100)), sql(node)
end
it "phrase prefix three terms" do
node = @builder.phrase_prefix(:description, "trail", "running", "sh")
assert_equal %("products"."description" @@@ pdb.phrase_prefix(ARRAY['trail', 'running', 'sh'])), sql(node)
end
it "exists wrapper" do
node = @builder.exists(:id)
assert_equal %("products"."id" @@@ pdb.exists()), sql(node)
end
it "range wrapper with Ruby range" do
node = @builder.range(:rating, 3..5)
assert_equal %("products"."rating" @@@ pdb.range(int8range(3, 5, '[]'))), sql(node)
end
it "range wrapper with exclusive end range" do
node = @builder.range(:rating, 3...5)
assert_equal %q{"products"."rating" @@@ pdb.range(int8range(3, 5, '[)'))}, sql(node)
end
it "range wrapper with bound options" do
node = @builder.range(:rating, nil, gte: 3, lt: 5)
assert_equal %q{"products"."rating" @@@ pdb.range(int8range(3, 5, '[)'))}, sql(node)
end
it "range term scalar value" do
node = @builder.range_term(:weight_range, 1)
assert_equal %("products"."weight_range" @@@ pdb.range_term(1)), sql(node)
end
it "range term with relation" do
node = @builder.range_term(:weight_range, "(10, 12]", relation: "Intersects", range_type: "int4range")
assert_equal %q{"products"."weight_range" @@@ pdb.range_term('(10, 12]'::int4range, 'Intersects')}, sql(node)
end
# ---- more_like_this ----
it "more like this with integer key" do
node = @builder.more_like_this(:id, 3, fields: [:description])
assert_equal %("products"."id" @@@ pdb.more_like_this(3, ARRAY['description'])), sql(node)
end
it "more like this without fields" do
node = @builder.more_like_this(:id, 3)
assert_equal %("products"."id" @@@ pdb.more_like_this(3)), sql(node)
end
it "more like this with json string" do
node = @builder.more_like_this(:id, '{"description": "running shoes"}')
assert_equal %("products"."id" @@@ pdb.more_like_this('{"description": "running shoes"}')), sql(node)
end
it "more like this with multiple fields" do
node = @builder.more_like_this(:id, 5, fields: [:description, :category])
assert_equal %("products"."id" @@@ pdb.more_like_this(5, ARRAY['description', 'category'])), sql(node)
end
it "more like this with options" do
node = @builder.more_like_this(
:id,
5,
fields: [:description],
options: { min_term_frequency: 2, max_query_terms: 10, stopwords: %w[the a] }
)
assert_equal %("products"."id" @@@ pdb.more_like_this(5, ARRAY['description'], min_term_frequency => 2, max_query_terms => 10, stopwords => ARRAY['the', 'a'])), sql(node)
end
# ---- full_text ----
it "full text with string expression" do
node = @builder.full_text(:description, "pdb.all()")
assert_equal %("products"."description" @@@ pdb.all()), sql(node)
end
it "full text with node expression" do
inner = @builder.match(:description, "shoes")
node = @builder.full_text(:id, inner)
rendered = sql(node)
assert_includes rendered, %("products"."id" @@@)
end
# ---- score / snippet / agg ----
it "score renders pdb function" do
node = @builder.score(:id)
assert_equal %(pdb.score("products"."id")), sql(node)
end
it "snippet no extra args" do
node = @builder.snippet(:description)
assert_equal %(pdb.snippet("products"."description")), sql(node)
end
it "snippet with tags" do
node = @builder.snippet(:description, "<b>", "</b>")
assert_equal %(pdb.snippet("products"."description", '<b>', '</b>')), sql(node)
end
it "snippet with tags and max chars" do
node = @builder.snippet(:description, "<b>", "</b>", 100)
assert_equal %(pdb.snippet("products"."description", '<b>', '</b>', 100)), sql(node)
end
it "snippets with named args" do
node = @builder.snippets(
:description,
start_tag: "<em>",
end_tag: "</em>",
max_num_chars: 15,
limit: 1,
offset: 0,
sort_by: "position"
)
assert_equal %(pdb.snippets("products"."description", start_tag => '<em>', end_tag => '</em>', max_num_chars => 15, "limit" => 1, "offset" => 0, sort_by => 'position')), sql(node)
end
it "snippet positions" do
node = @builder.snippet_positions(:description)
assert_equal %(pdb.snippet_positions("products"."description")), sql(node)
end
it "agg json string" do
node = @builder.agg('{"terms":{"field":"category","size":10}}')
assert_equal %(pdb.agg('{"terms":{"field":"category","size":10}}')), sql(node)
end
# ---- Boolean composition ----
it "and composition" do
a = @builder.match(:description, "shoes")
b = @builder.match(:category, "footwear")
combined = a.and(b)
expected = %("products"."description" &&& 'shoes' AND "products"."category" &&& 'footwear')
assert_sql_equal expected, sql(combined)
end
it "or composition" do
a = @builder.match(:description, "shoes")
b = @builder.match(:description, "boots")
combined = a.or(b)
expected = %(("products"."description" &&& 'shoes' OR "products"."description" &&& 'boots'))
assert_sql_equal expected, sql(combined)
end
it "not composition" do
a = @builder.match(:description, "cheap")
negated = a.not
assert_equal %(NOT ("products"."description" &&& 'cheap')), sql(negated)
end
it "nested and or not" do
shoes = @builder.match(:description, "shoes")
cheap = @builder.match(:description, "cheap")
boots = @builder.match(:description, "boots")
# (shoes AND NOT cheap) OR boots
combined = shoes.and(cheap.not).or(boots)
rendered = sql(combined)
assert_includes rendered, "AND NOT"
assert_includes rendered, " OR "
assert_includes rendered, "'shoes'"
assert_includes rendered, "'cheap'"
assert_includes rendered, "'boots'"
end
it "double negation" do
a = @builder.match(:description, "shoes")
double_neg = a.not.not
assert_equal %(NOT (NOT ("products"."description" &&& 'shoes'))), sql(double_neg)
end
it "triple and chain" do
a = @builder.match(:description, "shoes")
b = @builder.term(:in_stock, true)
c = @builder.term(:rating, 5)
combined = a.and(b).and(c)
rendered = sql(combined)
assert_includes rendered, "'shoes'"
assert_includes rendered, "TRUE"
assert_includes rendered, "5"
# Verify nested AND structure
assert_equal 2, rendered.scan("AND").size
end
# ---- to_sql helper and quoting primitives ----
it "to sql rejects unknown node" do
unknown = Object.new
assert_raises(TypeError) { ParadeDB::Arel.to_sql(unknown) }
end
it "build quoted string" do
assert_equal "'hello'", sql(Arel::Nodes.build_quoted("hello"))
end
it "build quoted integer" do
assert_equal "42", sql(Arel::Nodes.build_quoted(42))
end
it "build quoted boolean" do
assert_equal "TRUE", sql(Arel::Nodes.build_quoted(true))
end
# ---- ParadeDB::Arel.sql helper ----
it "arel sql helper" do
literal = ParadeDB::Arel.sql("pdb.all()")
assert_instance_of Arel::Nodes::SqlLiteral, literal
assert_equal "pdb.all()", sql(literal)
end
# ---- Edge cases: special characters ----
it "match with single quote in term" do
node = @builder.match(:description, "shoe's")
rendered = sql(node)
# Should be properly quoted (escaped single quote)
assert_includes rendered, "&&&"
refute_includes rendered, "shoe's'" # no unescaped quote
end
it "regex with backslash" do
node = @builder.regex(:description, "foo\\\\bar")
rendered = sql(node)
assert_includes rendered, "pdb.regex("
end
# ---- Cross-operator composition ----
it "match and regex composed" do
match_node = @builder.match(:description, "shoes")
regex_node = @builder.regex(:description, "run.*")
combined = match_node.and(regex_node)
rendered = sql(combined)
assert_includes rendered, "&&&"
assert_includes rendered, "@@@"
assert_includes rendered, "pdb.regex"
assert_includes rendered, "AND"
end
it "term or fuzzy composed" do
term_node = @builder.term(:description, "shoes")
fuzzy_node = @builder.term(:description, "shose", distance: 2)
combined = term_node.or(fuzzy_node)
rendered = sql(combined)
assert_includes rendered, "==="
assert_includes rendered, "pdb.fuzzy"
assert_includes rendered, " OR "
end
it "phrase and not match composed" do
phrase_node = @builder.phrase(:description, "running shoes", slop: 2)
match_node = @builder.match(:description, "cheap")
combined = phrase_node.and(match_node.not)
rendered = sql(combined)
assert_includes rendered, "###"
assert_includes rendered, "pdb.slop(2)"
assert_includes rendered, "AND NOT"
assert_includes rendered, "'cheap'"
end
end