Browse Source

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

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

11
database/postgres/utils.go

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

1
database/postgres/utils_test.go

@ -13,6 +13,7 @@ func TestTSQueryFromSearch(t *testing.T) {
{`"asari matron" blue`, `(asari<->matron) & blue`}, {`"asari matron" blue`, `(asari<->matron) & blue`},
{`"christmas present" "wrapping paper"`, `(christmas<->present) & (wrapping<->paper)`}, {`"christmas present" "wrapping paper"`, `(christmas<->present) & (wrapping<->paper)`},
{`stuff`, `stuff`}, {`stuff`, `stuff`},
{`"stuff"`, `stuff`},
{`"her slowly, rubbing the back of his head awkwardly. "`, `(her<->slowly<->rubbing<->the<->back<->of<->his<->head<->awkwardly)`}, {`"her slowly, rubbing the back of his head awkwardly. "`, `(her<->slowly<->rubbing<->the<->back<->of<->his<->head<->awkwardly)`},
} }

Loading…
Cancel
Save