From b641f7d5160917069d7e686779b4e3e85c8e7e89 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Fri, 2 Apr 2021 20:25:32 +0200 Subject: [PATCH] fix ts query getting mad at you for quoting a single word. --- database/postgres/utils.go | 11 +++++------ database/postgres/utils_test.go | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/database/postgres/utils.go b/database/postgres/utils.go index 1d5f157..85c625a 100644 --- a/database/postgres/utils.go +++ b/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, ",.;:()\"") diff --git a/database/postgres/utils_test.go b/database/postgres/utils_test.go index fedee12..fc14301 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`}, + {`"stuff"`, `stuff`}, {`"her slowly, rubbing the back of his head awkwardly. "`, `(her<->slowly<->rubbing<->the<->back<->of<->his<->head<->awkwardly)`}, }