diff --git a/database/postgres/utils.go b/database/postgres/utils.go index edd630b..1d5f157 100644 --- a/database/postgres/utils.go +++ b/database/postgres/utils.go @@ -17,28 +17,34 @@ func TSQueryFromSearch(search string) string { startQuotes := false if strings.HasPrefix(token, "\"") { - token = token[1:] + if len(token) > 1 { + token = token[1:] + } startQuotes = true } if strings.HasSuffix(token, "\"") { token = token[:len(token)-1] + startQuotes = false clearQuotes = true } - if startQuotes { - if i > 0 { + token := strings.Trim(token, ",.;:()\"") + if len(token) > 0 { + if startQuotes { + if i > 0 { + result += " & " + } + + result += "(" + } else if inQuotes { + result += "<->" + } else if i != 0 { result += " & " } - result += "(" - } else if inQuotes { - result += "<->" - } else if i != 0 { - result += " & " + result += token } - result += token - if startQuotes { inQuotes = true } diff --git a/database/postgres/utils_test.go b/database/postgres/utils_test.go index ffaed02..fedee12 100644 --- a/database/postgres/utils_test.go +++ b/database/postgres/utils_test.go @@ -13,6 +13,7 @@ func TestTSQueryFromSearch(t *testing.T) { {`"asari matron" blue`, `(asari<->matron) & blue`}, {`"christmas present" "wrapping paper"`, `(christmas<->present) & (wrapping<->paper)`}, {`stuff`, `stuff`}, + {`"her slowly, rubbing the back of his head awkwardly. "`, `(her<->slowly<->rubbing<->the<->back<->of<->his<->head<->awkwardly)`}, } for i, row := range rows {