(Feat): Initial Commit
Some checks failed
Build & Test / build-test (push) Has been cancelled
Build & Test / swagger-codegen-cli (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled

This commit is contained in:
2026-07-03 19:41:31 +05:30
commit 7e940c83a7
461 changed files with 45002 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
package db
import (
"regexp"
"strings"
)
var (
tsQueryWhiteSpaceRegex = regexp.MustCompile(`\s+`)
)
// SearchStringToTSQuery returns a TSQuery string from user input.
// The resulting query will match if every word matches a beginning of a word in the row.
// This function will trim all leading and trailing as well as consecutive whitespaces and remove all single quotes before
// transforming the input into TSQuery syntax.
// If no input was given (nil or empty string) or the value only contains invalid characters, an empty string will be returned.
func SearchStringToTSQuery(s *string) string {
if s == nil || len(*s) == 0 {
return ""
}
v := strings.TrimSpace(strings.ReplaceAll(*s, "'", ""))
if len(v) == 0 {
return ""
}
return "'" + tsQueryWhiteSpaceRegex.ReplaceAllString(v, "':* & '") + "':*"
}