Browse Source

fix ts query getting mad at you for quoting a single word.

master
Gisle Aune 3 years ago
parent
commit
b641f7d516
  1. 11
      database/postgres/utils.go
  2. 1
      database/postgres/utils_test.go

11
database/postgres/utils.go

@ -16,16 +16,15 @@ func TSQueryFromSearch(search string) string {
clearQuotes := false
startQuotes := false
if strings.HasPrefix(token, "\"") {
if len(token) > 1 {
token = token[1:]
}
if strings.HasPrefix(token, "\"") && len(token) > 1 {
startQuotes = true
}
if strings.HasSuffix(token, "\"") {
token = token[:len(token)-1]
if !startQuotes {
clearQuotes = true
}
startQuotes = false
clearQuotes = true
}
token := strings.Trim(token, ",.;:()\"")

1
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`},
{`"stuff"`, `stuff`},
{`"her slowly, rubbing the back of his head awkwardly. "`, `(her<->slowly<->rubbing<->the<->back<->of<->his<->head<->awkwardly)`},
}

Loading…
Cancel
Save