From a1a6689febd8a76d11351ec40f8fe99a5a7cbf10 Mon Sep 17 00:00:00 2001 From: Hadi <112569860+anotherhadi@users.noreply.github.com> Date: Thu, 25 Sep 2025 17:30:33 +0200 Subject: [PATCH] optimization Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com> --- back/search/dataleak/dataleak.go | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/back/search/dataleak/dataleak.go b/back/search/dataleak/dataleak.go index c1469d8..5d0705d 100644 --- a/back/search/dataleak/dataleak.go +++ b/back/search/dataleak/dataleak.go @@ -196,22 +196,17 @@ func getWhereClause(queryText string, columns []string, exactMatch bool) string termEscaped = strings.TrimSuffix(termEscaped, "$") } + termEscapedILike := strings.ReplaceAll(termEscaped, "_", "\\_") + termEscapedILike = strings.ReplaceAll(termEscapedILike, "%", "\\%") for _, col := range columns { if exactMatch || (startsWith && endsWith) { - termEscapedILike := strings.ReplaceAll(termEscaped, "_", "\\_") - termEscapedILike = strings.ReplaceAll(termEscapedILike, "%", "\\%") orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%s' ESCAPE '\\'", col, strings.ToLower(termEscapedILike))) + } else if startsWith { + orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%s%%' ESCAPE '\\'", col, strings.ToLower(termEscapedILike))) + } else if endsWith { + orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%%%s' ESCAPE '\\'", col, strings.ToLower(termEscapedILike))) } else { - // Escape characters for ILIKE - termEscapedILike := strings.ReplaceAll(termEscaped, "_", "\\_") - termEscapedILike = strings.ReplaceAll(termEscapedILike, "%", "\\%") - if startsWith { - orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%s%%' ESCAPE '\\'", col, strings.ToLower(termEscapedILike))) - } else if endsWith { - orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%%%s' ESCAPE '\\'", col, strings.ToLower(termEscapedILike))) - } else { - orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%%%s%%' ESCAPE '\\'", col, strings.ToLower(termEscapedILike))) - } + orClausesForTerm = append(orClausesForTerm, fmt.Sprintf("\"%s\" ILIKE '%%%s%%' ESCAPE '\\'", col, strings.ToLower(termEscapedILike))) } } andClauses = append(andClauses, "("+strings.Join(orClausesForTerm, " OR ")+")") @@ -226,11 +221,3 @@ func getFromClause(s *server.Server) string { } return fmt.Sprintf("read_parquet([%s], union_by_name=true, filename=true)", strings.Join(parquets, ", ")) } - -func castAllColumns(cols []string) []string { - casted := make([]string, len(cols)) - for i, col := range cols { - casted[i] = fmt.Sprintf("cast(%s as text)", col) - } - return casted -}