Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 40897bb

Browse files
trzysiektrzysiekjakozaur
authored
[flights] Small fixes to ilike expr renderer (#1340)
Fixes `Delays & Cancellations Panel` and a test. --------- Signed-off-by: Krzysztof Kiewicz <[email protected]> Co-authored-by: trzysiek <[email protected]> Co-authored-by: Jacek Migdal <[email protected]>
1 parent c689854 commit 40897bb

File tree

14 files changed

+227
-194
lines changed

14 files changed

+227
-194
lines changed

platform/frontend_connectors/schema_array_transformer.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@ func NewArrayTypeVisitor(resolver arrayTypeResolver) model.ExprVisitor {
9494
if ok {
9595
dbType := resolver.dbColumnType(column.ColumnName)
9696
if strings.HasPrefix(dbType, "Array") {
97-
op := strings.ToUpper(e.Op)
98-
op = strings.TrimSpace(op)
97+
op := strings.TrimSpace(e.Op)
98+
opUpperCase := strings.ToUpper(op)
9999
switch {
100-
case (op == "ILIKE" || op == "LIKE") && dbType == "Array(String)":
100+
case (opUpperCase == "ILIKE" || opUpperCase == "LIKE" || op == model.MatchOperator) && dbType == "Array(String)":
101101

102+
if op == model.MatchOperator {
103+
op = "ILIKE"
104+
}
102105
variableName := "x"
103106
lambda := model.NewLambdaExpr([]string{variableName}, model.NewInfixExpr(model.NewLiteral(variableName), op, e.Right.Accept(b).(model.Expr)))
104107
return model.NewFunction("arrayExists", lambda, e.Left)

platform/frontend_connectors/schema_transformer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,10 @@ func (s *SchemaCheckPass) applyMatchOperator(indexSchema schema.Schema, query *m
10681068

10691069
switch field.Type.String() {
10701070
case schema.QuesmaTypeInteger.Name, schema.QuesmaTypeLong.Name, schema.QuesmaTypeUnsignedLong.Name, schema.QuesmaTypeFloat.Name, schema.QuesmaTypeBoolean.Name:
1071+
rhsValue = strings.Trim(rhsValue, "%")
10711072
return model.NewInfixExpr(lhs, "=", model.NewLiteral(rhsValue))
10721073
default:
1073-
return model.NewInfixExpr(lhs, "iLIKE", model.NewLiteralWithEscapeType(rhsValue, model.NotEscapedLikeFull))
1074+
return model.NewInfixExpr(lhs, "ILIKE", model.NewLiteralWithEscapeType(rhsValue, rhs.EscapeType))
10741075
}
10751076
}
10761077

platform/frontend_connectors/schema_transformer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ func Test_applyMatchOperator(t *testing.T) {
11611161
WhereClause: model.NewInfixExpr(
11621162
model.NewColumnRef("message"),
11631163
model.MatchOperator,
1164-
model.NewLiteral("'needle'"),
1164+
model.NewLiteralWithEscapeType("'needle'", model.NotEscapedLikeFull),
11651165
),
11661166
},
11671167
},
@@ -1172,8 +1172,8 @@ func Test_applyMatchOperator(t *testing.T) {
11721172
Columns: []model.Expr{model.NewColumnRef("message")},
11731173
WhereClause: model.NewInfixExpr(
11741174
model.NewColumnRef("message"),
1175-
"iLIKE",
1176-
model.NewLiteral("'%needle%'"),
1175+
"ILIKE",
1176+
model.NewLiteralWithEscapeType("needle", model.NotEscapedLikeFull),
11771177
),
11781178
},
11791179
},

platform/model/expr_string_renderer.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,15 @@ func (v *renderer) VisitLiteral(l LiteralExpr) interface{} {
7575
case NotEscapedLikePrefix:
7676
return util.SingleQuote(escapeStringLike(escapeStringNormal(val)) + "%")
7777
case NotEscapedLikeFull:
78-
return util.SingleQuote("%" + escapeStringLike(escapeStringNormal(val)) + "%")
78+
withoutPercents := escapeStringLike(escapeStringNormal(val))
79+
if util.IsSingleQuoted(val) {
80+
withoutPercents = strings.Trim(withoutPercents, "'")
81+
}
82+
return util.SingleQuote(util.SurroundWithPercents(withoutPercents))
7983
case FullyEscaped:
84+
if util.IsSingleQuoted(val) {
85+
return val
86+
}
8087
return util.SingleQuote(val)
8188
default:
8289
logger.WarnWithThrottling("unknown_literal", "VisitLiteral %s", val)
@@ -118,9 +125,9 @@ func (v *renderer) VisitInfix(e InfixExpr) interface{} {
118125

119126
// This might look like a strange heuristics to but is aligned with the way we are currently generating the statement
120127
// I think in the future every infix op should be in braces.
121-
if strings.HasPrefix(e.Op, "_") || e.Op == "AND" || e.Op == "OR" {
128+
if (strings.HasPrefix(e.Op, "_") && e.Op != MatchOperator) || e.Op == "AND" || e.Op == "OR" { // LIKE is without (), so I propose MatchOperator as well
122129
return fmt.Sprintf("(%v %v %v)", lhs, e.Op, rhs)
123-
} else if strings.Contains(e.Op, "LIKE") || e.Op == "IS" || e.Op == "IN" || e.Op == "NOT IN" || e.Op == "REGEXP" || strings.Contains(e.Op, "UNION") {
130+
} else if strings.Contains(e.Op, "LIKE") || e.Op == MatchOperator || e.Op == "IS" || e.Op == "IN" || e.Op == "NOT IN" || e.Op == "REGEXP" || strings.Contains(e.Op, "UNION") {
124131
return fmt.Sprintf("%v %v %v", lhs, e.Op, rhs)
125132
} else {
126133
return fmt.Sprintf("%v%v%v", lhs, e.Op, rhs)

platform/parsers/elastic_query_dsl/lucene/lucene_parser_test.go

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ func TestTranslatingLuceneQueriesToSQL(t *testing.T) {
1717
query string
1818
want string
1919
}{
20-
{`title:"The Right Way" AND text:go!!`, `("title" ILIKE '%The Right Way%' AND "text" ILIKE '%go!!%')`},
21-
{`title:Do it right AND right`, `((("title" ILIKE '%Do%' OR ("title" ILIKE '%it%' OR "text" ILIKE '%it%')) OR ("title" ILIKE '%right%' OR "text" ILIKE '%right%')) AND ("title" ILIKE '%right%' OR "text" ILIKE '%right%'))`},
22-
{`roam~`, `("title" ILIKE '%roam%' OR "text" ILIKE '%roam%')`},
23-
{`roam~0.8`, `("title" ILIKE '%roam%' OR "text" ILIKE '%roam%')`},
24-
{`jakarta^4 apache`, `(("title" ILIKE '%jakarta%' OR "text" ILIKE '%jakarta%') OR ("title" ILIKE '%apache%' OR "text" ILIKE '%apache%'))`},
25-
{`"jakarta apache"^10`, `("title" ILIKE '%jakarta apache%' OR "text" ILIKE '%jakarta apache%')`},
26-
{`"jakarta apache"~10`, `("title" ILIKE '%jakarta apache%' OR "text" ILIKE '%jakarta apache%')`},
20+
{`title:"The Right Way" AND text:go!!`, `("title" __quesma_match '%The Right Way%' AND "text" __quesma_match '%go!!%')`},
21+
{`title:Do it right AND right`, `((("title" __quesma_match '%Do%' OR ("title" __quesma_match '%it%' OR "text" __quesma_match '%it%')) OR ("title" __quesma_match '%right%' OR "text" __quesma_match '%right%')) AND ("title" __quesma_match '%right%' OR "text" __quesma_match '%right%'))`},
22+
{`roam~`, `("title" __quesma_match '%roam%' OR "text" __quesma_match '%roam%')`},
23+
{`roam~0.8`, `("title" __quesma_match '%roam%' OR "text" __quesma_match '%roam%')`},
24+
{`jakarta^4 apache`, `(("title" __quesma_match '%jakarta%' OR "text" __quesma_match '%jakarta%') OR ("title" __quesma_match '%apache%' OR "text" __quesma_match '%apache%'))`},
25+
{`"jakarta apache"^10`, `("title" __quesma_match '%jakarta apache%' OR "text" __quesma_match '%jakarta apache%')`},
26+
{`"jakarta apache"~10`, `("title" __quesma_match '%jakarta apache%' OR "text" __quesma_match '%jakarta apache%')`},
2727
{`mod_date:[2002-01-01 TO 2003-02-15]`, `("mod_date" >= '2002-01-01' AND "mod_date" <= '2003-02-15')`}, // 7
2828
{`mod_date:[2002-01-01 TO 2003-02-15}`, `("mod_date" >= '2002-01-01' AND "mod_date" < '2003-02-15')`},
2929
{`age:>10`, `"age" > '10'`},
@@ -37,52 +37,52 @@ func TestTranslatingLuceneQueriesToSQL(t *testing.T) {
3737
{`age: <-10.2`, `"age" < '-10.2'`},
3838
{`age: < -10.2`, `"age" < '-10.2'`},
3939
{`age:10.2 age2:[12 TO 15] age3:{11 TO *}`, `(("age" = 10.2 OR ("age2" >= '12' AND "age2" <= '15')) OR "age3" > '11')`},
40-
{`date:{* TO 2012-01-01} another`, `("date" < '2012-01-01' OR ("title" ILIKE '%another%' OR "text" ILIKE '%another%'))`},
41-
{`date:{2012-01-15 TO *} another`, `("date" > '2012-01-15' OR ("title" ILIKE '%another%' OR "text" ILIKE '%another%'))`},
40+
{`date:{* TO 2012-01-01} another`, `("date" < '2012-01-01' OR ("title" __quesma_match '%another%' OR "text" __quesma_match '%another%'))`},
41+
{`date:{2012-01-15 TO *} another`, `("date" > '2012-01-15' OR ("title" __quesma_match '%another%' OR "text" __quesma_match '%another%'))`},
4242
{`date:{* TO *}`, `"date" IS NOT NULL`},
4343
{`title:{Aida TO Carmen]`, `("title" > 'Aida' AND "title" <= 'Carmen')`},
4444
{`count:[1 TO 5]`, `("count" >= '1' AND "count" <= '5')`}, // 17
45-
{`"jakarta apache" AND "Apache Lucene"`, `(("title" ILIKE '%jakarta apache%' OR "text" ILIKE '%jakarta apache%') AND ("title" ILIKE '%Apache Lucene%' OR "text" ILIKE '%Apache Lucene%'))`},
46-
{`NOT status:"jakarta apache"`, `NOT ("status" ILIKE '%jakarta apache%')`},
47-
{`"jakarta apache" NOT "Apache Lucene"`, `(("title" ILIKE '%jakarta apache%' OR "text" ILIKE '%jakarta apache%') AND NOT (("title" ILIKE '%Apache Lucene%' OR "text" ILIKE '%Apache Lucene%')))`},
48-
{`(jakarta OR apache) AND website`, `(((("title" ILIKE '%jakarta%' OR "text" ILIKE '%jakarta%')) OR ("title" ILIKE '%apache%' OR "text" ILIKE '%apache%')) AND ("title" ILIKE '%website%' OR "text" ILIKE '%website%'))`},
49-
{`title:(return "pink panther")`, `("title" ILIKE '%return%' OR "title" ILIKE '%pink panther%')`},
50-
{`status:(active OR pending) title:(full text search)^2`, `(("status" ILIKE '%active%' OR "status" ILIKE '%pending%') OR (("title" ILIKE '%full%' OR "title" ILIKE '%text%') OR "title" ILIKE '%search%'))`},
51-
{`status:(active OR NOT (pending AND in-progress)) title:(full text search)^2`, `(("status" ILIKE '%active%' OR NOT (("status" ILIKE '%pending%' AND "status" ILIKE '%in-progress%'))) OR (("title" ILIKE '%full%' OR "title" ILIKE '%text%') OR "title" ILIKE '%search%'))`},
52-
{`status:(NOT active OR NOT (pending AND in-progress)) title:(full text search)^2`, `((NOT ("status" ILIKE '%active%') OR NOT (("status" ILIKE '%pending%' AND "status" ILIKE '%in-progress%'))) OR (("title" ILIKE '%full%' OR "title" ILIKE '%text%') OR "title" ILIKE '%search%'))`},
53-
{`status:(active OR (pending AND in-progress)) title:(full text search)^2`, `(("status" ILIKE '%active%' OR ("status" ILIKE '%pending%' AND "status" ILIKE '%in-progress%')) OR (("title" ILIKE '%full%' OR "title" ILIKE '%text%') OR "title" ILIKE '%search%'))`},
54-
{`status:((a OR (b AND c)) AND d)`, `(("status" ILIKE '%a%' OR ("status" ILIKE '%b%' AND "status" ILIKE '%c%')) AND "status" ILIKE '%d%')`},
55-
{`title:(return [Aida TO Carmen])`, `("title" ILIKE '%return%' OR ("title" >= 'Aida' AND "title" <= 'Carmen'))`},
56-
{`host.name:(NOT active OR NOT (pending OR in-progress)) (full text search)^2`, `((((NOT ("host.name" ILIKE '%active%') OR NOT (("host.name" ILIKE '%pending%' OR "host.name" ILIKE '%in-progress%'))) OR (("title" ILIKE '%full%' OR "text" ILIKE '%full%'))) OR ("title" ILIKE '%text%' OR "text" ILIKE '%text%')) OR ("title" ILIKE '%search%' OR "text" ILIKE '%search%'))`},
57-
{`host.name:(active AND NOT (pending OR in-progress)) hermes nemesis^2`, `((("host.name" ILIKE '%active%' AND NOT (("host.name" ILIKE '%pending%' OR "host.name" ILIKE '%in-progress%'))) OR ("title" ILIKE '%hermes%' OR "text" ILIKE '%hermes%')) OR ("title" ILIKE '%nemesis%' OR "text" ILIKE '%nemesis%'))`},
45+
{`"jakarta apache" AND "Apache Lucene"`, `(("title" __quesma_match '%jakarta apache%' OR "text" __quesma_match '%jakarta apache%') AND ("title" __quesma_match '%Apache Lucene%' OR "text" __quesma_match '%Apache Lucene%'))`},
46+
{`NOT status:"jakarta apache"`, `NOT ("status" __quesma_match '%jakarta apache%')`},
47+
{`"jakarta apache" NOT "Apache Lucene"`, `(("title" __quesma_match '%jakarta apache%' OR "text" __quesma_match '%jakarta apache%') AND NOT (("title" __quesma_match '%Apache Lucene%' OR "text" __quesma_match '%Apache Lucene%')))`},
48+
{`(jakarta OR apache) AND website`, `(((("title" __quesma_match '%jakarta%' OR "text" __quesma_match '%jakarta%')) OR ("title" __quesma_match '%apache%' OR "text" __quesma_match '%apache%')) AND ("title" __quesma_match '%website%' OR "text" __quesma_match '%website%'))`},
49+
{`title:(return "pink panther")`, `("title" __quesma_match '%return%' OR "title" __quesma_match '%pink panther%')`},
50+
{`status:(active OR pending) title:(full text search)^2`, `(("status" __quesma_match '%active%' OR "status" __quesma_match '%pending%') OR (("title" __quesma_match '%full%' OR "title" __quesma_match '%text%') OR "title" __quesma_match '%search%'))`},
51+
{`status:(active OR NOT (pending AND in-progress)) title:(full text search)^2`, `(("status" __quesma_match '%active%' OR NOT (("status" __quesma_match '%pending%' AND "status" __quesma_match '%in-progress%'))) OR (("title" __quesma_match '%full%' OR "title" __quesma_match '%text%') OR "title" __quesma_match '%search%'))`},
52+
{`status:(NOT active OR NOT (pending AND in-progress)) title:(full text search)^2`, `((NOT ("status" __quesma_match '%active%') OR NOT (("status" __quesma_match '%pending%' AND "status" __quesma_match '%in-progress%'))) OR (("title" __quesma_match '%full%' OR "title" __quesma_match '%text%') OR "title" __quesma_match '%search%'))`},
53+
{`status:(active OR (pending AND in-progress)) title:(full text search)^2`, `(("status" __quesma_match '%active%' OR ("status" __quesma_match '%pending%' AND "status" __quesma_match '%in-progress%')) OR (("title" __quesma_match '%full%' OR "title" __quesma_match '%text%') OR "title" __quesma_match '%search%'))`},
54+
{`status:((a OR (b AND c)) AND d)`, `(("status" __quesma_match '%a%' OR ("status" __quesma_match '%b%' AND "status" __quesma_match '%c%')) AND "status" __quesma_match '%d%')`},
55+
{`title:(return [Aida TO Carmen])`, `("title" __quesma_match '%return%' OR ("title" >= 'Aida' AND "title" <= 'Carmen'))`},
56+
{`host.name:(NOT active OR NOT (pending OR in-progress)) (full text search)^2`, `((((NOT ("host.name" __quesma_match '%active%') OR NOT (("host.name" __quesma_match '%pending%' OR "host.name" __quesma_match '%in-progress%'))) OR (("title" __quesma_match '%full%' OR "text" __quesma_match '%full%'))) OR ("title" __quesma_match '%text%' OR "text" __quesma_match '%text%')) OR ("title" __quesma_match '%search%' OR "text" __quesma_match '%search%'))`},
57+
{`host.name:(active AND NOT (pending OR in-progress)) hermes nemesis^2`, `((("host.name" __quesma_match '%active%' AND NOT (("host.name" __quesma_match '%pending%' OR "host.name" __quesma_match '%in-progress%'))) OR ("title" __quesma_match '%hermes%' OR "text" __quesma_match '%hermes%')) OR ("title" __quesma_match '%nemesis%' OR "text" __quesma_match '%nemesis%'))`},
5858

5959
// special characters
60-
{`dajhd \(%&RY#WFDG`, `(("title" ILIKE '%dajhd%' OR "text" ILIKE '%dajhd%') OR ("title" ILIKE '%(\%&RY#WFDG%' OR "text" ILIKE '%(\%&RY#WFDG%'))`},
61-
{`x:aaa'bbb`, `"x" ILIKE '%aaa\'bbb%'`},
62-
{`x:aaa\bbb`, `"x" ILIKE '%aaa\\bbb%'`},
63-
{`x:aaa*bbb`, `"x" ILIKE '%aaa%bbb%'`},
64-
{`x:aaa_bbb`, `"x" ILIKE '%aaa\_bbb%'`},
65-
{`x:aaa%bbb`, `"x" ILIKE '%aaa\%bbb%'`},
66-
{`x:aaa%\*_bbb`, `"x" ILIKE '%aaa\%*\_bbb%'`},
60+
{`dajhd \(%&RY#WFDG`, `(("title" __quesma_match '%dajhd%' OR "text" __quesma_match '%dajhd%') OR ("title" __quesma_match '%(\%&RY#WFDG%' OR "text" __quesma_match '%(\%&RY#WFDG%'))`},
61+
{`x:aaa'bbb`, `"x" __quesma_match '%aaa\'bbb%'`},
62+
{`x:aaa\bbb`, `"x" __quesma_match '%aaa\\bbb%'`},
63+
{`x:aaa*bbb`, `"x" __quesma_match '%aaa%bbb%'`},
64+
{`x:aaa_bbb`, `"x" __quesma_match '%aaa\_bbb%'`},
65+
{`x:aaa%bbb`, `"x" __quesma_match '%aaa\%bbb%'`},
66+
{`x:aaa%\*_bbb`, `"x" __quesma_match '%aaa\%*\_bbb%'`},
6767

6868
// tests for wildcards
69-
{"%", `("title" ILIKE '%\%%' OR "text" ILIKE '%\%%')`},
70-
{`*`, `("title" ILIKE '%' OR "text" ILIKE '%')`},
71-
{`*neme*`, `("title" ILIKE '%neme%' OR "text" ILIKE '%neme%')`},
72-
{`*nem?* abc:ne*`, `(("title" ILIKE '%nem_%' OR "text" ILIKE '%nem_%') OR "abc" ILIKE '%ne%%')`},
73-
{`title:(NOT a* AND NOT (b* OR *))`, `(NOT ("title" ILIKE '%a%%') AND NOT (("title" ILIKE '%b%%' OR "title" ILIKE '%')))`},
74-
{`title:abc\*`, `"title" ILIKE '%abc*%'`},
75-
{`title:abc*\*`, `"title" ILIKE '%abc%*%'`},
76-
{`ab\+c`, `("title" ILIKE '%ab+c%' OR "text" ILIKE '%ab+c%')`},
77-
{`!db.str:FAIL`, `NOT ("db.str" ILIKE '%FAIL%')`},
69+
{"%", `("title" __quesma_match '%\%%' OR "text" __quesma_match '%\%%')`},
70+
{`*`, `("title" __quesma_match '%' OR "text" __quesma_match '%')`},
71+
{`*neme*`, `("title" __quesma_match '%neme%' OR "text" __quesma_match '%neme%')`},
72+
{`*nem?* abc:ne*`, `(("title" __quesma_match '%nem_%' OR "text" __quesma_match '%nem_%') OR "abc" __quesma_match '%ne%%')`},
73+
{`title:(NOT a* AND NOT (b* OR *))`, `(NOT ("title" __quesma_match '%a%%') AND NOT (("title" __quesma_match '%b%%' OR "title" __quesma_match '%')))`},
74+
{`title:abc\*`, `"title" __quesma_match '%abc*%'`},
75+
{`title:abc*\*`, `"title" __quesma_match '%abc%*%'`},
76+
{`ab\+c`, `("title" __quesma_match '%ab+c%' OR "text" __quesma_match '%ab+c%')`},
77+
{`!db.str:FAIL`, `NOT ("db.str" __quesma_match '%FAIL%')`},
7878
{`_exists_:title`, `"title" IS NOT NULL`},
7979
{`!_exists_:title`, `NOT ("title" IS NOT NULL)`},
80-
{"db.str:*weaver%12*", `"db.str" ILIKE '%weaver\%12%'`},
81-
{"(db.str:*weaver*)", `("db.str" ILIKE '%weaver%')`},
82-
{"(a.type:*ab* OR a.type:*Ab*)", `(("a.type" ILIKE '%ab%') OR "a.type" ILIKE '%Ab%')`},
83-
{"log: \"lalala lala la\" AND log: \"troll\"", `("log" ILIKE '%lalala lala la%' AND "log" ILIKE '%troll%')`},
80+
{"db.str:*weaver%12*", `"db.str" __quesma_match '%weaver\%12%'`},
81+
{"(db.str:*weaver*)", `("db.str" __quesma_match '%weaver%')`},
82+
{"(a.type:*ab* OR a.type:*Ab*)", `(("a.type" __quesma_match '%ab%') OR "a.type" __quesma_match '%Ab%')`},
83+
{"log: \"lalala lala la\" AND log: \"troll\"", `("log" __quesma_match '%lalala lala la%' AND "log" __quesma_match '%troll%')`},
8484
{"int: 20", `"int" = 20`},
85-
{`int: "20"`, `"int" ILIKE '%20%'`},
85+
{`int: "20"`, `"int" __quesma_match '%20%'`},
8686
}
8787
var randomQueriesWithPossiblyIncorrectInput = []struct {
8888
query string
@@ -91,17 +91,17 @@ func TestTranslatingLuceneQueriesToSQL(t *testing.T) {
9191
{``, `true`},
9292
{` `, `true`},
9393
{` 2 `, `("title" = 2 OR "text" = 2)`},
94-
{` 2df$ ! `, `(("title" ILIKE '%2df$%' OR "text" ILIKE '%2df$%') AND NOT (false))`}, // TODO: this should probably just be "false"
94+
{` 2df$ ! `, `(("title" __quesma_match '%2df$%' OR "text" __quesma_match '%2df$%') AND NOT (false))`}, // TODO: this should probably just be "false"
9595
{`title:`, `false`},
96-
{`title: abc`, `"title" ILIKE '%abc%'`},
97-
{`title[`, `("title" ILIKE '%title[%' OR "text" ILIKE '%title[%')`},
98-
{`title[]`, `("title" ILIKE '%title[]%' OR "text" ILIKE '%title[]%')`},
99-
{`title[ TO ]`, `((("title" ILIKE '%title[%' OR "text" ILIKE '%title[%') OR ("title" ILIKE '%TO%' OR "text" ILIKE '%TO%')) OR ("title" ILIKE '%]%' OR "text" ILIKE '%]%'))`},
96+
{`title: abc`, `"title" __quesma_match '%abc%'`},
97+
{`title[`, `("title" __quesma_match '%title[%' OR "text" __quesma_match '%title[%')`},
98+
{`title[]`, `("title" __quesma_match '%title[]%' OR "text" __quesma_match '%title[]%')`},
99+
{`title[ TO ]`, `((("title" __quesma_match '%title[%' OR "text" __quesma_match '%title[%') OR ("title" __quesma_match '%TO%' OR "text" __quesma_match '%TO%')) OR ("title" __quesma_match '%]%' OR "text" __quesma_match '%]%'))`},
100100
{`title:[ TO 2]`, `("title" >= '' AND "title" <= '2')`},
101-
{` title `, `("title" ILIKE '%title%' OR "text" ILIKE '%title%')`},
102-
{` title : (+a -b c)`, `(("title" ILIKE '%+a%' OR "title" ILIKE '%-b%') OR "title" ILIKE '%c%')`}, // we don't support '+', '-' operators, but in that case the answer seems good enough + nothing crashes
101+
{` title `, `("title" __quesma_match '%title%' OR "text" __quesma_match '%title%')`},
102+
{` title : (+a -b c)`, `(("title" __quesma_match '%+a%' OR "title" __quesma_match '%-b%') OR "title" __quesma_match '%c%')`}, // we don't support '+', '-' operators, but in that case the answer seems good enough + nothing crashes
103103
{`title:()`, `false`},
104-
{`() a`, `((false) OR ("title" ILIKE '%a%' OR "text" ILIKE '%a%'))`}, // a bit weird, but '(false)' is OK as I think nothing should match '()'
104+
{`() a`, `((false) OR ("title" __quesma_match '%a%' OR "text" __quesma_match '%a%'))`}, // a bit weird, but '(false)' is OK as I think nothing should match '()'
105105
}
106106

107107
currentSchema := schema.Schema{
@@ -127,7 +127,7 @@ func TestResolvePropertyNamesWhenTranslatingToSQL(t *testing.T) {
127127
mapping map[string]string
128128
want string
129129
}{
130-
{query: `title:"The Right Way" AND text:go!!`, mapping: map[string]string{}, want: `("title" ILIKE '%The Right Way%' AND "text" ILIKE '%go!!%')`},
130+
{query: `title:"The Right Way" AND text:go!!`, mapping: map[string]string{}, want: `("title" __quesma_match '%The Right Way%' AND "text" __quesma_match '%go!!%')`},
131131
{query: `age:>10`, mapping: map[string]string{"age": "foo"}, want: `"foo" > '10'`},
132132
}
133133
for i, tt := range properQueries {

0 commit comments

Comments
 (0)